Skip to content

Commit 7e88e34

Browse files
authored
Improve perception tutorial (#633)
1 parent 37c0701 commit 7e88e34

File tree

6 files changed

+128
-130
lines changed

6 files changed

+128
-130
lines changed
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
add_executable(cylinder_segment src/cylinder_segment.cpp)
2-
target_link_libraries(cylinder_segment ${catkin_LIBRARIES})
1+
add_executable(detect_and_add_cylinder_collision_object_demo src/detect_and_add_cylinder_collision_object_demo.cpp)
2+
target_link_libraries(detect_and_add_cylinder_collision_object_demo ${catkin_LIBRARIES})
33

44
add_executable(bag_publisher_maintain_time src/bag_publisher_maintain_time.cpp)
55
target_link_libraries(bag_publisher_maintain_time ${catkin_LIBRARIES} ${Boost_LIBRARIES})
66

77
install(
88
TARGETS
99
bag_publisher_maintain_time
10-
cylinder_segment
10+
detect_and_add_cylinder_collision_object_demo
1111
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})
1212

1313
install(DIRECTORY launch DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})
14+
install(DIRECTORY bags DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/doc/perception_pipeline/)

doc/perception_pipeline/launch/detect_and_add_cylinder_collision_object_demo.launch

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
<launch>
22
<include file="$(find panda_moveit_config)/launch/demo.launch" />
3+
<!--
4+
In this tutorial we wait much longer for the robot transforms than we usually would,
5+
because the user's machine might be quite slow.
6+
-->
7+
<param name="robot_description_planning/shape_transform_cache_lookup_wait_time" value="0.5" />
38

49
<!-- Play the rosbag that contains the pointcloud data -->
510
<node pkg="moveit_tutorials" type="bag_publisher_maintain_time" name="point_clouds" />
611

712
<!-- If needed, broadcast static tf for robot root -->
813
<node pkg="tf2_ros" type="static_transform_publisher" name="to_panda" args="0 0 0 0 0 0 world panda_link0" />
9-
<node pkg="tf2_ros" type="static_transform_publisher" name="to_camera" args="0.115 0.427 0.570 0 0.2 1.92 camera_rgb_optical_frame world" />
14+
<node pkg="tf2_ros" type="static_transform_publisher" name="to_camera" args="0.00 -.40 0.60 0.19 0.07 -1.91 world camera_rgb_optical_frame" />
1015

1116
</launch>

doc/perception_pipeline/perception_pipeline_tutorial.rst

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Once properly configured, you should see something like this in RViz:
99

1010
Getting Started
1111
---------------
12+
1213
If you haven't already done so, make sure you've completed the steps in `Getting Started <../getting_started/getting_started.html>`_.
1314

1415
Configuration
@@ -106,6 +107,7 @@ Update the launch file
106107

107108
Add the YAML file to the launch script
108109
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
110+
109111
You will now need to update the *sensor_manager.launch* file in the "launch" directory of your panda_moveit_config directory with this sensor information (this file is auto-generated by the Setup Assistant but is empty). You will need to add the following line into that file to configure the set of sensor sources for MoveIt to use: ::
110112

111113
<rosparam command="load" file="$(find panda_moveit_config)/config/sensors_kinect_pointcloud.yaml" />
@@ -115,6 +117,7 @@ Note that you will need to input the path to the right file you have created abo
115117

116118
Octomap Configuration
117119
^^^^^^^^^^^^^^^^^^^^^
120+
118121
You will also need to configure the `Octomap <http://octomap.github.io/>`_ by adding the following lines into the *sensor_manager.launch*: ::
119122

120123
<param name="octomap_frame" type="string" value="odom_combined" />
@@ -136,7 +139,8 @@ If you set the initial and the final location of the robot in a way that there i
136139

137140
Running the Interface
138141
+++++++++++++++++++++
139-
Roslaunch the launch file to run the code directly from moveit_tutorials: ::
142+
143+
Launch the prepared launch file in moveit_tutorials to see the planning scene integrating sample point cloud data into an octomap: ::
140144

141145
roslaunch moveit_tutorials obstacle_avoidance_demo.launch
142146

