The answersDownload the PDF
Worksheet

3.5 Two loops at once

Control · Robot club · about 20 min

BugBotLab
NameClassDate

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
  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
  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?

  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)
  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
  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

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()

Plan your program here, then type it in and press Run.

QR code
Do it on the robot
www.bugbotlab.com/learn/3-5-two-loops-at-once/
The simulator checks it and tells you when it passes. Nothing to install, no account.

Challenges

  1. Add a third controller: forward speed from the distance to the end of the zone, so it parks at y = 75 exactly.
  2. Follow the line x = -10, then x = 10, switching halfway.
  3. Write hold_line(target_x, until_y) as a function. You will want it in lesson 3.6.