Science Oxford Logo

Helping your Robot to Drive in a Straight Line

If one of your wheels moves faster than the other, follow these instructions to adjust the values given to the motors.

Step 1

Before editing the code, you must work out which motor is turning the fastest.

Drive your robot forwards and check which direction it turns in.

If it turns slightly left, then the right wheel is turning faster than the left one.

wheel speeds animation

Step 2

In your while True loop, you have two variables, left and right.

You will need to edit just one of these lines of code, to slow down your fastest wheel.

To make the left wheel turn at half the speed of the right wheel, multiply it by 0.5.

After you have adjusted the value, it will probably not be a whole number any more!

You must turn it into a whole number before it can be used. int(number) will turn a number into an integer, which means a whole number.

Look at the example code below, then adjust your own program:

left = int(message[0]*0.5)

Half-speed will probably be too slow for your robot, so adjust the number until you are happy with it!

Multiplying by 0.99, will give you a number pretty close to full speed, multiplying by 0.75 will give you three-quarters of the speed.

Click here to see the example code in full.