How the Receiver Works
The radio_tilt_bot_fb_lr_with_stop_range project is just another development step from the previous activity. Here are the changes that were made to radio_tilt_bot_fb_with_stop_range to add the left/right control.
Remember how the project sets fb to y /10 to reduce the range of values from -1024…1024 to -102 to 102? Well, since the x-axis measurements also come in a range of -1024 to 1024, the project can also divide those by 10. That’s what set lr to (x / 10) does, and lr is shorthand for left/right.
After setting up vL and vR with fb and –fb, the lr component can be added in to cause turns. The statement if(fb < 0): set lr to (0 – lr) changes the sign of the lr variable if you are tipping the tilt transmitter toward you. That’s because the rules for wheel rotation directions for turning reverse when the robot is backing up.
Let’s try an exercise called variable tracing. Variable tracing is the process of stepping through each block after setting variable values and checking what each statement does with those values. Some software development environments offer an automated version of this, but here, it is a mental exercise to help better understand how the statements correctly control the wheel speeds. The variable values are calculated in comments to the right of the statements.
Example: Tilt the micro:bit away from you and to the left.
Assume the y variable is 400, and the x variable is 200.
Example: Tilt the micro:bit toward you and to the right.
Assume the y variable is -400, and the x variable is -200.