Skip to content

feat: add Teensy communication node - #4

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

ericcai32 wants to merge 5 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

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


# uint8_t to int8_t conversion for negative values.
mainsail_angle = packet[2] - 256 if packet[2] >= 128 else packet[2]
mainsail_angle = (

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

When we send a sail angle, we send it as-is. When we read it back, we flip it (90 - angle) - I don't remember if this is the intended behavior? @nizhnerk

@nizhnerk nizhnerk Sep 20, 2026 •

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 I remember this popping up in sailbot sometime before comp because of a servo issue but it's not right.

@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.

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