8. Case 06: Automatic Obstacle Avoidance

8.1. Purpose


  • Build a Wonder Rugged Kit that can avoid obstacles.

8.2. Materials


  • micro:bit Wonder Rugged Kit

  • Ultrasonic Sound Sensor

8.3. Background Knowledge


8.4. Software


MicroSoft makecode

8.5. Program


Step 1

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

https://raw.githubusercontent.com/elecfreaks/learn-cn/master/microbitKit/Mecanum_wheel_car_kit/images/Mecanum%20wheel%20car%20kit_case_01_01.png

For programming the Wonder Rugged Kit, we need to add a package. Click “Extensions” at the bottom of the drawer and then search “Wukong” in the dialogue box to download it.

https://raw.githubusercontent.com/elecfreaks/learn-cn/master/microbitKit/Mecanum_wheel_car_kit/images/Mecanum%20wheel%20car%20kit_case_01_02.png

For programming the ultrasonic sound sensor, we need to add a package. Click “Extensions” at the bottom of the drawer and then search “github.com/elecfreaks/pxt-sonarbit” in the dialogue box to download it.

https://raw.githubusercontent.com/elecfreaks/learn-cn/master/microbitKit/Mecanum_wheel_car_kit/images/Mecanum%20wheel%20car%20kit_case_03_04.png

Note:If you get a warning indicating some packages will be removed because of incompatibility issues, you can follow the prompts or create a new project in the menu.

Step 2

Click Wukong to choose mecanum block.

https://raw.githubusercontent.com/elecfreaks/learn-cn/master/microbitKit/Mecanum_wheel_car_kit/images/Mecanum%20wheel%20car%20kit_case_01_03.png

Step 3

Drag mecanum into on start block and set the connection for servos accordingly.

https://raw.githubusercontent.com/elecfreaks/learn-cn/master/microbitKit/Mecanum_wheel_car_kit/images/Mecanum%20wheel%20car%20kit_case_06_05.png

Step 4

Set the car to move forward and judge the distance between the obstacle and the car, if the distance is below 25cm, the car goes back with 500ms and turns left with 500ms.

https://raw.githubusercontent.com/elecfreaks/learn-cn/master/microbitKit/Mecanum_wheel_car_kit/images/Mecanum%20wheel%20car%20kit_case_06_06.png

Program

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

You can also download it directly:

Result

The car moves forward after starting, if detecting any obstacles, it goes back and turns left to avoid the obstacle and then keeps going.

8.6. Exploration


8.7. FAQ


8.8. Relevant Files