Skip to content

Commit 4ea1187

Browse files
committed
WIP Improve: ros2-ified perception tutorial .cpp files.
1 parent 7d0def4 commit 4ea1187

File tree

10 files changed

+90
-117
lines changed

10 files changed

+90
-117
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ add_subdirectory(doc/examples/motion_planning_pipeline)
5959
add_subdirectory(doc/examples/motion_planning_python_api)
6060
add_subdirectory(doc/examples/move_group_interface)
6161
add_subdirectory(doc/examples/moveit_cpp)
62+
add_subdirectory(doc/examples/perception_pipeline)
6263
add_subdirectory(doc/examples/planning_scene)
6364
add_subdirectory(doc/examples/planning_scene_ros_api)
6465
add_subdirectory(doc/examples/realtime_servo)
Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
add_executable(cylinder_segment src/cylinder_segment.cpp)
2-
target_link_libraries(cylinder_segment ${catkin_LIBRARIES})
1+
find_package(PCL REQUIRED)
2+
set(SUBTUTORIAL_DEPENDS
3+
geometry_msgs
4+
pcl_conversions
5+
sensor_msgs
6+
)
7+
foreach(dep IN ITEMS ${SUBTUTORIAL_DEPENDS})
8+
find_package(${dep} REQUIRED)
9+
endforeach()
310

4-
add_executable(bag_publisher_maintain_time src/bag_publisher_maintain_time.cpp)
5-
target_link_libraries(bag_publisher_maintain_time ${catkin_LIBRARIES} ${Boost_LIBRARIES})
11+
include_directories(include ${PCL_INCLUDE_DIRS})
612

7-
install(
8-
TARGETS
9-
bag_publisher_maintain_time
10-
cylinder_segment
11-
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})
13+
add_executable(cylinder_segment src/cylinder_segment.cpp)
14+
ament_target_dependencies(cylinder_segment
15+
${SUBTUTORIAL_DEPENDS}
16+
${THIS_PACKAGE_INCLUDE_DEPENDS})
1217

13-
install(DIRECTORY launch DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})
18+
install(DIRECTORY bags launch
19+
DESTINATION share/${PROJECT_NAME}
20+
)
-1.56 MB
Binary file not shown.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
rosbag2_bagfile_information:
2+
compression_format: ''
3+
compression_mode: ''
4+
custom_data: {}
5+
duration:
6+
nanoseconds: 0
7+
files:
8+
- duration:
9+
nanoseconds: 0
10+
message_count: 1
11+
path: perception_tutorial.db3
12+
starting_time:
13+
nanoseconds_since_epoch: 1530016169214859695
14+
message_count: 1
15+
relative_file_paths:
16+
- perception_tutorial.db3
17+
starting_time:
18+
nanoseconds_since_epoch: 1530016169214859695
19+
storage_identifier: sqlite3
20+
topics_with_message_count:
21+
- message_count: 1
22+
topic_metadata:
23+
name: /camera/depth_registered/points
24+
offered_qos_profiles: ''
25+
serialization_format: cdr
26+
type: sensor_msgs/msg/PointCloud2
27+
version: 6
Binary file not shown.

doc/examples/perception_pipeline/launch/obstacle_avoidance_demo.launch

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<include file="$(find panda_moveit_config)/launch/demo.launch" />
33

44
<!-- Play the rosbag that contains the pointcloud data -->
5-
<node pkg="moveit_tutorials" type="bag_publisher_maintain_time" name="point_clouds" />
5+
<arg namve="bagfile" value="$(find moveit2_tutorials)/share/moveit2_tutorials/bags/perception_tutorial.bag" />
6+
<executable cmd="ros2 bag play -l ${arg bagfile)" output="screen" />
67

78
<!-- If needed, broadcast static tf for robot root -->
89
<node pkg="tf2_ros" type="static_transform_publisher" name="to_panda" args="0 0 0 0 0 0 world panda_link0" />

doc/examples/perception_pipeline/perception_pipeline_tutorial.rst

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Getting Started
1111
---------------
1212
If you haven't already done so, make sure you've completed the steps in :doc:`Getting Started </doc/tutorials/getting_started/getting_started>`.
1313

14+
Particularly, use ``rolling`` for this tutorial as some dependencies may not be available in ``humble`` or earlier (explained in `moveit2_tutorials!700 <https://github.com/ros-planning/moveit2_tutorials/pull/700#issuecomment-1581411304>`_).
15+
1416
Configuration
1517
-------------
1618

