# MicroPython Tutorial X

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        leftMotor.run_target(speed,angle,Stop.COAST,False)        rightMotor.run_target(speed,angle,Stop.COAST,True)        print(gyro.angle(), " ", speed)        wait(500)`

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-micropythonfrom pybricks import ev3brick as brickfrom pybricks.parameters import Portfrom pybricks.ev3devices import Motorfrom pybricks.tools import waitleftMotor = Motor(Port.B)rightMotor = Motor(Port.C)leftMotor.track_target(3600)rightMotor.track_target(3600)wait(10000)`

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.