This example program shows how to program the V5 Clawbot to turn left and right using Modkit.
- A V5 Smart Motor, on Port 1, named LeftMotor.
- A V5 Smart Motor, on Port 10, named RightMotor and set to Reversed.
How it works
when (STARTED) block tells the robot to run this code when the program starts. A number variable,
revsPerClawbot90Turn is declared and assigned to
This value should turn a V5 Clawbot with 18:1 gear motors approximately 90 degrees. Based on the weight of the robot and the friction of the wheels, the amount of turn may be slightly more or less than 90 degrees. You can adjust the
revsPerClawbot90Turn variable if desired.
Then, the left motor is set to start rotating with a negative number of revolutions. Since
startRotateFor is used the motor will begin rotating and the program will continue immediately.
Next, the right motor is set to rotate, but with a positive number of revolutions. Since
rotateFor is used the program will not continue until the motor completes its rotation.
Since the motors are set to rotate in opposite directions, with the left motor rotating backward, the robot will turn in place to the left. The facing of the V5 Clawbot will change by about 90 degrees.
Then, when the right motor has finished rotating, the program will pause for
Finally, the motor rotation blocks are repeated. This time, the positive and negative rotations are switched and multiplied by
2. The motors will spin in the opposite direction and twice as far, which will turn the robot to face in the opposite direction.