@@ -134,6 +136,16 @@ If you set the initial and the final location of the robot in a way that there i
134136
.. image:: obstacle_avoidance.gif
135137
:width: 700px
136138

139+
Before running the software
140+
+++++++++++++++++++++++++++
141+
This tutorial uses `moveit2_tutorials` that depends on `moveit_task_constructor`, whose installer has not yet been available in ros2 yet (progress tracked in `moveit_task_constructor#400 <https://github.com/ros-planning/moveit_task_constructor/issues/400>`_) so you need to get it via source code. Move into your colcon workspace and pull the MoveIt Task Constructor source: ::
142+
143+
cd ~/ws_moveit/src
144+
git clone git@github.com:ros-planning/moveit_task_constructor.git -b ros2
145+
cd ~/ws_moveit
146+
colcon build --mixin release
147+
source ~/ws_moveit/install/setup.bash
148+
137149
Running the Interface
138150
+++++++++++++++++++++
139151
Roslaunch the launch file to run the code directly from moveit_tutorials: ::
@@ -174,9 +186,9 @@ You can follow its status in the `issue tracker <https://github.com/ros-planning
174186

175187
Relevant Code
176188
+++++++++++++
177-
The entire code can be seen :codedir:`here<examples/perception_pipeline>` in the moveit_tutorials GitHub project.
189+
The entire code can be seen :codedir:`here <examples/perception_pipeline>` in the moveit_tutorials GitHub project.
178190

179-
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>`_.
191+
The details regarding the implementation of each of the perception pipeline function have been omitted in this tutorial as they are well documented on `ros1 wiki <http://wiki.ros.org/pcl/Tutorials>`_.
180192

181193
.. |br| raw:: html
182194

doc/examples/perception_pipeline/src/bag_publisher_maintain_time.cpp

Lines changed: 0 additions & 82 deletions
This file was deleted.

doc/examples/perception_pipeline/src/cylinder_segment.cpp

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,27 @@
3434

3535
/* Author: Ridhwan Luthra */
3636

37-
#include <ros/ros.h>
38-
#include <sensor_msgs/PointCloud2.h>
37+
#include <geometry_msgs/msg/pose.hpp>
38+
#include <moveit/planning_scene_interface/planning_scene_interface.h>
39+
#include <moveit_msgs/msg/collision_object.hpp>
40+
#include <rclcpp/rclcpp.hpp>
3941
#include <pcl_conversions/pcl_conversions.h>
4042
#include <pcl/filters/passthrough.h>
4143
#include <pcl/filters/extract_indices.h>
4244
#include <pcl/features/normal_3d.h>
4345
#include <pcl/segmentation/sac_segmentation.h>
46+
#include <sensor_msgs/msg/point_cloud2.hpp>
47+
#include "std_msgs/msg/string.hpp"
4448

45-
#include <moveit/planning_scene_interface/planning_scene_interface.h>
46-
#include <moveit_msgs/CollisionObject.h>
47-
48-
class CylinderSegment
49+
class CylinderSegment : public rclcpp::Node
4950
{
5051
public:
51-
CylinderSegment()
52+
explicit CylinderSegment(const rclcpp::NodeOptions& options)
53+
: rclcpp::Node("cylinder_segment")
5254
{
53-
ros::NodeHandle nh;
5455
// Initialize subscriber to the raw point cloud
55-
ros::Subscriber sub = nh.subscribe("/camera/depth_registered/points", 1, &CylinderSegment::cloudCB, this);
56-
// Spin
57-
ros::spin();
56+
subscription_ = this->create_subscription<std_msgs::msg::String>(
57+
"/camera/depth_registered/points", 10, std::bind(&CylinderSegment::cloudCB, this, std::placeholders::_1));
5858
}
5959

6060
/** \brief Given the parameters of the cylinder add the cylinder to the planning scene.
@@ -67,12 +67,12 @@ class CylinderSegment
6767
// Adding Cylinder to Planning Scene
6868
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6969
// Define a collision object ROS message.
70-
moveit_msgs::CollisionObject collision_object;
70+
moveit_msgs::msg::CollisionObject collision_object;
7171
collision_object.header.frame_id = "camera_rgb_optical_frame";
7272
collision_object.id = "cylinder";
7373

7474
// Define a cylinder which will be added to the world.
75-
shape_msgs::SolidPrimitive primitive;
75+
shape_msgs::msg::SolidPrimitive primitive;
7676
primitive.type = primitive.CYLINDER;
7777
primitive.dimensions.resize(2);
7878
/* Setting height of cylinder. */
@@ -81,7 +81,7 @@ class CylinderSegment
8181
primitive.dimensions[1] = cylinder_params->radius;
8282

8383
// Define a pose for the cylinder (specified relative to frame_id).
84-
geometry_msgs::Pose cylinder_pose;
84+
geometry_msgs::msg::Pose cylinder_pose;
8585
/* Computing and setting quaternion from axis angle representation. */
8686
Eigen::Vector3d cylinder_z_direction(cylinder_params->direction_vec[0], cylinder_params->direction_vec[1],
8787
cylinder_params->direction_vec[2]);
@@ -165,7 +165,10 @@ class CylinderSegment
165165
}
166166

