Skip to content

Add ROS2 Action client, server, and .action codegen support - #327

Open
comoc wants to merge 5 commits into
Unity-Technologies:mainfrom
comoc:main
Open

comoc wants to merge 5 commits into
Unity-Technologies:mainfrom
comoc:main

Conversation

@comoc

@comoc comoc commented Apr 10, 2026

Copy link
Copy Markdown

Proposed change(s)

Add ROS2 Action support: C# client/server classes, ROSConnection integration, and .action file code generation. Works with a patched ROS-TCP-Endpoint (PR #178).

New classes

  • ROSActionClient<TGoal, TResult, TFeedback> — async SendGoal, feedback events via ActionGoalHandle, GetResult, Cancel
  • ROSActionServer<TGoal, TResult, TFeedback> — GoalReceived event, PublishFeedback, SetResult via ActionServerGoalHandle

ROSConnection integration

  • CreateActionClient() / CreateActionServer() factory methods
  • AllocateServiceRequest() for thread-safe srv_id allocation
  • QueueRawMessage() for data frames without publisher registration
  • TryRouteToActionServer() for goal dispatch via existing __request/__response
  • FindObjectOfType -> FindAnyObjectByType (deprecation fix)

.action code generation

  • ActionAutoGen.GenerateFeedbackMessage() — generates a ROS2-style FeedbackMessage class (UUID + Feedback body) with dual MessageRegistry registration for both short and /action/ type name variants
  • Robotics > Generate ROS Messages now produces FeedbackMessage.cs alongside Goal/Result/Feedback for each .action file

SysCommand additions

6 new constants + 3 param structs for __action_client, __action_send_goal, __action_get_result, __action_cancel_goal, __action_server, __action_publish_feedback

Useful links

Types of change(s)

  • Bug fix
  • New feature
  • Code refactor
  • Documentation update
  • Other

Testing and Verification

  1. Action client (Unity -> ROS2 fibonacci_action_server): 9 feedback messages + result [0,1,1,2,3,5,8,13,21,34,55]
  2. Action server (ros2 action send_goal -> Unity): 4 feedback messages + result [0,1,1,2,3,5] with SUCCEEDED
  3. Reconnect after endpoint restart: feedback subscription re-registers correctly
  4. .action codegen: Generate ROS Messages produces FibonacciFeedbackMessage.cs with correct dual registration

Test Configuration:

  • Unity Version: Unity 6000.0
  • Unity machine OS: Windows 11
  • ROS machine OS + version: Ubuntu 22.04, ROS2 Humble
  • ROS-Unity communication: TCP (WSL2)

Checklist

  • Ensured this PR is up-to-date with the main branch
  • Created this PR to target the dev branch (Note: dev branch last updated 2022)
  • Followed the style guidelines as described in the Contribution Guidelines
  • Added tests that prove my fix is effective or that my feature works
  • Updated the Changelog
  • Updated the documentation as appropriate

Notes

Requires companion endpoint changes in PR #178. Fully backwards-compatible — existing functionality unaffected. Wiki documentation available at https://github.com/comoc/ROS-TCP-Connector/wiki

comoc and others added 4 commits April 10, 2026 12:44
Adds C# Action client and server classes that work with the patched
ROS-TCP-Endpoint (comoc/ROS-TCP-Endpoint, main-ros2 branch) to
bridge ROS2 Actions through the TCP connection.

SysCommand.cs:
- 6 new command constants (__action_client, __action_send_goal,
  __action_get_result, __action_cancel_goal, __action_server,
  __action_publish_feedback)
- 3 new param structs (SysCommand_ActionRegistration,
  SysCommand_ActionGoalOp, SysCommand_ActionFeedback)

ROSActionClient.cs:
- ROSActionClient<TGoal, TResult, TFeedback> with async SendGoal()
  returning ActionGoalHandle
- ActionGoalHandle with async GetResult(), Cancel(), and
  FeedbackReceived event
- RegisterFeedbackSubscription<TFeedbackMessage>() for wiring up
  goal-specific feedback routing via SubscribeByMessageName
- GetResultRequestProxy and CancelGoalRequestProxy internal messages
- Handles the endpoint's UUID-prepend convention on SendGoal response
- Skips int8 status + alignment padding in GetResult response

ROSActionServer.cs:
- ROSActionServer<TGoal, TResult, TFeedback> with GoalReceived event
- ActionServerGoalHandle with PublishFeedback() and SetResult()
- Goal routing via __request/__response reusing existing service
  infrastructure

ROSConnection.cs:
- AllocateServiceRequest() internal helper for thread-safe srv_id
  allocation without exposing private fields
- QueueRawMessage() internal helper for sending data frames without
  triggering Publish()'s publisher-registration check
- CreateActionClient<>() and CreateActionServer<>() factory methods
- TryRouteToActionServer() for __request dispatch to action servers
- Action server routing integrated into ReceiveSysCommand's
  m_SpecialIncomingMessageHandler
- FindObjectOfType -> FindAnyObjectByType (deprecation fix)

Hand-written Fibonacci message classes for testing:
- FibonacciGoal, FibonacciResult, FibonacciFeedback,
  FibonacciFeedbackMessage (with dual MessageRegistry registration
  for short and /action/ type name variants)

