Skip to content

feat: add Teensy communication node - #4

Draft
ericcai32 wants to merge 19 commits into
mainfrom
teensy-initial
Draft

ericcai32 wants to merge 19 commits into
mainfrom
teensy-initial

Conversation

@ericcai32

@ericcai32 ericcai32 commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add ROS 2 node for communicating with the Teensy through a serial port. Apologies for the large PR. Most changes are boilerplate and tests; the important changes are in teensy_node.py and serial_port.py.

Changes

  • The majority of code is migrated from teensy_node.py and teensy.py in the sailbot repo.
  • Instead of the sailboat_main ROS 2 package, the sailing package will contain reinforcement_learning and teensy subdirectories.
  • Fixed bug with the PHYSICAL.MAX_RUDDER_ANGLE constant being set to -25 instead of -45 causing errors in angle conversion math. For an operational clamp, a separate constant should be used.
  • Instead of INFO logs, the sending and receiving packets log DEBUG logs that are hidden by default. Warnings on send and receive errors are also throttled to a rate of WARNING_THROTTLE_SECONDS.

Testing

  • Added serial driver tests for packet parsing, command encoding, and connection cleanup.
  • Added ROS node tests for command forwarding and telemetry publishing.
  • Covered serial failures, missing telemetry, invalid polling settings, and shutdown behavior.

Future Work

  • Add functionality for Teensy to pass up VectorNav and anemometer readings to RL algo.
  • Add functionality for ROS 2 to pass down a latlong coordinate to Teensy for determinstic algo.

@ericcai32 ericcai32 self-assigned this Sep 19, 2026
@ericcai32
ericcai32 force-pushed the teensy-initial branch 2 times, most recently from 3f435c4 to 7724577 Compare September 19, 2026 21:05
return result


def main(args=None):

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.

If the Teensy is unplugged or the port is wrong, Teensy() crashes after ROS is already started. This finally never runs, so ROS is never shut down. (which is fine if the whole process dies, but it breaks if a test or another script catches the error and keeps going)

tldr I think it's safer to set teensy_node = None before the try. In finally, only destroy the node if it was created, and always call rclpy.try_shutdown() after that

@ericcai32
ericcai32 marked this pull request as draft September 21, 2026 22:39
@ericcai32

Copy link
Copy Markdown
Contributor Author

Changed to draft pending @nizhnerk's code quality changes.

@nizhnerk
nizhnerk removed their request for review November 3, 2026 02:19
incoming_byte = self.serial.read()[0]

# If we see START_FLAG, prepare for reading in a new packet.
if incoming_byte == SERIAL.TX_START_FLAG:

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.

correct me if i'm wrong, but the Teensy marks the start of a message with the byte 0xFF and the end with 0xEE, and nothing is restricting these bytes from getting sent in as actual wind directions in the packet itself? so if wind is either 0xEE or 0xFF the message is discarded/mangled. I think the fix would be to add an extra byte of some sort to indicate that the following byte is actual wind data/differentiate it from start/end markers

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.

yeah this is something i've been chewing on for a bit, i'll fix it before this pr is ready


def mainsail_angle_callback(self, msg):
"""Update the mainsail goal and send the full command."""
self.desired_mainsail_angle = msg.data

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.

i think this change would need to happen in the other callbacks too, but I assume we should safeguard against bad values. i.e, check the new angle against the allowed range before saving it. If it is outside that range, leave the old value in place and skip the send, so one bad rudder command cannot block the mainsail and jib commands that come after it

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.

3 participants