Skip to content

Commit 95980e1

Browse files
authored
Merge pull request #3 from ipa-svn/feature/without_msgs_filter
Merge clean and working version without message filter interface: Feature/without msgs filter
2 parents 3aa3081 + 5ca6504 commit 95980e1

10 files changed

+626
-134
lines changed

CMakeLists.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,34 @@ find_package(catkin REQUIRED COMPONENTS
66
nodelet
77
roscpp
88
sensor_msgs
9+
tf
910
tf2
1011
tf2_ros
1112
tf2_sensor_msgs
1213
tf2_geometry_msgs
14+
pcl_ros
1315
)
1416

1517
catkin_package(
1618
INCLUDE_DIRS include
17-
LIBRARIES pointcloud_to_laserscan ipa_pointcloud_to_laserscan
18-
CATKIN_DEPENDS roscpp message_filters nodelet sensor_msgs tf2 tf2_ros tf2_sensor_msgs tf2_geometry_msgs
19+
LIBRARIES pointcloud_to_laserscan ipa_pointcloud_to_laserscan roi_outlier_removal
20+
CATKIN_DEPENDS roscpp message_filters nodelet sensor_msgs tf2 tf2_ros tf2_sensor_msgs tf2_geometry_msgs pcl_ros
1921
)
2022

2123
include_directories(
2224
include
2325
${catkin_INCLUDE_DIRS}
2426
)
2527

28+
add_library(frame_publisher src/frame_publisher.cpp)
29+
target_link_libraries(frame_publisher ${catkin_LIBRARIES})
30+
31+
add_executable(frame_publisher_node src/frame_publisher_node.cpp)
32+
target_link_libraries(frame_publisher_node frame_publisher ${catkin_LIBRARIES})
33+
34+
add_library(roi_outlier_removal src/roi_outlier_removal_nodelet.cpp)
35+
target_link_libraries(roi_outlier_removal ${catkin_LIBRARIES})
36+
2637
add_library(pointcloud_to_laserscan src/pointcloud_to_laserscan_nodelet.cpp)
2738
target_link_libraries(pointcloud_to_laserscan ${catkin_LIBRARIES})
2839

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#ifndef FRAME_PUB_H
2+
#define FRAME_PUB_H
3+
4+
#include <ros/ros.h>
5+
6+
#include <tf/transform_listener.h>
7+
#include <tf/transform_broadcaster.h>
8+
#include <tf/transform_datatypes.h>
9+
10+
class FramePublisher
11+
{
12+
public:
13+
bool initialize();
14+
15+
private:
16+
void frameBroadcastCallback(const ros::TimerEvent& event);
17+
18+
private:
19+
ros::NodeHandle nh_, priv_nh_;
20+
tf::TransformListener tf_listener_;
21+
tf::TransformBroadcaster tf_broadcaster_;
22+
23+
ros::Timer frame_broadcast_timer_;
24+
double update_rate_;
25+
std::string base_frame_;
26+
std::string rotation_frame_;
27+
std::string target_frame_;
28+
bool rot_z_, rot_x_, rot_y_;
29+
};
30+
31+
#endif // FRAME_PUB_H

include/pointcloud_to_laserscan/ipa_pointcloud_to_laserscan_nodelet.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
#include "tf2_ros/buffer.h"
5050
#include "tf2_ros/transform_listener.h"
5151
#include "tf2_ros/message_filter.h"
52-
#include "message_filters/subscriber.h"
52+
#include <tf2_sensor_msgs/tf2_sensor_msgs.h>
53+
#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
5354
#include "sensor_msgs/PointCloud2.h"
5455
#include <pointcloud_to_laserscan/scan_outlier_removal_filter.h>
5556

@@ -72,21 +73,17 @@ namespace pointcloud_to_laserscan
7273
virtual void onInit();
7374

7475
void cloudCb(const sensor_msgs::PointCloud2ConstPtr &cloud_msg);
75-
void failureCb(const sensor_msgs::PointCloud2ConstPtr &cloud_msg,
76-
tf2_ros::filter_failure_reasons::FilterFailureReason reason);
7776

78-
void connectCb();
79-
80-
void disconnectCb();
77+
void convert_pointcloud_to_laserscan(const sensor_msgs::PointCloud2ConstPtr &cloud, sensor_msgs::LaserScan &output, const tf2::Transform &T, const double range_min );
8178

8279
ros::NodeHandle nh_, private_nh_;
8380
ros::Publisher pub_;
8481
boost::mutex connect_mutex_;
8582