Verified end-to-end:
- Action client: Unity -> ROS2 fibonacci_action_server, all 9
  feedback messages + result [0,1,1,2,3,5,8,13,21,34,55]
- Action server: ros2 action send_goal -> Unity, 4 feedback messages
  + result [0,1,1,2,3,5] with SUCCEEDED status
- Reconnect after endpoint restart works correctly
Add ROS2 Action client and server support
ActionAutoGen now generates a ROS2-style FeedbackMessage class
alongside the existing Goal/Result/Feedback classes. The generated
class contains:
- byte[16] goal_id (UUID for goal routing)
- Feedback body (the user-defined Feedback type)
- Dual MessageRegistry registration for both the short type name
  (pkg/Action_FeedbackMessage) and the /action/ variant that
  __topic_list reports

This eliminates the need to hand-write FeedbackMessage classes
for each Action type. The class is required by
ROSActionClient.RegisterFeedbackSubscription to route feedback
to the correct ActionGoalHandle.
Copilot AI review requested due to automatic review settings April 10, 2026 05:47
@cla-assistant-unity

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds ROS2 Action support to the Unity ROS-TCP-Connector by introducing C# action client/server APIs, integrating action routing into ROSConnection, and extending .action code generation to emit ROS2-style *_FeedbackMessage types.

Changes:

  • Add ROSActionClient / ROSActionServer APIs and integrate action syscommands + routing into ROSConnection.
  • Add new SysCommand constants/param structs required for action registration and operations.
  • Extend .action codegen to generate ROS2 FeedbackMessage classes (UUID + Feedback) with dual type-name registration.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
com.unity.robotics.ros-tcp-connector/Runtime/TcpConnector/SysCommand.cs Adds action-related syscommand constants and payload structs.
com.unity.robotics.ros-tcp-connector/Runtime/TcpConnector/ROSConnection.cs Adds action factories, raw-frame queueing, service-id allocation helper, and action server routing hook; updates deprecated Unity API usage.
com.unity.robotics.ros-tcp-connector/Runtime/TcpConnector/ROSActionServer.cs.meta Unity asset metadata for new action server file.
com.unity.robotics.ros-tcp-connector/Runtime/TcpConnector/ROSActionServer.cs New Unity-side ROS2 action server implementation and goal handle.
com.unity.robotics.ros-tcp-connector/Runtime/TcpConnector/ROSActionClient.cs.meta Unity asset metadata for new action client file.
com.unity.robotics.ros-tcp-connector/Runtime/TcpConnector/ROSActionClient.cs New Unity-side ROS2 action client and goal handle APIs.
com.unity.robotics.ros-tcp-connector/Runtime/Messages/ActionTutorialsInterfaces/action/FibonacciResult.cs.meta Unity asset metadata for generated message.
com.unity.robotics.ros-tcp-connector/Runtime/Messages/ActionTutorialsInterfaces/action/FibonacciResult.cs Generated action Result message type.
com.unity.robotics.ros-tcp-connector/Runtime/Messages/ActionTutorialsInterfaces/action/FibonacciGoal.cs.meta Unity asset metadata for generated message.
com.unity.robotics.ros-tcp-connector/Runtime/Messages/ActionTutorialsInterfaces/action/FibonacciGoal.cs Generated action Goal message type.
com.unity.robotics.ros-tcp-connector/Runtime/Messages/ActionTutorialsInterfaces/action/FibonacciFeedbackMessage.cs.meta Unity asset metadata for generated message.
com.unity.robotics.ros-tcp-connector/Runtime/Messages/ActionTutorialsInterfaces/action/FibonacciFeedbackMessage.cs Generated ROS2 wire-level FeedbackMessage (UUID + Feedback) with dual registration.
com.unity.robotics.ros-tcp-connector/Runtime/Messages/ActionTutorialsInterfaces/action/FibonacciFeedback.cs.meta Unity asset metadata for generated message.
com.unity.robotics.ros-tcp-connector/Runtime/Messages/ActionTutorialsInterfaces/action/FibonacciFeedback.cs Generated action Feedback message type.
com.unity.robotics.ros-tcp-connector/Runtime/Messages/ActionTutorialsInterfaces/action.meta Unity folder metadata for generated action message folder.
com.unity.robotics.ros-tcp-connector/Runtime/Messages/ActionTutorialsInterfaces.meta Unity folder metadata for generated message package folder.
com.unity.robotics.ros-tcp-connector/Editor/MessageGeneration/ActionAutoGen.cs Extends .action generation to emit ROS2 FeedbackMessage classes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- ROSActionServer: catch goal deserialization/handler exceptions and
  reply with an empty result when GoalReceived has no subscriber, so the
  ROS 2 action client is not left hanging
- ROSActionServer: remove completed goals from m_ActiveGoals on SetResult
- ROSConnection: route goal requests via an internal interface instead of
  reflection (also safe under IL2CPP stripping)
- ROSConnection: use a dedicated MessageSerializer in QueueRawMessage
- ROSActionClient: drop goal handles after GetResult / successful Cancel
- ActionAutoGen: include FeedbackMessage.cs in GetActionClassPaths

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants