Science Oxford Logo

Increasing the Speed of your Robot

The values your joystick is sending, are not the highest values the motors can understand. You can adjust these to make the robot faster!

Step 1

Before speeding up your robot, you must find out what values are being sent by your joystick.

To do this, you will use the code we used at the beginning of the session!

During testing, you do not want your robot to drive around.

Use the # symbol on your keyboard to tell the micro:bit to ignore your drive line of code:

#drive(left, right)

It should turn grey in Mu.

Underneath this line, print the joystick's values, like we did at the beginning:

print(message)

Step 2

To view the values, you need to use the REPL again.

If your robot's body is in the way of the micro:bit's reset button, carefully remove it.

View the values in the REPL:

Write down the highest number you can get from the joystick.

Step 3

The highest value that the motors can understand, is 1023.

You can make the value from the joystick larger, by multiplying it - the trick is to make sure it doesn't go any quicker than 1023!

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

You will need to edit these lines of code, to maximise the speed of your motors.

For example, to make the motors turn slightly faster, multiply the values by 1.2.

After you have adjusted the values, they will probably not be whole numbers any more!

You must turn them into whole numbers before they 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]*1.2)
right = int(message[1]*1.2)

Test these values using the REPL:

Keep adjusting until you get the best possible speed out of your motors.

Click here to see the example code in full.