Project 6 XGO Draws A Square

Ⅰ. Teaching Aims

  1. Consolidate the segmentation thinking of “walk - stop - turn - stop” and avoid taking arcs.

  2. Use repeat to simplify the repeated path.

  3. Adjust the step size and waiting time through distance measurement, making the displacement more accurate.

  4. Use the forever infinite loop to perform square movements.

Ⅱ. Pre-class Check

  • XGO + Foxbit + MicroBlocks IDE.

  • Prepare an 80 cm × 80 cm blank floor and stick positioning points at the four corners with tape.

  • XGO battery power ≥ 60 %.

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

  • If precise distance measurement is required, prepare a tape measure or stick a scale paper tape on the ground.

Ⅲ. Key Blocks Analysis

Img

Functions

n [−100, 100];
positive for forward,
negative for backward

Common misuses

The walking section still gives turn → Take an arc

Img

Functions

Maintain the previous instruction for ms milliseconds

Common misuses

Write milliseconds as seconds → Wait too short

Img

Functions

n [−100, 100];
positive for left, negative for right;
additional wait is required

Common misuses

Forgot turn 0 to zero out

Img

Functions

Loop the code block k times

Common misuses

Forgot to write wait in the loop

Img

Functions

Forever loop

Ⅳ. Calculation of Step Size and Distance

Hard ground, 6.0V experience value:

Step size

1000 ms Forward distance

40

≈ 12 cm

60

≈ 15 cm

80

≈ 19 cm

Calculation:

Waiting time(ms) Target distance(cm) ÷ (distance each 1000 ms) × 1000

Example: target distance is 30 cm, so we use a step size of 60 → 30 ÷ 15 × 1000 2000 ms

Ⅴ. Test 1: 30cm Straight Line

Img

Click ▶Run, and then measure the displacement with a ruler; If the deviation is greater than 3 cm, fine-tune and wait for ±100 ms.

Online code: Click here

Ⅵ. Test 2: Square Route

  1. Requirement: Walk 30 cm → turn right at 90° → repeat 4 times, and finally return to the starting point.

  2. Recommended:

    • Go straight: walk 60 + wait 3000

    • Stop: walk 0 + wait 500

    • Turn: turn 90 + wait 1800 (≈ 90°)

    • Zero out: turn 0 + wait 200

Loop script sample:

Img

Online code: Click here

Debugging tips:

  • The turning angle is • too small → wait +50~100 ms • too large → wait −50 ms

  • The route is trapezoidal → Reduce the step size to 50, and ensure the ground is flat.

Ⅶ. Quiz

  1. Why is it necessary to walk 0 before starting the turn after the straight section ends?

  2. If we modify it to turn left and draw a counter-clockwise square, which two parts of the script should be changed?

  3. How to package “step size, distance, angle” with custom blocks to improve reusability?

Ⅷ. FAQ

Questions

Possible causes

Solutions

Walk in an arc line

Still set turn in the walking section

Section: Reset to zero after walking and then turn

The turning angle is too small / too large

wait is mismatching

Fine-tune in steps of 50 ms

It’s still rotating after turning

Forgot turn 0

Reset to zero immediately after the turn

Cannot return to the starting point

The accumulation of errors in walking distance

Slow the speed down, increase friction, or recalibrate