The Night Ferry · Scaffold ← Back to the harbor

The Night Ferry algorithm cheat sheet

An algorithm is a list of steps you follow in order. Every room of the Night Ferry has one, and they build on each other the same way the week does on the real V5 robot. Find your room, follow its steps, and check the example. Every picture here is a real screen from the game.

The screenRoom 1 · Timed RunRoom 2 · CompassRoom 3 · HuntRoom 4 · Dead WaterRoom 5 · Short WayThe short version
Before anything

Read the screen

The controls: Run times 5, Stop, and a speed slider.
▶ Run ×5
Runs your program as many times as the level asks, here five. One run proves nothing; the level wants the whole set.
■ Stop
Stops the runs early.
Logbook
One line per run: where it ended, how far apart the runs landed (the spread), and how many times it reversed.
Heading · Target · Error
On the water: where the ferry points, where you want it, and how far off it is right now.
Brain
Whatever your program prints, the same as the V5 Brain screen.
Python
Open VEXcode V5 under the blocks to see your program as Python. It is the same program, written as text.
Show me the answer
Loads a working program. It costs the "without Show me" star.

Three words the whole week uses

  1. Target: the heading you want, in degrees. 0 is north, 90 is east.
  2. Error: Target − heading. How far off you are, and which way.
  3. Band: how close counts as arrived.
Room 1 · The Timed Run · levels 1-1 and 1-2

Drive and turn on a timer

A program that moves for a set time, run five times, to see how much a timer can be trusted.

Cast off: drive on a timer

The algorithm

  1. drive forward: the motors start and keep going.
  2. wait 2 seconds: the program pauses while the boat moves.
  3. stop driving: the motors cut, and the boat coasts a little.
  4. Press ▶ Run ×5 and read the five stops in the logbook.
Blocks: drive forward, wait 2 seconds, stop driving.
Three blocks, top to bottom. Order matters: start, wait, stop.
The logbook: five runs, each stopping at a slightly different distance, and the spread between them.
Same program, five different stops. The spread is how far apart they landed: the error a timer cannot see.

A timed turn: tune for the average

The tuning algorithm

  1. Build turn right, wait, stop driving, and Run ×5.
  2. Read the average of the five, not the best one.
  3. Average short of 90? Make the wait a little longer. Past 90? A little shorter.
  4. Change it in small steps and Run again, until the average is within 8° of 90.
  5. Then look at the spread. That is how far a timer turn wanders even when the average is right.
Logbook for the starting timed turn: five runs ending near 47 to 55 degrees.
The starting program averages under 50°: not far enough. The game says wait a little longer.

Mistakes to watch for

  • Expecting the same stop every time. Same program, same boat, five different stops.
  • Tuning until one run looks perfect. Tune for the average, then look at the spread.
Room 2 · The Compass · levels 2-1 and 2-2

Calibrate, read, and measure

The Inertial sensor gives the heading. It has to calibrate first, and it drifts over time.

Calibrate, and wait for it

The algorithm

  1. calibrate Inertial: the sensor finds its own zero. The boat must be still.
  2. wait until not Inertial calibrating?: do not read anything until it is done.
  3. forever: print the heading on the Brain, then wait 0.5 seconds.
Blocks: calibrate Inertial, wait until not Inertial calibrating, forever print Inertial heading on Brain and wait 0.5 seconds.
Calibrate, wait for it, then read in a loop.

Measure the drift

The algorithm

  1. Run it. The boat is tied up and still for three minutes, printing every 10 seconds.
  2. Read the Brain at about 0:00, 1:00 and 3:00.
  3. Drift per minute = (reading at 3:00 − reading at 0:00) ÷ 3.
  4. Check it with the 1:00 reading: it should have moved about one minute's worth.
  5. Type your answer, in degrees per minute, into the logbook.
The Brain screen: readings every 10 seconds, from 0.05 at 0:02 up to 3.67 at 3:02.
A real run: 0.05 at 0:02 and 3.67 at 3:02. (3.67 − 0.05) ÷ 3 ≈ 1.2° per minute. At 1:02 it read 1.29, about one minute's worth. It checks.

Your numbers will be different

  1. Every player's sensor has its own drift, faster or slower, up or down.
  2. Use your Brain readings, not these.
  3. A drifting heading is why the robot needs to steer by the sensor all the time, not once.

Mistakes to watch for

  • Reading the heading while it is still calibrating. That number has not been decided yet, and nothing warns you.
  • Saying "not much". Degrees per minute is a measurement; "not much" is not.
Room 3 · The Hunt · levels 3-1 to 3-3

Steer by the compass

Turning until the heading equals the Target does not work. Steering both ways works, but it hunts.

Make it hunt: why equals fails

The algorithm

  1. Run the program you are given. Do not fix it yet.
  2. Watch the heading as it reaches 90. It goes past.
  3. Why: the heading arrives in steps (88.9, 89.8, 90.6) and skips the one exact number the program waits for.
Blocks: set Target to 90, turn right, wait until heading equals Target, stop driving.
It waits for heading = Target.
Logbook: turned 376 degrees and never stopped.
It turned all the way round and never stopped: the heading never equalled 90.

Steer both ways

The algorithm

  1. set Target to 90.
  2. forever: if heading < Target then turn right, else turn left.
  3. Run it and count the reversals in the logbook.
