Fix ROS 2 controller bounds and shutdown - #4
Open
wee733 wants to merge 1 commit into
Open
Conversation
Signed-off-by: 李博钊 <18622332179@163.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes undefined behavior in the ROS 2 R5 controller’s status publishing by preventing out-of-bounds writes to the 7-element joint arrays, and it removes a shutdown callback that could race with the 1 kHz publish timer and cause crashes during Ctrl+C shutdown.
Changes:
- Replace incorrect joint array loops (previously iterating with
i <= 7) with bounds-checked loops using both the ROS message array size and the SDK vector size. - Remove
rclcpp::on_shutdown(...)callback that resetinterfaces_ptr_, avoiding a potential race with timer callbacks during shutdown.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Problem
RobotStatus.msgdefines seven-element joint arrays, but the controller loops previously usedi <= 7, which writes index 7 and invokes undefined behavior.The controller also registered an
on_shutdowncallback that immediately resetinterfaces_ptr_. During a Ctrl+C shutdown this could race withPubState(), which accesses the same pointer every millisecond. On the tested system, the motor and CAN cleanup ran, but the process then exited with code-11.Relying on normal node/member destruction stops executor callbacks before releasing the hardware interface. After this change, the receiver thread and CAN socket terminate cleanly and the process exits normally.
Validation
can1colcon build --symlink-install --packages-select arx_r5_controller/arm_statusreceived at approximately 1000 HzThe official documentation targets ROS 2 Humble; maintainers should also verify the lifecycle change on Humble.