12. Case 11: Following with A Fixed Distance

12.1. Purpose


  • Programme to set the TPBot following another car with a fixed distance.

12.2. Material


../../_images/TPBot_tianpeng_case_01_01.png

12.3. Software


MicroSoftmakecode

12.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 an icon on the micro:bit display.

  • Save the variable as the distance detected from the TPBot to its front car in the forever brick, judge if the the distance is between 10 and 20(exl. 10&20), if yes, set the speed of both wheels in 0; if the distance is below 10, set the speed of both wheels in -30%; or set the speed both in 30%.

../../_images/TPBot_tianpeng_case_11_04.png

12.5. Conclusion


Power up to show an icon on the micro:bit display and the TPBot keeps a distance to its front car. It goes slower if the distance detected was close or it goes forward if the distance detected was far; and it stops if the distance detected was between the set interval value.

12.6. Exploration


12.7. FAQ


12.8. Relevant File