Skip to content

feat: port deterministic sailing algorithm to Teensy - #14

Open
nizhnerk wants to merge 17 commits into
mainfrom
algo_initial
Open

nizhnerk wants to merge 17 commits into
mainfrom
algo_initial

Conversation

@nizhnerk

Copy link
Copy Markdown
Member

The deterministic algo is now on the Teensy!

This PR brings initial deterministic algorithm tasks over from sailbot to boat -- this time in the teensy/ codebase rather than as ROS nodes. Currently, the deterministic algorithm for trimming the sails is fully implemented, while the algorithm for setting the rudder is not.


Core Functionality

The biggest architecture change to this codebase was the new sailing/ directory, created to store the new deterministic algorithm tasks. It contains:

  • sail_trim_algo -- a task which corresponds to the old trim_sail node from sailbot.
  • steering_algo -- a task which corresponds to Albo, or more generally, the state machine that we used to simply label as the "sailing algorithm".

Note that steering_algo is currently only a filler/fake -- an actual deterministic steering algorithm has not been written or ported over yet. This simplified version acts as (helpful) boilerplate: something that can hopefully be used by the sailbench team as they figure out testing.

Other Notable Changes

In order to work the above algorithm tasks into the existing Teensy codebase, some global modifications had to be made. The most important such changes include:

  • ControlMode (in contants.hpp) and the parallel control::mode in the SFR: more explicit bookkeeping to represent current control mode state (Radio or RC or deterministic algorithm). This replaces the implicit multiplexer we had before, which was tied only to the radio_flag SFR field.
    • The control mode flags were reordered to better reflect the priority we want: 0 represents being in RC mode, (unlike before), 1 represents being in ROS/RL algo mode, and 2 represents being in deterministic algo mode.
    • ServoControlTask and LedControlTask were updated accordingly in how they handled each control mode.
  • AnemometerMonitor: the angle-reading convention was finally modernized so that a value of 0 represents being head-to-wind, and a value of 180 represents being dead downwind.
  • TelemetryControlTask: restructured slightly to match the control flow of the deterministic algorithm tasks.
  • MainControlLoop -- algorithm tasks entered and execution order optimized.

Finally, tests were added to enforce all of the above functionality:

  • sail_trim -- added to the suite to verify the new sail trimming logic of the corresponding algorithm task.
  • anemometer, led, servo_control -- verify the convention updates described above.

Remaining Work

The new control mode conventions on the Teensy must be reflected elsewhere in the CUSail stack. Most notably, for the RC app:

  • We need functionality to handle switching the control mode beyond just radio and USB inputs -- we need to be able to specify deterministic algorithm now as well.
  • The flag that corresponds to radio mode is no longer 1: before, that (or more generally radio_flag != 0) meant to initiate radio mode; now, radio_flag = 0 (or more generally radio_flag != {1, 2}) means to initiate radio mode. This needs to be reflected in the packet sent by the RC app.

Also, we need to test the anemometer physically to double check what side of the boat receives which angle (e.g. does a reading of 90 degrees mean wind on the port or starboard side of the boat).

@nizhnerk nizhnerk self-assigned this Nov 11, 2026

@nicoleluo7 nicoleluo7 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - sail trim on the Teensy and new control modes make sense, and the tests adequately cover the mode switch and the wind-angle changes. approving now, agreeing that RC app mode change and the physical anemometer check are still left as follow-ups.

@EmithU EmithU left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll work on fixing the app/Pico side of things, this is non-trivial because there's only 1 bit for storing control mode right now, we'll need to update it to 2. Should be pretty quick. This looks good though 👍

@ericcai32 ericcai32 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@EmithU EmithU left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@EmithU EmithU left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants