Introduction to Programming (Blocks)

To program the robot to move forward a set distance, the movement blocks offer a simple solution. Both the angle of the robot and the distance can be adjusted.

Setting Motors and Moving Straight

The following code programs the robot to use C and D as the movement motors with a speed of 25%. Then, it goes straight for 17.5 centimeters.

Without setting the movement motors (first block), the robot would not know which two motors to move. To solve this, we must tell the robot that the motors connected to the C and D ports are the two motors that will move together. Adjusting the speed to 25% allows to prevent the robot from going too fast, but it can be adjusted up to 100% (fast). The angle can also be changed, allowing the robot to move in a curve. If you want the robot to move backward, we can change the speed to be negative.

Turning

To turn the robot, there is a block in the movement section that will only rotate one motor. This can be used to make a turn if you know how much the motor has to turn in centimeters. If you don’t, you can always experiment to find out then save that value.

Or, you could find it mathematically if you know the distance between the two wheels on the robot.

The outer wheel (the one that moves during the turn) forms the circumference of a circle where the radius is the distance between the two wheels. The second wheel acts as an anchor point, or the center of the circle. The following formula can thus be used:

Dwheel = Dπ×(θ/360)

If we want to turn 90 degrees:

11.3 cm × π × 90/360 = 8.8 cm

We have to move the motor 8.8 cm to make a 90 degree turn to the right. One rotation of the motor is 17.5 cm, so the robot moves 0.5 rotations to make a 90 degree turn. We can program this as follows.

Practice

  1. Program the robot to move in a 20 cm by 20 cm square
  2. Program the robot to go straight 30 cm then turn 280 degrees and move backwards 10 cm