@@ -145,7 +149,7 @@ If not, you may have run into a `known OpenGL rendering issue <http://wiki.ros.o
145149

146150
export LIBGL_ALWAYS_SOFTWARE=1
147151

148-
You can test obstacle avoidance for yourself by setting the goal state manually and then planning and executing. To learn how to do that look at `MoveIt Quickstart in RViz <../quickstart_in_rviz/quickstart_in_rviz_tutorial.html>`_
152+
You can test obstacle avoidance with the generated octomap for yourself by setting the goal state manually and then planning and executing. To learn how to do that look at `MoveIt Quickstart in RViz <../quickstart_in_rviz/quickstart_in_rviz_tutorial.html>`_
149153

150154
Detecting and Adding Object as Collision Object
151155
-----------------------------------------------
@@ -160,20 +164,14 @@ After running the code, you should be able to see something like this in RViz:
160164

161165
Running the Code
162166
++++++++++++++++
163-
Roslaunch the launch file to run the code directly from moveit_tutorials: ::
164167

165-
roslaunch moveit_tutorials detect_and_add_cylinder_collision_object_demo.launch
168+
Keep the launch file from above running and run the code directly from moveit_tutorials: ::
166169

167-
KNOWN ISSUE - You may see the following error when running the demo ::
168-
169-
ros.moveit_ros_planning.planning_scene_monitor: Transform error: Lookup would require extrapolation into the future. Requested time 1527473962.793050157 but the latest data is at time 1527473962.776993978, when looking up transform from frame [panda_link2] to frame [camera_rgb_optical_frame]
170-
ros.moveit_ros_perception: Transform cache was not updated. Self-filtering may fail.
171-
172-
We are working on fixing it, it should not break the working of the demo.
173-
You can follow its status in the `issue tracker <https://github.com/ros-planning/moveit_tutorials/issues/192>`_
170+
rosrun moveit_tutorials detect_and_add_cylinder_collision_object_demo
174171

175172
Relevant Code
176173
+++++++++++++
174+
177175
The entire code can be seen :codedir:`here<perception_pipeline>` in the moveit_tutorials GitHub project.
178176

179177
The details regarding the implementation of each of the perception pipeline function have been omitted in this tutorial as they are well documented `here <http://wiki.ros.org/pcl/Tutorials>`_.
@@ -190,4 +188,4 @@ The details regarding the implementation of each of the perception pipeline func
190188

191189
</code>
192190

193-
.. tutorial-formatter:: ./src/cylinder_segment.cpp
191+
.. tutorial-formatter:: ./src/detect_and_add_cylinder_collision_object_demo.cpp

doc/perception_pipeline/src/bag_publisher_maintain_time.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ int main(int argc, char** argv)
4444
{
4545
ros::init(argc, argv, "bag_publisher_maintain_time");
4646
ros::NodeHandle nh;
47+
ros::AsyncSpinner spinner(1);
48+
spinner.start();
4749

48-
ros::Publisher point_cloud_publisher = nh.advertise<sensor_msgs::PointCloud2>("/camera/depth_registered/points", 1);
49-
ros::Rate loop_rate(0.1);
50+
ros::Publisher point_cloud_publisher =
51+
nh.advertise<sensor_msgs::PointCloud2>("/camera/depth_registered/points", 2, true);
5052

5153
// Variable holding the rosbag containing point cloud data.
5254
rosbag::Bag bagfile;
@@ -58,25 +60,27 @@ int main(int argc, char** argv)
5860
topics.push_back("/camera/depth_registered/points");
5961

6062
// Iterator for topics in bag.
61-
rosbag::View bagtopics_iter(bagfile, rosbag::TopicQuery(topics));
63+
rosbag::View bag(bagfile, rosbag::TopicQuery(topics));
6264

63-
for (auto const msg : bagtopics_iter)
65+
sensor_msgs::PointCloud2::Ptr point_cloud_ptr = bag.begin()->instantiate<sensor_msgs::PointCloud2>();
66+
if (!point_cloud_ptr)
6467
{
65-
sensor_msgs::PointCloud2::Ptr point_cloud_ptr = msg.instantiate<sensor_msgs::PointCloud2>();
66-
if (point_cloud_ptr == nullptr)
67-
{
68-
std::cout << "error" << std::endl;
69-
break;
70-
}
68+
ROS_FATAL("invalid message in rosbag");
69+
return 1;
70+
}
71+
72+
// Give a bit of time to move_group to connect & cache transforms
73+
// works around sporadic tf extrapolation errors
74+
ros::Duration(1.0).sleep();
7175

72-
while (ros::ok())
73-
{
74-
point_cloud_ptr->header.stamp = ros::Time::now();
75-
point_cloud_publisher.publish(*point_cloud_ptr);
76-
ros::spinOnce();
77-
loop_rate.sleep();
78-
}
76+
ros::Rate loop_rate(0.2);
77+
while (ros::ok())
78+
{
79+
point_cloud_ptr->header.stamp = ros::Time::now();
80+
point_cloud_publisher.publish(*point_cloud_ptr);
81+
loop_rate.sleep();
7982
}
83+
8084
bagfile.close();
8185
return 0;
8286
}

0 commit comments

Comments
 (0)