Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix JTC segfault #518

Merged
merged 1 commit into from
Feb 10, 2023
Merged

Fix JTC segfault #518

merged 1 commit into from
Feb 10, 2023

Conversation

mechwiz
Copy link
Contributor

@mechwiz mechwiz commented Feb 6, 2023

@swiz23 noticed a segfault in the JTC specifically when aborting a motion, followed by deactivating, followed by activating where the segfault would occur. After looking at this PR, I think it very much has to do with the line
output_state = trajectory_msgs::msg::JointTrajectoryPoint().
I think the flow of events occur as follows:

When aborting, set_hold_position() is called. That essentially adds and writes an empty trajectory message in order to disregard the current one.
When sample() is called in the update() loop, state_desired_ gets overwritten with that empty trajectory point meaning it has an empty position, velocity, and acceleration array.
The controllers get deactivated
The controllers get reactivated. When this happens, read_state_frome_hardware is called on state_desired_. Within that function, we try to index the position array within state_deisred_ as if it has the same size as dof_ when it in fact no longer does. This causes the segault.
The solution is to simply move the line defining the output_state within the sample() function in trajectory.cpp to after the last possible place that the function can return false -> here. I tested this out at least for the case that @swiz23 had issues with and verified that there was no longer a segfault.

This probably fixes #423
@JafarAbdi

@swiz23
Copy link
Contributor

swiz23 commented Feb 7, 2023

Just double checked this and also verified that it fixes my issue.

Copy link
Contributor

@JafarAbdi JafarAbdi left a comment

Choose a reason for hiding this comment

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

lgtm

@bmagyar bmagyar merged commit 3a1402e into ros-controls:master Feb 10, 2023
@bmagyar
Copy link
Member

bmagyar commented Feb 10, 2023

@Mergifyio backport to humble

@mergify
Copy link
Contributor

mergify bot commented Feb 10, 2023

backport to humble

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Feb 10, 2023
Co-authored-by: Michael Wiznitzer <michael.wiznitzer@resquared.com>
(cherry picked from commit 3a1402e)
bmagyar pushed a commit that referenced this pull request Feb 10, 2023
Co-authored-by: Michael Wiznitzer <michael.wiznitzer@resquared.com>
(cherry picked from commit 3a1402e)

Co-authored-by: Michael Wiznitzer <31753650+mechwiz@users.noreply.github.com>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants