ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

How to implement the robot body filter?

asked 2020-09-21 10:52:03 -0500

updated 2021-01-21 12:32:19 -0500

jayess gravatar image

Hey everybody,

I'm stuck on the implementation of the Robot Body Filter (https://github.com/peci1/robot_body_f...) I want to self filter my robot from an RGBD-Image/pointcloud2 (Realsense D435i) but I don't know how to set up the filter. I've seen lines of C++-code but I would like to get this done within a launch-file. But I can't find any tutorials or examples of that. I'm using ROS Melodic on an Ubuntu 18.04

Maybe someone could point me in the right direction.

Thank you!


Update:

Hey ahedfares89,

thanks for your reply. I tried to apply your manual but got stuck. It's probably more of an C++-problem (I'm more the python guy). Maybe you can spot the wrong thinks. I tried different ways to implement your answer but non of them worked.

#include "ros/ros.h"
#include "sensor_msgs/PointCloud2.h"
#include "filters/filter_chain.h"
#include <ros/console.h>

class robot_body_filter
{  
  filters::FilterChain<sensor_msgs::PointCloud2> filter_chain_;    
public:
  robot_body_filter()
  {
    pub_ = n_.advertise<sensor_msgs::PointCloud2>("/camera/depth/color/points_filtered", 1);
    sub_ = n_.subscribe("/camera/depth/color/points", 1, &robot_body_filter::callback, this);
  }
  void callback(const sensor_msgs::PointCloud2& input)
  {    
    sensor_msgs::PointCloud2 output;

    filter_chain_.update(input, output);
    pub_.publish(output);
  }
private:
  ros::NodeHandle n_;
  ros::Publisher pub_;
  ros::Subscriber sub_;
};

int main(int argc, char **argv)
{
  ros::init(argc, argv, "load_filter_chain");

  robot_body_filter rbf;
  rbf.configure("cloud_filter_chain");
  ros::spin();
  return 0;
}

Thanks in advance.

Robert

edit retag flag offensive close merge delete

Comments

Hello! In the wiki page (http://wiki.ros.org/robot_body_filter) You can find all the filter params. Just add them as you choose in your launch file! It this what are you asking for?

Solrac3589 gravatar image Solrac3589  ( 2020-09-22 05:12:57 -0500 )edit

I've seen the params but where/how do I specify the sensor_msgs/PointCloud2-stream that is comming from my Camera?

RobertZickler gravatar image RobertZickler  ( 2020-09-22 05:59:59 -0500 )edit

I am not sure because I didn't work with this, but checking the page it says that this filter is dependant to filters:FilterBase API (in 3.1) and is compatible with filterchain. Checking at filters web (http://wiki.ros.org/filters) there is a filterschain explanation which should be a good way to apply that.

Solrac3589 gravatar image Solrac3589  ( 2020-09-23 00:32:11 -0500 )edit
1

I've already tried to implement the filter chain but with no success. The documentation could be improved. I also wasn't able to find any working examples. I was hoping that there would be an alternativ way just by implementing the filter in a launch file. Well I guess I first have to get the filterchain-C++-Script up and running.

RobertZickler gravatar image RobertZickler  ( 2020-09-23 01:55:06 -0500 )edit
1

just checking a little i have the same impression as you. hope someone can help you! :)

Solrac3589 gravatar image Solrac3589  ( 2020-09-23 05:18:22 -0500 )edit
2

Not an answer to your question but you could also try realtime_urdf_filter

Roberto Z. gravatar image Roberto Z.  ( 2020-10-19 06:41:08 -0500 )edit

Thank you. As you can see here: http://official-rtab-map-forum.206.s1... I did exactly that. Maybe not the most elegant or most efficent way but working. Still looking for a working example of an implemented filter.

RobertZickler gravatar image RobertZickler  ( 2020-10-19 06:49:49 -0500 )edit

Hello Robert, did you manage to implement the filter? Id have some questions too

Qilos gravatar image Qilos  ( 2021-09-14 03:16:22 -0500 )edit

2 Answers

Sort by » oldest newest most voted
2

answered 2021-01-20 06:26:44 -0500

ahedfares89 gravatar image

updated 2021-01-22 10:29:07 -0500

