Project 10 XGO Follows Light

Ⅰ. Teaching Aims

  1. Read the value light level (0-100) of the Fox:bit on-board photoresistor.

  2. Use map() to linearly map light intensity to step size or speed.

  3. Suppress bright and dark jitter through “double thresholds + return difference”.

  4. Be capable of independently completing two types of self-developed scripts:

  • Bright → Stand up / Dark → sit down

  • Light following mode: the brighter the light is, the faster it will walk.

Ⅱ. Pre-class Check

  • XGO + Foxbit + MicroBlocks IDE.

  • XGO battery power ≥ 60 %. Place the robot on a 1m × 1m flat ground and avoid direct strong light or flickering.

  • MicroBlocks status bar shows a green dot, XGO-lite extension is loaded and the development board model is Foxbit.

  • Run XGO reset pose and confirm that the zero position and step size are normal.

Ⅲ. Key Blocks Analysis

Img

Functions

Return the ambient light intensity from 0 to 100

Fallible points

Must be placed in forever for real-time reading

Img

Functions

Linear mapping a–bc–d

Fallible points

a and b cannot be the same

Img

Functions

Determine the light intensity and switch actions

Fallible points

Missing “return difference” → shaking

Img

Functions

Set the forward step size to n mm

Fallible points

Step size > 90 mm → Prone to falling

Comparison table of photosensitivity and step size:

Environment

light level

Recommended step size

Dark room

0 – 10

0(stop)

Ordinary classroom

20 – 40

30 – 50

Beside the desk lamp

60 – 80

60 – 80

Direct flashlight

100+

80 – 90(upper limit)

Ⅳ. Practice

Test 1: Read Real-time Light Intensity (for debugging)

Img

Online code: Click here

Test 2: Stand Up When Bright, Sit Down When Dark

High threshold hiCut = 100, low threshold loCut = 60, return difference 40 lx

Img

Online code: Click here

Test 3: Light Following Dog: Brighter Light for Faster Speed

scriptImage58890

Online code: Click here

Ⅴ. Quiz

  1. Why does Test 2 require “double thresholds” instead of just one?

  2. What would happen if the wait 100 ms in Test 3 were changed to 20 ms?

  3. Besides photoresistor, what other sensors can you use to “drive” the step size? Please give two examples and explain their mapping range.

Ⅵ. FAQ

Questions

Possible causes

Solutions

Frequent switch between standing up
and sitting down

The interval between hiCut
and loCut is too small

Return difference ≥ 30 lx

The step size changes randomly

Ambient light flickering

wait 100 ms,
or perform a moving average

Fall while walking

Step size > 90 mm

Set the upper limit of map() to 90

The reading is always either 0 or 100

The sensor is blocked
or directly exposed to strong light

Clean the photoresistor holes;
Avoid direct light

Response delay

wait is too long

Shorten to 80–120 ms