Fix reference in chained diff drive controller #1529
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.
Hi,
There seems to be an issue with the new chained diff drive implementation from PR #1485.
I initially had an issue when chaining this (
malloc(): unaligned tcache chunk detected
after loading the upstream controller). However, while hunting down the error, I found that the cleanup phase is a more easily replicable scenario to get the same problem.The bug can be reproduced following these steps), but it boils down to dereferencing of the
reference_interfaces_
data inDiffDriveController::reset_buffers()
:ros2_controllers/diff_drive_controller/src/diff_drive_controller.cpp
Lines 619 to 627 in 5486fcd
This method is called at different points in the controller:
on_configure()
,on_error()
, andon_cleanup
. Each time, the previously exported reference interface is invalidated.The
reset_buffer
method should not assign a new vector, at it invalidates the references.As far as I can see, there are only two options:
In the PR, I went with the
std::fill(...)
option, not sure if there is any argument for one against the other...Additionally, I moved the resize to the
on_configure()
method to make sure the memory is allocated right away. Otherwise, some tests break (reference_interfaces_
not allocated at first use).Are there any guidelines about that?
That seems to be the way it is done in ros2_control_demos (example_12), but not in the steering_controllers_library.cpp:
ros2_controllers/steering_controllers_library/src/steering_controllers_library.cpp
Lines 311 to 328 in 5486fcd