Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix polygon padding on filter load #191

Merged
merged 4 commits into from
Mar 24, 2024

Conversation

geotsam
Copy link

@geotsam geotsam commented Mar 13, 2024

The issue:
Setting the polygon filter parameters from a .yaml results in correct parameters loaded in the parameter server (and can be seen in rqt_reconfigure). However, the filter itself does not incorporate the padding, unless the reconfigureCb() is called at least once. This can also be seen in rViz by inspecting the Polygon messages.

The solution:
Calling padPolygon() once in configure() in order to correctly pad the polygon inside the node.

@jonbinney
Copy link
Contributor

This looks reasonable. Before I merge I'm going to dig into the initialization code of DynamicReconfigure to make sure I understand in exactly what sequence things happen. One question so that I can reproduce your exact use case: When you say you're setting the parameters from a yaml file, are you loading the yaml file onto the parameter server in your roslaunch file? Is it the same roslaunch file you're using to launch the laser filters node?

@geotsam
Copy link
Author

geotsam commented Mar 14, 2024

Yes @jonbinney, the parameters are loaded from a launch file like this:

<node pkg="laser_filters" type="scan_to_scan_filter_chain" output="screen" name="laser_filter_rear">
    <remap from="scan" to="raw_scan_rear" />
    <remap from="scan_filtered" to="scan_rear" />
    <rosparam command="load" file="$(find my_robot_bringup)/config/laser_filters_rear.yaml" />
</node>

I'll also provide you with the yaml:

scan_filter_chain:
- name: footprint_filter
  type: laser_filters/LaserScanPolygonFilter
  params:
    polygon_frame: base_link
    polygon: [[0.16, 0.27], [0.16, -0.27], [-0.45, -0.27], [-0.45, 0.27]] 
    invert: false
    polygon_padding: 0.30

Setting a large polygon_padding (like 0.3) will make the issue quickly apparent 😅

@jonbinney
Copy link
Contributor

The problem here seems to come from dynamic_reconfigure not supporting variable size arrays. The initial value for polygon that is defined in the YAML and loaded onto the parameter is an array, which is supported by XmlRpc (which the is how ROS1 represents parameters). Since dynamic reconfigure can't handle arrays, it expects polygon to be a string. To workaround this, LaserScanPolygonFilterBase::configure() loads the array representation from the polygon parameter, converts it to a string, and then overwrites the parameter with that string. This is really ugly.... but mostly works.

As @geotsam points out, padPolygon() doesn't get called until dynamic reconfigure calls LaserScanPolygonFilterBase::reconfigureCb(). That actually happens when dyn_server_->setCallback(f); is called earlier in configure(), but at that point the polygon parameter hasn't yet been converted from an array to a string. I think that waiting to call dyn_server_->setCallback(f); until later in the code will be a cleaner fix; i'll add a review comment to that effect.

src/polygon_filter.cpp Outdated Show resolved Hide resolved
@geotsam
Copy link
Author

geotsam commented Mar 21, 2024

Some auto-formatting slipped in the previous commit and modified the whole file 😖; I pushed a new one that only changes the lines we are discussing.

@jonbinney
Copy link
Contributor

One more nitpick - could you add back the end line at the end of the file? Looks like that was left in from the autoformat.

@geotsam
Copy link
Author

geotsam commented Mar 24, 2024

It should be fine now! I added the end line back.

@jonbinney
Copy link
Contributor

Thank you @geotsam!

@jonbinney jonbinney merged commit 75913d5 into ros-perception:noetic-devel Mar 24, 2024
2 checks passed
@geotsam
Copy link
Author

geotsam commented Jul 10, 2024

Hi @jonbinney! Do you know if the apt noetic package is going to be updated to include this fix?

@jonbinney
Copy link
Contributor

@geotsam I'll do a release this week. Sorry it has taken a while!

@jonbinney
Copy link
Contributor

Tracking release process in this issue: #200

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