Control · Robot club · about 20 min
Heading and sideways controllers together on a holonomic robot.
[1 mark]The heading is held perfectly, but the robot still ends up to the left. Why?
[1 mark]In drive(70, x_error * 10, heading_error * 4), what does each number do?
drive.[1 mark]target_x is 10, x is 4, and the sideways gain is 10. What sideways value does (target_x - x) * 10 give?
[1 mark]What does this program print?
def wrapped(h):
return (h + 180) % 360 - 180
target_x = 10
x = 13
heading = 355
print("sideways", (target_x - x) * 10)
print("rotation", wrapped(0 - heading) * 4)sideways -30 rotation 20
x is 3 past the line, so sideways is -30, back to the left. A heading of 355 is 5 to the left of 0, so rotation is 20, turning right.
[1 mark]Why do the sideways and heading controllers not fight each other?
[1 mark]What is the right way to tune two gains?
The zone is only 6 cm wide. Finish inside it, facing 0 within 5 degrees, on the curving, leaking robot.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
def wrapped(h):
return (h + 180) % 360 - 180
while position()[1] < 65:
error = wrapped(0 - heading())
# forward, sideways, rotation: -100 to 100 each, until the next command
drive(70, 0, error * 4)
# pause 0.1 s (the robot keeps doing what it was told)
wait(0.1)
# all motors off
stop()The hint students can ask for: This robot curves AND leaks sideways. Two controllers at once: rotation from the heading error, sideways from the x error. The zone is only 6 cm wide.
from bugbot import *
connect()
def wrapped(h):
return (h + 180) % 360 - 180
while position()[1] < 65:
x, y = position()
error = wrapped(heading())
drive(70, -x * 10, -error * 4)
wait(0.1)
stop()
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.