Blocks: set Target to 90, forever: if heading is less than Target, turn right, else turn left.
Always turning toward the Target.
Logbook: ended 95.1 degrees, 15 reversals after arriving.
It gets there, then reverses over and over. That is the hunt: it is always turning one way or the other.

Slow it down

The tuning algorithm

  1. Add set turn velocity at the very top.
  2. Lower the % a step at a time and Run.
  3. Read the wobble at the end of the run. Keep going until it is under 8° side to side.
  4. Too slow and it never reaches 90 in time. Go back up a step.

Mistakes to watch for

  • Trusting equals with a sensor. Use < and >.
  • Thinking it will settle. With only two choices, right or left, it never stops.
  • Slowing it down so much it never gets there.
Room 4 · Dead Water · levels 4-1 to 4-4

The deadband: close enough counts

Give the program a third choice: when it is close enough, do nothing. That band is the deadband, like a held bumper.

The deadband algorithm

  1. set Target, set Band, set turn velocity.
  2. forever: set Error to Target − heading.
  3. if abs of Error < Band then stop driving. Close enough, from either side.
  4. else: if Error > 0 then turn right, else turn left.
  5. Run all three. The goal is to stop once, cleanly.
The deadband program: set Target 90, set Band 6, set turn velocity 35, forever set Error to Target minus heading, if abs of Error is less than Band stop driving, else if Error is greater than 0 turn right, else turn left.
The three choices: stop, turn right, turn left.
Logbook: three runs, each ending near 90 with 1 reversal after arriving.
All three held inside the band, with one rock each. It passes, and a slightly wider band or a slower turn stops it cleanly.
The same program as VEXcode V5 Python.
The same program in Python. abs of becomes abs().

Tuning the band (4-2 and 4-4)

  1. Still hunting (lots of reversals)? The boat coasts further than the band is wide: widen the band or turn slower.
  2. Stopping too far from Target? The band is too wide: shrink it.
  3. To find the narrowest band that works: start wide, shrink it a step at a time, and when it starts hunting, go back one step.
  4. A faster turn coasts further, so it needs a wider band (4-4).

Hold the line (4-3)

  1. Inside the band, drive forward instead of stopping.
  2. Outside it, turn back toward the Target.
  3. A turn stops the driving on this drivetrain, so the drive has to come back on inside the band.
The starting blocks for 4-3: set Target 90, set Band 4, forever set Error to Target minus heading.
4-3 starts you here. Build the choices under set Error.

Mistakes to watch for

  • A band smaller than the overshoot. If the ferry coasts further than the band is wide, it still hunts.
  • Leaving out abs of. Arriving from either side has to count.
  • Thinking a wider band is safer. It is just less accurate.
Room 5 · The Short Way · levels 5-1 to 5-6

Turn the short way across north

Heading is a circle, not a ruler: 359 and 1 are two degrees apart. Plain Target − heading can send the ferry the long way round.

The fold

  1. Replace the Error with: Error = remainder of (Target − heading + 540) / 360, minus 180.
  2. That always gives a number from −180 to 180: the short way, and which side.
  3. Positive: turn right. Negative: turn left. Small: inside the band, stop.
StepTarget 10, heading 350Means
Target − heading10 − 350 = −340340° left: the long way
+ 540−340 + 540 = 200never negative now
remainder of ÷ 360200wrapped onto the circle
− 1802020° right: the short way
The 5-1 starting program, with Error set to Target minus heading.
The starting program uses plain Target − heading.
Logbook: ended 27.1 degrees, never arrived.
From 350 to 10 it went the long way round and never arrived in time.
The fixed program: set Error to remainder of Target minus heading plus 540, divided by 360, minus 180.
Only the set Error line changes. With the fold, the same trip is 20° to the right.
Python: Error equals Target minus inertial heading plus 540, remainder 360, minus 180.
In Python the remainder is %: ((Target − heading) + 540) % 360 − 180.
Logbook after the fix: ended 14.6 degrees, 0 reversals after arriving.
Fixed: twenty degrees right, the short way, and it stopped once inside the band.

The rest of the room

  1. Any heading (5-2) and the night crossing (5-5): the harbor master sets Target, so take your set Target block out. Every trip has to take the short way and stop, even 270 → 135, which never crosses north.
  2. Ten runs, measured (5-3): run your heading turn ten times against the timer turn from Room 1, and compare the two spreads in the logbook.
  3. As tight as it goes (5-6): band of 2°, 9 of 10 runs inside it. Change only the turn velocity: a tighter band needs a slower turn.
  4. The pilot's touch (bonus, 5-4): inside the loop, set turn velocity to abs of Error × a number. Start the number at 2 and ease it down until the ferry stops without rocking.

Mistakes to watch for

  • Treating heading like a ruler. It is a circle.
  • Testing only the turns that cross north. The fold has to get every turn right.
  • Calling it from one good run. Ten runs is a measurement; one run is an anecdote.
  • Shrinking the band and keeping the speed. A tighter band needs a slower turn.
The short version

Six rules for the whole harbor

Run it more than onceRead the spread, not one run. The average tunes it; the spread judges it.
Calibrate, then waitNo reading until not calibrating. Drift is degrees per minute.
Never equalsA sensor skips past exact numbers. Use < and >.
Three choicesInside the band: stop. Error positive: right. Negative: left.
Band vs speedHunting? Widen the band or slow the turn. Faster needs wider.
The short wayError = remainder of (Target − heading + 540) / 360 − 180.