I haven't tested my implementation much yet but this is what you need to do to make it work.

  1. Create a robot_body_filter.yaml file that will contain the configuration values required for each filter you need in your chain (could be multiple filters in the chain or only one)

    • add this file to <PACKAGE_NAME>/config/ directory.
    • refer to examples for examples of such YAML files.
    • note that params: section in your YAML file can be filled with whichever parameters needed by your filter, refer to robot_body_filter for a list of applicable parameters.
  2. Launch: robot_body_filter package does not implement launchable nodes as opposed to laser_filter package, thus, you will have to implement the functionality in your code and load the previously created robot_body_filter.yaml file to your server.

  3. load the robot_body_filter.yaml configuration file to your ros_parameter server by adding <rosparam command="load" file="$(find PACKAGE_NAME)/config/robot_body_filter.yaml" /> inside your <node> tag to load the robot_body_filter.yaml file into the parameter server.

    • create a filters::FilterChain object in your class that will be used to configure the filters listed in robot_body_filter.yaml file filters::FilterChain<T> filter_chain_;, where T is the template you need for the incoming msgs, i.e. sensor_msgs::PointCloud2 or sensor_msgs::LaserScan

    • construct the filter_chain_ object in your constructor's initialization list with the T you have previously selected filter_chain_("T")

    • configure the filter_chain_ object in your constructor filter_chain_.configure("NAME", pnh_);, where NAME is the name of your filter chain mentioned at the beginning of your robot_body_filter.yaml file (i.e. scan_filter_chain or cloud_filter_chain)

  4. at this point, your filter_chain_ (including all the listed filters) is ready to be used by the update() function, once you have the pointcloud or laserscan msg received in your callback function, apply filter_chain_.update(*msg_in, msg_out) and the result will be saved in msg_out.

Note: you will know that everything is loaded properly by seeing INFO and WARNING log messages for the listed filter parameters in the Yaml file in the log when you launch the node.


Update:

try this

#include "ros/ros.h"
#include "sensor_msgs/PointCloud2.h"
#include "filters/filter_chain.h"
#include <ros/console.h>

class robot_body_filter
{  
  filters::FilterChain<sensor_msgs::PointCloud2> filter_chain_;    
public:
  robot_body_filter() : filter_chain_("sensor_msgs::PointCloud2")
  {
    filter_chain_.configure("cloud_filter_chain");
    pub_ = n_.advertise<sensor_msgs::PointCloud2>("/camera/depth/color/points_filtered", 1);
    sub_ = n_.subscribe("/camera/depth/color/points", 1, &robot_body_filter::callback, this);
  }
  void callback(const sensor_msgs::PointCloud2ConstPtr& input)
  {    
    sensor_msgs::PointCloud2 output;
    filter_chain_.update(*input, output);
    pub_.publish(output);
  }
private:
  ros::NodeHandle n_;
  ros::Publisher pub_;
  ros::Subscriber sub_;
};

int main(int argc, char **argv)
{
  ros::init(argc, argv, "load_filter_chain");
  robot_body_filter rbf;
  ros::spin();
  return 0;
}
edit flag offensive delete link more
0

answered 2022-02-04 00:56:01 -0500

peci1 gravatar image

Hi, I know it was a bit cumbersome to actually start using the filter, so I created a helper package for it a few months ago. Have a look at http://wiki.ros.org/sensor_filters . It sets up the simplest possible node or nodelet running a single filter chain. Implementations for all sensor_msgs types are provided.

We've also added an examples folder to robot_body_filter that contains some YAML files and an example launch file. It is basically what @ahedfares89 wrote.

d435.yaml:

cloud_filter_chain:
  - name: RobotBodyFilter
    type: robot_body_filter/RobotBodyFilterPointCloud2
    params:
      frames/sensor: 'camera_color_optical_frame'
      filter/keep_clouds_organized: True
      filter/do_clipping: True
      filter/do_contains_test: True
      filter/do_shadow_test: False
      sensor/point_by_point: False
      sensor/min_distance: 0.3
      sensor/max_distance: 5.0
      body_model/inflation/scale: 1.07
      body_model/inflation/padding: 0.01
      transforms/buffer_length: 15.0
      transforms/timeout/reachable: 0.2
      transforms/timeout/unreachable: 0.2

filter.launch:

<launch>
    <node name="filter" pkg="sensor_filters" type="pointcloud2_filter_chain" output="screen">
        <rosparam command="load" file="$(dirname)/d435.yaml" />
        <remap from="~input" to="camera/depth/color/points" />
        <remap from="~output" to="camera/depth/color/points_filtered" />
    </node>
</launch>
edit flag offensive delete link more

Question Tools

4 followers

Stats

Asked: 2020-09-21 10:52:03 -0500

Seen: 645 times

Last updated: Feb 04 '22