8683
boost::shared_ptr<tf2_ros::Buffer> tf2_;
8784
boost::shared_ptr<tf2_ros::TransformListener> tf2_listener_;
88-
message_filters::Subscriber<sensor_msgs::PointCloud2> sub_;
89-
boost::shared_ptr<MessageFilter> message_filter_;
85+
86+
ros::Subscriber sub_;
9087

9188
scan_outlier_filter::ScanOutlierRemovalFilter outlier_filter_;
9289
// ROS Parameters
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Software License Agreement (BSD License)
3+
*
4+
* Copyright (c) 2010-2012, Willow Garage, Inc.
5+
* All rights reserved.
6+
*
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions
9+
* are met:
10+
*
11+
* * Redistributions of source code must retain the above copyright
12+
* notice, this list of conditions and the following disclaimer.
13+
* * Redistributions in binary form must reproduce the above
14+
* copyright notice, this list of conditions and the following
15+
* disclaimer in the documentation and/or other materials provided
16+
* with the distribution.
17+
* * Neither the name of Willow Garage, Inc. nor the names of its
18+
* contributors may be used to endorse or promote products derived
19+
* from this software without specific prior written permission.
20+
*
21+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31+
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32+
* POSSIBILITY OF SUCH DAMAGE.
33+
*
34+
*
35+
*/
36+
37+
/*
38+
* Author: Sofie Nilsson
39+
*/
40+
41+
#ifndef ROI_OUTLIER_REMOVAL_NODELET
42+
#define ROI_OUTLIER_REMOVAL_NODELET
43+
44+
#include "ros/ros.h"
45+
#include "boost/thread/mutex.hpp"
46+
47+
#include "nodelet/nodelet.h"
48+
#include "tf2_ros/buffer.h"
49+
#include "tf2_ros/transform_listener.h"
50+
#include "tf2_ros/message_filter.h"
51+
#include <tf2_sensor_msgs/tf2_sensor_msgs.h>
52+
#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
53+
#include "sensor_msgs/PointCloud2.h"
54+
55+
// includes for pcl filtering
56+
#include <pcl_ros/point_cloud.h>
57+
58+
namespace pointcloud_to_laserscan
59+
{
60+
typedef tf2_ros::MessageFilter<sensor_msgs::PointCloud2> MessageFilter;
61+
/**
62+
* The ROI outlier removal removes all points outside the specified region of interest (ROI) and publishes the remaining points into a new pointcloud.
63+
* The roi is defined as a z value range, angle range in the xy plane, and a max and min range in the xyy plane, for a chosen frame.
64+
* The filter converts the roi borders to to the original pointcloud frame in order to not have to waist time on transforming points
65+
* that are not to be used later on.
66+
* The points within the roi are transformed to and published in the same frame as the borders were given.
67+
* The filter is relevant to the pointcloud to laserscan transformation since it creates a possibility to apply additional statistical filtering
68+
* to a reduced pointcloud before creating the scan. The loclation of this filter within the pointcloud to laserscan package is however questionable.
69+
*/
70+
class RoiOutlierRemovalNodelet : public nodelet::Nodelet
71+
{
72+
73+
public:
74+
RoiOutlierRemovalNodelet();
75+
void configure_filter();
76+
77+
private:
78+
virtual void onInit();
79+
80+
void cloudCb(const sensor_msgs::PointCloud2ConstPtr &cloud_msg);
81+
82+
void reduce_point_cloud_to_roi(const pcl::PointCloud<pcl::PointXYZ>::Ptr pcl_cloud,
83+
pcl::PointCloud<pcl::PointXYZ>::Ptr reduced_pcl_cloud,
84+
const tf2::Transform &T);
85+
86+
ros::NodeHandle nh_, private_nh_;
87+
ros::Publisher pub_;
88+
89+
boost::shared_ptr<tf2_ros::Buffer> tf2_;
90+
boost::shared_ptr<tf2_ros::TransformListener> tf2_listener_;
91+
92+
ros::Subscriber sub_;
93+
94+
// ROS Parameters
95+
unsigned int input_queue_size_;
96+
std::string roi_def_frame_;
97+
double tolerance_;
98+
double min_height_, max_height_, angle_min_, angle_max_, angle_increment_, range_min_, range_max_;
99+
};
100+
101+
} // roi_outlier_removal
102+
103+
#endif // ROI_OUTLIER_REMOVAL_NODELET

nodelets.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,15 @@
2121
</class>
2222

2323
</library>
24+
25+
<library path="lib/libroi_outlier_removal">
26+
27+
<class name="pointcloud_to_laserscan/RoiOutlierRemovalNodelet"
28+
type="pointcloud_to_laserscan::RoiOutlierRemovalNodelet"
29+
base_class_type="nodelet::Nodelet">
30+
<description>
31+
Nodelet to remove all points not witin the defined field of view. The remaining points are published to a new pointcloud.
32+
</description>
33+
</class>
34+
35+
</library>

