Conversation
📝 WalkthroughWalkthroughRefactors the teleop ROS2 publisher into a TeleopRos2PublisherNode class that encapsulates initialization, parameter handling, publishers, and runtime loop; adds README subsection showing how to override ROS 2 parameters via Changes
Sequence Diagram(s)sequenceDiagram
participant Runner
participant Node as TeleopRos2PublisherNode
participant XR as TeleopSession (XR)
participant ROS as ROS2 Publishers
Runner->>Node: start (rclpy.init() & instantiate)
Node->>Node: declare/read parameters
Node->>XR: create TeleopSession / assemble sources
Node->>ROS: create publishers
loop runtime loop
Node->>XR: poll frames / get latest pose/twist/controller
XR-->>Node: pose, twist, controller data
Node->>ROS: publish hand pose, twist/root pose, controller/full_body
alt XR unavailable / error
Node->>Node: handle error, wait/retry
end
end
Runner->>Node: shutdown -> cleanup (rclpy.shutdown())
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@examples/teleop_ros2/python/teleop_ros2_publisher.py`:
- Around line 184-404: The file teleop_ros2_publisher.py was reformatted by
ruff-format in CI; run the repository's formatting hooks (e.g., pre-commit or
ruff format) locally and commit the updated file so CI no longer modifies it;
specifically run the formatter against
examples/teleop_ros2/python/teleop_ros2_publisher.py (or run pre-commit run
--all-files) and then add/commit the changes that affect
TeleopRos2PublisherNode, run(), and main() formatting to satisfy ruff-format.
- Around line 217-218: The code clamps invalid rate_hz to 1e-3 producing a 1000s
sleep; instead validate rate_hz after reading it from get_parameter and
fail-fast or apply a safe fallback: check rate_hz for <= 0 or NaN and either
raise an exception (or call self.get_logger().error and raise RuntimeError) to
stop startup, or log a warning and set a sensible default (e.g. 10.0 Hz) before
computing self._sleep_period_s; then compute self._sleep_period_s = 1.0 /
rate_hz using the validated value. Ensure you reference the same symbols:
get_parameter, rate_hz, self.get_logger(), and _sleep_period_s.
- Line 197: The parameter declaration uses a positional boolean literal in
declare_parameter which triggers Ruff FBT003; update the call to pass the
boolean as a keyword (e.g., use value=False) so it becomes explicit. Locate the
declare_parameter invocation in teleop_ros2_publisher.py (the call to
declare_parameter) and change the second argument to a named keyword argument
(value=False) to satisfy the linter and improve clarity.
- Around line 365-371: The code is creating a tuple of single-byte bytes objects
for ByteMultiArray.data which is invalid; instead use the raw bytes/sequence of
integers returned by msgpack.packb. Replace the tuple conversion where payload
is set (the lines handling controller_payload and body payload) so that payload
= msgpack.packb(controller_payload, default=mnp.encode) (and likewise for body
payload) and assign that raw bytes directly to controller_msg.data (and
body_msg.data) so ByteMultiArray receives a sequence of integers; keep using
controller_msg and body_msg as the ByteMultiArray instances and publish them as
before.
ℹ️ Review info
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (2)
examples/teleop_ros2/README.mdexamples/teleop_ros2/python/teleop_ros2_publisher.py
e5cb28b to
9a346cb
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
examples/teleop_ros2/python/teleop_ros2_publisher.py (1)
377-394:⚠️ Potential issue | 🔴 CriticalUse raw
bytesforByteMultiArray.datainstead of tuple of single-byte objects.The
tuple(bytes([a]) for a in payload)conversion on lines 380 and 391 creates a tuple ofbytesobjects (each containing a single byte), rather than a sequence of integers (0–255) thatByteMultiArray.dataexpects. This will cause serialization issues or incorrect message content.Assign the
msgpack.packb()return value directly to the message'sdatafield.Proposed fix
payload = msgpack.packb( controller_payload, default=mnp.encode ) - payload = tuple(bytes([a]) for a in payload) controller_msg = ByteMultiArray() controller_msg.data = payload self._pub_controller.publish(controller_msg)body_payload = _build_full_body_payload(full_body_data) payload = msgpack.packb(body_payload, default=mnp.encode) - payload = tuple(bytes([a]) for a in payload) body_msg = ByteMultiArray() body_msg.data = payload self._pub_full_body.publish(body_msg)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@examples/teleop_ros2/python/teleop_ros2_publisher.py` around lines 377 - 394, The code currently converts the bytes returned by msgpack.packb(...) into a tuple of single-byte bytes objects before assigning to ByteMultiArray.data, which expects a sequence of integer byte values; instead, assign the raw packed bytes directly. Update both places where payload is set (for controller_payload and for body_payload produced by _build_full_body_payload) to use payload = msgpack.packb(..., default=mnp.encode) and then set controller_msg.data = payload and body_msg.data = payload before publishing to _pub_controller and _pub_full_body respectively (keep using ByteMultiArray).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@examples/teleop_ros2/python/teleop_ros2_publisher.py`:
- Around line 377-394: The code currently converts the bytes returned by
msgpack.packb(...) into a tuple of single-byte bytes objects before assigning to
ByteMultiArray.data, which expects a sequence of integer byte values; instead,
assign the raw packed bytes directly. Update both places where payload is set
(for controller_payload and for body_payload produced by
_build_full_body_payload) to use payload = msgpack.packb(...,
default=mnp.encode) and then set controller_msg.data = payload and body_msg.data
= payload before publishing to _pub_controller and _pub_full_body respectively
(keep using ByteMultiArray).
ℹ️ Review info
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (2)
examples/teleop_ros2/README.mdexamples/teleop_ros2/python/teleop_ros2_publisher.py
Summary by CodeRabbit
Documentation
Improvements