The worksheetDownload the PDF
Answers

3.5 Two loops at once

Control · Robot club · about 20 min

BugBotLab

What this lesson is about

Heading and sideways controllers together on a holonomic robot.

Questions 6 marks in all

  1. [1 mark]The heading is held perfectly, but the robot still ends up to the left. Why?

    1. AIt slides sideways even while pointing straight
    2. BThe heading gain is too low
    3. Cwrapped() has the wrong sign
    4. Dposition() cannot measure x
    Answer: A. This robot curves and leaks. Heading control fixes the curve, but only a sideways controller can fix the leak.
  2. [1 mark]In drive(70, x_error * 10, heading_error * 4), what does each number do?

    1. A70 drives forward, the sideways part holds x, the rotation holds the heading
    2. B70 holds the heading, the second holds speed, the third holds x
    3. CAll three hold the heading
    4. DThe first two hold x and the third is the speed
    Answer: A. Forward, sideways and rotation: two errors with their own gains, going into one drive.
  3. [1 mark]target_x is 10, x is 4, and the sideways gain is 10. What sideways value does (target_x - x) * 10 give?

    Answer: 60. 10 minus 4 is 6, and 6 times 10 is 60, sliding right towards the line x = 10.
  4. [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)
    Answer:
    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.

  5. [1 mark]Why do the sideways and heading controllers not fight each other?

    1. AOn this robot, rotation and sideways motion are separate
    2. BThey take turns, one per loop
    3. CThe gains are the same
    4. DThey do fight, which is why the robot wobbles
    Answer: A. BugBot can slide without turning. A car cannot, which is why parallel parking is hard.
  6. [1 mark]What is the right way to tune two gains?

    1. AChange one at a time and watch what it does
    2. BChange both together by the same amount
    3. CSet both as high as they will go
    4. DCopy the gain from lesson 3.3
    Answer: A. Each gain has its own good range. Change one, see whether it lags or shakes, then move on to the other.

The task: on the rails

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.

A solution

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.