Move along the S-shaped track

8,459
Author: Yisong Xu, Si Xu

Press the onboard button and mBot moves in a S-shaped track.

Hardware requirements:

mBot

Implementation:

Upload the program to Arduino

Example program download:

S-shaped track.sb2

download

Example programs
arduino code

In this example the module directive arduino code is defined to let mBot move in a S-shaped track.
Define the module directive to combine several blocks. The program executes the defined module directive, i. e. calling its defined block behavior. This can make the program simpler and easier to read. See Knowledge Point 2 for methods.

 

Knowledge points
Point 1 Use “differential speed” to control mBot’s turning.
Use Block arduino code to directly control the direction of mBot in Example 15 Moving along the M-shaped track. Otherwise you can also control the speed of mBot’s left and right motors to control its direction:
When the right wheel speed is more than the left one, mBot turns left; when the left wheel speed is more than the right one, mBot turns right.
Install mBot correctly as required in the Instructions. Left wheel motor is connected to Motor Port 1 and right wheel motor to Motor Port 2. Watch mBot’s turning by testing the following script (taking mBot’s left turning for example, and its right turning is the same).

Script Turning
arduino code Turning left while moving forward
arduino code Turning left on the left wheel
arduino code Turning left on the right wheel
arduino code Turning left in place. The effects is the same with Block arduino code

 

Point 2 How to define the module directive
Click “Data and blocks” in “Scripts” and click “Make a block ” and enter the name of the new module directive in the window poping up, and then clck “Ok”. Then define the module directive in the programming area to use the new module directive for programming.
arduino code

 

Extended tasks

Task 1 Let mBot moves in a round track
Task 2 Modify the speed value of left and right motors of mBot (such as increasing the difference between the two values) and watch the moving status of mBot and record it.

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

—— More examples