There is a second very similar, but subtlety different command to turn the wheels using angles. Change the template we developed in tutorial IX so that it uses the run_target command under the UP button. The new code sniplet should look something like this.

    if Button.UP in brick.buttons():
#speed = speed + jumpSpeed
print(gyro.angle(), " ", speed)

Now upload it and try it out by pressing the RIGHT or the LEFT key first and then the UP key next.

What it appear to do is reverse the action you just requested. But beware this isn’t what it is doing.

If you press the RIGHT three times and then the UP you’ll see the difference. The bot will turn each time you press the right key and then it will return it’s original angle when you press the UP in a single move. I hope this is making sense.

The run_target command moves the wheels X degrees until they reach an absolute angle you specify. The run_angle command however moves the wheels X degrees relatively to their current angle.

In numbers if run_angle moves the wheels by 180 degrees and then by 180 degrees, the wheels on the bot would have moved by 360 degrees. If you then use the run_target command with a goal of 0 degrees, the wheels which will be currently set to 360 degrees will run in reverse until they return to 0 degrees.

Finally there is one more command to mention, target_angle() which like run_angle() takes an absolute angle value and moves the wheels as quickly as it can to said angle. Remember the angle I am referring too here is the angle of the wheel itself. Here is an super short example in figures, this command runs both wheels 10 times.

#!/usr/bin/env pybricks-micropython
from pybricks import ev3brick as brick
from pybricks.parameters import Port
from pybricks.ev3devices import Motor
from import wait
leftMotor = Motor(Port.B)
rightMotor = Motor(Port.C)

Now, you’re being forgiven for asking what use this all really is, wheel rotations isn’t a currency that most people are used too. It is however a core concept used in robotics and even has its own name, odemetry.

The basic formulas used in odemetry are pretty simple, with three principle players in it. The diameters of the wheels, the distance they are apart and a measure that is some times called clicks, or angle() on our bots. The very same value you’ve been using to move the wheels with the past three commands.

Now you multiply the diameter of your wheel by pi [3.142] to get the circumference. You then divide the circumference by the number of clicks for a full turn, so in our case 360 degrees. The value your’re left with is the calibration factor.

Now if you know how many clicks you travelled, you can figure out how far you travelled with your calibration factor. Let’s do an example. The diameter of the wheels of my robot is 70mm. I multiply that by 3.142 and then divide the answer by 360. The value I get, my calibration value is 0.61094.

Now if I run the previous script, using 360 and not 3600 I can work out that I will travel 0.16094 x 360 or approx. 220mm. Try an example out for yourself, with the figures for your bot of course.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store