5. Case 04: Obstacle-avoidance Driving

5.1. Purpose


  • Programme to set the TPBot avoiding an obstacle automatically.

5.2. Material


../../_images/TPBot_tianpeng_case_01_01.png

5.3. Software


MicroSoftmakecode

5.4. Programming


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

../../_images/TPBot_tianpeng_case_01_02.png

  • We need to add a package for programming. Click “Extensions” in the bottom of the drawer and seach with “tpbot” in the dialogue box to download it.

../../_images/TPBot_tianpeng_case_01_03.png

##Sample

  • Set a triangle in the micro:bit and the TPBot moving forward at the speed of 50%; Set the LED headlights in green.

  • Save the variable of the distance from the TPBot to the obstacle in the forever brick, judge if the items of i<15 and i≠0 are both true, if yes, set TPBot stopping immediately and the headlights flashing three times; set it reversing for 1 second at the speed of 30% and then turning left for 0.5 second at the speed of 30%; finally set the headlights showing green and the TPBot moving forward at the speed of 50%.

../../_images/TPBot_tianpeng_case_04_04.png

5.5. Conclusion


  • Power up the TPBot to move forward and it stops immediately with the headlights flashing three times if an obstacle was detected, then it reverses and turns left to keep moving forward with the headlights in green.

5.6. Exploration


5.7. FAQ


5.8. Relevant File