package.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,23 @@
2020
<build_depend>nodelet</build_depend>
2121
<build_depend>roscpp</build_depend>
2222
<build_depend>sensor_msgs</build_depend>
23+
<build_depend>tf</build_depend>
2324
<build_depend>tf2</build_depend>
2425
<build_depend>tf2_ros</build_depend>
2526
<build_depend>tf2_sensor_msgs</build_depend>
2627
<build_depend>tf2_geometry_msgs</build_depend>
28+
<build_depend>pcl_ros</build_depend>
2729

2830
<run_depend>message_filters</run_depend>
2931
<run_depend>nodelet</run_depend>
3032
<run_depend>roscpp</run_depend>
3133
<run_depend>sensor_msgs</run_depend>
34+
<run_depend>tf</run_depend>
3235
<run_depend>tf2</run_depend>
3336
<run_depend>tf2_ros</run_depend>
3437
<run_depend>tf2_sensor_msgs</run_depend>
3538
<run_depend>tf2_geometry_msgs</run_depend>
39+
<run_depend>pcl_ros</run_depend>
3640

3741
<export>
3842
<nodelet plugin="${prefix}/nodelets.xml"/>

src/frame_publisher.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include <pointcloud_to_laserscan/frame_publisher.h>
2+
3+
bool FramePublisher::initialize()
4+
{
5+
priv_nh_ = ros::NodeHandle("~");
6+
7+
priv_nh_.param<double>("update_rate", update_rate_, 0.01); // 100Hz
8+
9+
priv_nh_.param<std::string>("base_frame", base_frame_, "base_link");
10+
priv_nh_.param<std::string>("rotation_frame", rotation_frame_, "torso_center_link");
11+
priv_nh_.param<std::string>("target_frame", target_frame_, "torso_rotated_base_link");
12+
13+
priv_nh_.param<bool>("rot_z", rot_z_, false);
14+
priv_nh_.param<bool>("rot_x", rot_x_, false);
15+
priv_nh_.param<bool>("rot_y", rot_y_, false);
16+
17+
frame_broadcast_timer_ = nh_.createTimer(ros::Duration(update_rate_), &FramePublisher::frameBroadcastCallback, this);
18+
19+
ros::Duration(1.0).sleep(); //give tf_listener some time
20+
21+
return true;
22+
}
23+
24+
/// Broadcast a frame aligned with the base frame but rotated around specified axes as rotation_frame
25+
void FramePublisher::frameBroadcastCallback(const ros::TimerEvent& event)
26+
{
27+
tf::StampedTransform frame_transform;
28+
try
29+
{
30+
tf_listener_.waitForTransform(base_frame_, rotation_frame_, event.current_real, ros::Duration(0.1));
31+
tf_listener_.lookupTransform(base_frame_, rotation_frame_, ros::Time(0), frame_transform);
32+
}
33+
catch (tf::TransformException& ex)
34+
{
35+
ROS_ERROR("FramePublisher::getTransform: \n%s", ex.what());
36+
return;
37+
}
38+
39+
double rot_frame_roll, rot_frame_pitch, rot_frame_yaw;
40+
frame_transform.getBasis().getRPY(rot_frame_roll, rot_frame_pitch, rot_frame_yaw);
41+
tf::Transform target_transform(frame_transform.getRotation());
42+
43+
// Use rotations according to settings
44+
double target_frame_roll = 0;
45+
double target_frame_pitch = 0;
46+
double target_frame_yaw = 0;
47+
if (rot_z_){ target_frame_yaw = rot_frame_yaw;}
48+
if (rot_x_){ target_frame_roll = rot_frame_roll;}
49+
if (rot_y_){ target_frame_pitch = rot_frame_pitch;}
50+
51+
target_transform.getBasis().setRPY(target_frame_roll, target_frame_pitch, target_frame_yaw);
52+
53+
// Broadcast new frame
54+
tf_broadcaster_.sendTransform(tf::StampedTransform(target_transform, frame_transform.stamp_, base_frame_, target_frame_));
55+
}

src/frame_publisher_node.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <ros/ros.h>
2+
#include <pointcloud_to_laserscan/frame_publisher.h>
3+
4+
int main(int argc, char **argv)
5+
{
6+
ros::init(argc, argv, "msh_frame_publisher_node");
7+
FramePublisher* ad = new FramePublisher();
8+
9+
if (!ad->initialize())
10+
{
11+
ROS_ERROR("Failed to initialize FramePublisher");
12+
return -1;
13+
}
14+
15+
ros::spin();
16+
return 0;
17+
}

0 commit comments

Comments
 (0)