167167
/** \brief Given a pointcloud extract the ROI defined by the user.
168-
@param cloud - Pointcloud whose ROI needs to be extracted. */
168+
* <- @TODO 20230607 @130s doesn't see user input anywhere in this .cpp file?
169+
*
170+
* @param cloud - Pointcloud whose ROI needs to be extracted.
171+
**/
169172
void passThroughFilter(const pcl::PointCloud<pcl::PointXYZRGB>::Ptr& cloud)
170173
{
171174
pcl::PassThrough<pcl::PointXYZRGB> pass;
@@ -269,7 +272,7 @@ class CylinderSegment
269272
extract.filter(*cloud);
270273
}
271274

272-
void cloudCB(const sensor_msgs::PointCloud2ConstPtr& input)
275+
void cloudCB(const sensor_msgs::msg::PointCloud2::SharedPtr input)
273276
{
274277
// BEGIN_SUB_TUTORIAL callback
275278
//
@@ -304,7 +307,7 @@ class CylinderSegment
304307
// END_SUB_TUTORIAL
305308
if (cloud->points.empty())
306309
{
307-
ROS_ERROR_STREAM_NAMED("cylinder_segment", "Can't find the cylindrical component.");
310+
RCLCPP_ERROR(this->get_logger(), "cylinder_segment, can't find the cylindrical component.");
308311
return;
309312
}
310313
if (points_not_found)
@@ -341,6 +344,8 @@ class CylinderSegment
341344
}
342345

343346
private:
347+
rclcpp::Subscription<std_msgs::msg::String>::SharedPtr subscription_;
348+
344349
// BEGIN_SUB_TUTORIAL param_struct
345350
// There are 4 fields and a total of 7 parameters used to define this.
346351
struct AddCylinderParams
@@ -364,7 +369,6 @@ class CylinderSegment
364369
int main(int argc, char** argv)
365370
{
366371
// Initialize ROS
367-
ros::init(argc, argv, "cylinder_segment");
368-
// Start the segmentor
369-
CylinderSegment();
372+
rclcpp::init(argc, argv);
373+
rclcpp::spin(std::make_shared<CylinderSegment>());
370374
}

package.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<buildtool_depend>ament_cmake</buildtool_depend>
2020

2121
<depend>control_msgs</depend>
22+
<depend>geometry_msgs</depend>
2223
<depend>interactive_markers</depend>
2324
<depend>moveit_core</depend>
2425
<depend>moveit_ros_perception</depend>
@@ -27,11 +28,12 @@
2728
<depend>moveit_hybrid_planning</depend>
2829
<depend>moveit_visual_tools</depend>
2930
<depend>moveit_msgs</depend>
30-
<!-- <depend>pcl_conversions</depend> -->
31-
<!-- <depend>pcl_ros</depend> -->
31+
<depend>pcl_conversions</depend>
32+
<depend>pcl_ros</depend>
3233
<depend>pluginlib</depend>
3334
<!-- <depend>rosbag</depend> -->
3435
<depend>rviz_visual_tools</depend>
36+
<depend>sensor_msgs</depend>
3537
<depend>tf2_eigen</depend>
3638
<depend>tf2_geometry_msgs</depend>
3739
<depend>tf2_ros</depend>
@@ -55,6 +57,7 @@
5557
<exec_depend>moveit_resources_panda_moveit_config</exec_depend>
5658
<exec_depend>moveit_configs_utils</exec_depend>
5759
<exec_depend>moveit_py</exec_depend>
60+
<exec_depend>panda_moveit_config</exec_depend>
5861
<exec_depend>robot_state_publisher</exec_depend>
5962
<exec_depend>ros2_control</exec_depend>
6063
<exec_depend>rviz2</exec_depend>

0 commit comments

Comments
 (0)