Case 11: Following with A Fixed Distance
Contents
14. Case 11: Following with A Fixed Distance#
14.1. Purpose#
Programme to set the TPBot following another car with a fixed distance.
14.2. Material#
1 x TPBot
14.3. Software#
14.4. Programming#
Click “Advanced” to see more choices in the MakeCode drawer.
We need to add a package for programming. Click “Extensions” in the bottom of the drawer and search with “tpbot” in the dialogue box to download it.
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%.
Link#
You may also download it directly below:
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.
14.5. Exploration#
14.6. FAQ#
Q: The car does not work with the code in the wiki.
A: It should be the batteries that are lack of power, please try to fix it by adding the value of the speed in the code.