The servo control base program in last chapter lays a foundation for controlling the RollFlash to move forward and backward, and turn left and right. Next let’s talk about the specific control program for some movements.
In the program above, the number 30, the value in the function ServoWrite() represents the pace of RollFlash. Due to its structure design (the servo installation), the moving pace is fixed.
How can it move forward? It moves its feet diagonally in opposite directions: raise the right front foot and move forward -> raise the left front foot and right hind foot at the same time to move the body –> the right front foot gets on the ground –> raise the left hind foot to move forward –> the left hind foot gets on the ground. It walks a step forward after all these actions.
Then it continues from the other side: raise the left front foot and move forward –> raise the right front foot and left hind foot at the same time to move the body –> the left front foot gets on the ground –> raise the right hind foot to move forward –> the right hind foot gets on the ground. It walks another step forward then.
Therefore, it will keep walking forward by continuing these two loops.
The program above is to control it move backward, which is similar to moving forward. The only difference is the walking direction: raise the right hind foot and move backward -> raise the right front foot and left hind foot at the same time to move the body -> the right hind foot gets on the ground -> raise the left front foot to move backward -> the left front foot gets on the ground. It walks a step backward after all these actions.
Then it continues from the other side: raise left hind foot and move backwards -> raise the left front foot and right hind foot at the same time to move the body -> the left hind foot gets on the ground -> raise the right front foot to move backward -> the right front foot gets on the ground. It walks another step backward then.
Therefore, it will keep walking backward by continuing these two loops.
The program above is for turning right. RollFlash can realize turning right by keeping the left feet moving forward, while to do the right feet moving backward.
Program above is for turning left. RollFlash can realize turning left by keeping the left feet moving backwards, while the right feet moving forwards.
The above code is for the RollFlash’s basic movements. It will follow the commands received from the Bluetooth module via the serial port and take the corresponding actions.
With the code above, we can read the data from the Bluetooth module, and save it with a variable.
If the command “c” is received, it means to let RollFlash move forward; if the command “d”, it moves backwards; if “a”, it turns left; if “b”, it turns right; if “s”, it stops. Thus, we can remotely control the RollFlash to move forward and backward, turning left and right, etc.