Member-only story
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.