Skip to content

Commit 5133423

Browse files
authored
Moved PCL Transformation into the sb_pointcloud_processing package (#371)
* Revert "Revert "Pegged librealsense Version as a Temporary Fix (#359)" (#361)" This reverts commit 863ae21. * Changed setup_realsense realsense version to a working version * Updated realsense version * Fixed install_tools script * Refactored zed_transform to pcl_transform and added a new param * Fixed output frame_id for pcl_transform * Update src/sb_pointcloud_processing/src/pcl_transform.cpp Removed space between time and (s) Co-Authored-By: RobynCastro <[email protected]> * Reordered CMakeLists.txt and changed when pcl_transform will log messages
1 parent 3b6184d commit 5133423

File tree

5 files changed

+77
-44
lines changed

5 files changed

+77
-44
lines changed

src/sb_gazebo/CMakeLists.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,12 @@ include_directories(
4141

4242
## Declare a C++ executable
4343
# add_executable(gazebo_node src/gazebo_node.cpp)
44-
add_executable(zed_transform src/zed_transform.cpp)
44+
4545

4646
## Specify libraries to link a library or executable target against
4747
# target_link_libraries(gazebo_node
4848
# ${catkin_LIBRARIES}
4949
# )
50-
target_link_libraries(zed_transform ${catkin_LIBRARIES} ${sb_utils_LIBRARIES})
5150

5251

5352
#############

src/sb_gazebo/launch/elsax_control.launch

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</include>
2020

2121
<!-- This is for jfrost's depthcamera/kinect/zed plugin -->
22-
<node name="zed_transform" pkg="sb_gazebo" type="zed_transform" output="screen">
22+
<node name="zed_transform" pkg="sb_pointcloud_processing" type="pcl_transform" output="screen">
2323
<rosparam param="output_frame"> "zed_pointcloud" </rosparam>
2424

2525
<remap from="/input_pointcloud" to="/zed/camera/point_cloud/uncorrected_cloud_do_not_use"/>

src/sb_gazebo/launch/jfrost_control.launch

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</include>
2020

2121
<!-- This is for jfrost's depthcamera/kinect/zed plugin -->
22-
<node name="zed_transform" pkg="sb_gazebo" type="zed_transform" output="screen">
22+
<node name="zed_transform" pkg="sb_pointcloud_processing" type="pcl_transform" output="screen">
2323
<rosparam param="output_frame"> "zed_pointcloud" </rosparam>
2424

2525
<remap from="/input_pointcloud" to="/zed/camera/point_cloud/uncorrected_cloud_do_not_use"/>

src/sb_pointcloud_processing/CMakeLists.txt

+41-28
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ find_package(catkin REQUIRED COMPONENTS
2929
pcl_msgs
3030
sensor_msgs
3131
mapping_igvc
32+
geometry_msgs
33+
tf2
34+
tf2_ros
35+
tf2_msgs
36+
tf2_sensor_msgs
3237
)
3338
find_package(PCL 1.3 REQUIRED COMPONENTS
3439
common
@@ -58,14 +63,24 @@ include_directories(
5863
## With catkin_make all packages are built within a single CMake context
5964
## The recommended prefix ensures that target names across packages don't collide
6065
add_executable(line_extractor_node
61-
include/LineExtractorNode.h
62-
include/DBSCAN.h
63-
include/Regression.h
64-
src/line_extractor_node.cpp
65-
src/LineExtractorNode.cpp
66-
src/DBSCAN.cpp
67-
src/Regression.cpp
68-
include/Regression.h
66+
include/LineExtractorNode.h
67+
include/DBSCAN.h
68+
include/Regression.h
69+
src/line_extractor_node.cpp
70+
src/LineExtractorNode.cpp
71+
src/DBSCAN.cpp
72+
src/Regression.cpp
73+
include/Regression.h
74+
)
75+
76+
target_link_libraries(line_extractor_node
77+
${catkin_LIBRARIES}
78+
${PCL_COMMON_LIBRARIES}
79+
${PCL_IO_LIBRARIES}
80+
)
81+
82+
add_dependencies(line_extractor_node
83+
${mapping_igvc_EXPORTED_TARGETS}
6984
)
7085

7186
add_library(sb_pointcloud_processing
@@ -81,35 +96,33 @@ target_link_libraries(sb_pointcloud_processing
8196
${PCL_LIBRARIES}
8297
)
8398

84-
add_executable(test_pcl_generator_node
85-
src/test_pcl_generator_node.cpp
86-
test/TestUtils.h
87-
)
88-
89-
## Specify libraries to link a library or executable target against
90-
target_link_libraries(line_extractor_node
91-
${catkin_LIBRARIES}
92-
${PCL_COMMON_LIBRARIES}
93-
${PCL_IO_LIBRARIES}
94-
)
95-
96-
add_dependencies(line_extractor_node
97-
${mapping_igvc_EXPORTED_TARGETS}
98-
)
9999

100100
install(
101101
TARGETS
102-
sb_pointcloud_processing
102+
sb_pointcloud_processing
103103
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
104104
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
105105
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
106106
)
107107

108+
add_executable(test_pcl_generator_node
109+
src/test_pcl_generator_node.cpp
110+
test/TestUtils.h
111+
)
112+
108113
target_link_libraries(test_pcl_generator_node
109-
${catkin_LIBRARIES}
110-
${PCL_COMMON_LIBRARIES}
111-
${PCL_IO_LIBRARIES}
112-
)
114+
${catkin_LIBRARIES}
115+
${PCL_COMMON_LIBRARIES}
116+
${PCL_IO_LIBRARIES}
117+
)
118+
119+
120+
add_executable(pcl_transform src/pcl_transform.cpp)
121+
122+
target_link_libraries(pcl_transform
123+
${catkin_LIBRARIES}
124+
${sb_utils_LIBRARIES}
125+
)
113126

114127
#############
115128
## Testing ##

src/sb_gazebo/src/zed_transform.cpp src/sb_pointcloud_processing/src/pcl_transform.cpp

+33-12
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,59 @@
1414
#include <sb_utils.h>
1515

1616
ros::Publisher pub;
17-
std::string output_frame;
1817
tf2_ros::Buffer tf_buffer;
1918

19+
std::string output_frame;
20+
ros::Time last_exception_time;
21+
22+
// The amount of time(s) for a new pointcloud transform to be published.
23+
double transform_period;
24+
2025
void pointCloudCallback(const sensor_msgs::PointCloud2::ConstPtr& msg) {
2126
try {
2227
// Create an empty pointcloud
2328
sensor_msgs::PointCloud2 output;
2429
// Transform the pointcloud to the requested frame
2530
geometry_msgs::TransformStamped tf_stamped = tf_buffer.lookupTransform(
26-
msg->header.frame_id, output_frame, ros::Time(0), ros::Duration(1.0));
31+
msg->header.frame_id, output_frame, ros::Time(0), ros::Duration(0.1));
32+
2733
tf2::doTransform(*msg, output, tf_stamped);
2834

35+
output.header.frame_id = output_frame;
36+
2937
// Publish the transformed pointcloud
3038
pub.publish(output);
31-
} catch (tf2::TransformException ex){
32-
ROS_WARN("%s", ex.what());
33-
ros::Duration(1.0).sleep();
39+
40+
ros::Duration(transform_period).sleep();
41+
} catch (tf2::TransformException ex) {
42+
if (ros::Time::now().toSec() - last_exception_time.toSec() > 1.0)
43+
ROS_WARN("%s", ex.what());
44+
45+
last_exception_time = ros::Time::now();
3446
}
3547
}
3648

37-
int main(int argc, char** argv){
49+
int main(int argc, char** argv) {
3850
ros::init(argc, argv, "pointcloud_transformer");
3951
ros::NodeHandle private_nh("~");
40-
if (!SB_getParam(private_nh, "output_frame", output_frame)){
52+
if (!SB_getParam(private_nh, "output_frame", output_frame)) {
4153
// Error and exit if we didn't get a frame to transform to.
42-
// We need this to transform anything, and there is no reasonable default
43-
ROS_ERROR("Param 'output_frame' not provided. " \
44-
"Can't transform anything without a frame to transform it to");
54+
// We need this to transform anything, and there is no reasonable
55+
// default
56+
ROS_ERROR(
57+
"Param 'output_frame' not provided. "
58+
"Can't transform anything without a frame to transform it to");
4559
return 1;
4660
}
47-
ros::Subscriber sub = private_nh.subscribe("/input_pointcloud", 1, pointCloudCallback);
48-
pub = private_nh.advertise<sensor_msgs::PointCloud2>("/output_pointcloud", 1);
61+
62+
double default_transform_period = 0;
63+
SB_getParam(
64+
private_nh, "transform_period", transform_period, default_transform_period);
65+
66+
ros::Subscriber sub =
67+
private_nh.subscribe("/input_pointcloud", 1, pointCloudCallback);
68+
pub =
69+
private_nh.advertise<sensor_msgs::PointCloud2>("/output_pointcloud", 1);
4970
tf2_ros::TransformListener tfListener(tf_buffer);
5071
ros::spin();
5172
return 0;

0 commit comments

Comments
 (0)