11. Case 09: Autonomous Obstacle Avoidance

11.1. Purpose


  • The Cutebot avoids the obstacles automatically to move forward.

11.2. Materials


11.3. Software Platform


MicroSoft makecode

11.4. Programming


Step 1

  • Click the “Advanced” to see more choices in the MakeCode drawer.

../../_images/cutebot-pk-1.png

  • A codebase is required for Cutebot programming, click “Add Package” at the bottom of the drawer, search Cutebot in the dialogue box and download it.

../../_images/cutebot-pk-11.png

Note: If you met a tip indicating incompatibility of the codebase, you can continue with the tips or build a new project there.

Step 2

  • Drag “go straight at full speed” brick into the On start brick.

../../_images/case_09_01.png

Step 3

  • Set a Sonar variable to save the detected Cm value in the Forever brick.

  • If the detected value is between 2 and 20 which means there is obstacle being detected in the front 20cm far, set the left wheel speed to 0 and right to -50, make a right turn at a random time to complete an obstacle avoidance.

  • If not, move forward at its full speed.

../../_images/case_09_02.png

Programming

Links: https://makecode.microbit.org/_hijb4L6ttgfc

You can also download it directly below:

---

11.5. Result


  • The Cutebot moves forward at its full speed and will make a right turn to keep going if any obstacle being detected.

11.6. Exploration


  • Why should the detected value be over 2cm ?

11.7. FAQ


11.8. Relevant Files