moveit2
The MoveIt Motion Planning Framework for ROS 2.
demo_scene.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 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 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 /* Author: Ioan Sucan */
36 
38 #include <geometric_shapes/solid_primitive_dims.h>
39 #include <rclcpp/clock.hpp>
40 #include <rclcpp/executors.hpp>
41 #include <rclcpp/logger.hpp>
42 #include <rclcpp/logging.hpp>
43 #include <rclcpp/node.hpp>
44 #include <rclcpp/publisher.hpp>
45 #include <rclcpp/qos_event.hpp>
46 #include <rclcpp/time.hpp>
47 #include <rclcpp/utilities.hpp>
48 
49 static const rclcpp::Logger LOGGER = rclcpp::get_logger("moveit_ros.planning_scene_monitor.demo_scene");
50 
51 static const std::string ROBOT_DESCRIPTION = "robot_description";
52 
53 void sendKnife(const rclcpp::Node::SharedPtr& node)
54 {
55  auto pub_aco = node->create_publisher<moveit_msgs::msg::AttachedCollisionObject>("attached_collision_object", 10);
56  moveit_msgs::msg::AttachedCollisionObject aco;
57  aco.link_name = "r_wrist_roll_link";
58  aco.touch_links.push_back("r_wrist_roll_link");
59  aco.touch_links.push_back("r_gripper_palm_link");
60  aco.touch_links.push_back("r_gripper_led_frame");
61  aco.touch_links.push_back("r_gripper_motor_accelerometer_link");
62  aco.touch_links.push_back("r_gripper_tool_frame");
63  aco.touch_links.push_back("r_gripper_motor_slider_link");
64  aco.touch_links.push_back("r_gripper_motor_screw_link");
65  aco.touch_links.push_back("r_gripper_l_finger_link");
66  aco.touch_links.push_back("r_gripper_l_finger_tip_link");
67  aco.touch_links.push_back("r_gripper_r_finger_link");
68  aco.touch_links.push_back("r_gripper_r_finger_tip_link");
69  aco.touch_links.push_back("r_gripper_l_finger_tip_frame");
70 
71  moveit_msgs::msg::CollisionObject& co = aco.object;
72  co.id = "knife";
73  co.header.stamp = rclcpp::Clock().now();
74  co.header.frame_id = aco.link_name;
75  co.pose.orientation.w = 1.0;
76  co.operation = moveit_msgs::msg::CollisionObject::ADD;
77  co.primitives.resize(1);
78  co.primitives[0].type = shape_msgs::msg::SolidPrimitive::BOX;
79  co.primitives[0].dimensions.push_back(0.1);
80  co.primitives[0].dimensions.push_back(0.1);
81  co.primitives[0].dimensions.push_back(0.4);
82  co.primitive_poses.resize(1);
83  co.primitive_poses[0].position.x = 0.1;
84  co.primitive_poses[0].position.y = 0;
85  co.primitive_poses[0].position.z = -0.2;
86 
87  using namespace std::chrono_literals;
88  pub_aco->publish(aco);
89  rclcpp::sleep_for(1s);
90  pub_aco->publish(aco);
91  RCLCPP_INFO(LOGGER, "Object published.");
92  rclcpp::sleep_for(1500ms);
93 }
94 
95 int main(int argc, char** argv)
96 {
97  rclcpp::init(argc, argv);
98 
99  auto node = rclcpp::Node::make_shared("demo_scene");
100 
101  sendKnife(node);
102 
103  rclcpp::spin(node);
104 
105  return 0;
106 }
void sendKnife(const rclcpp::Node::SharedPtr &node)
Definition: demo_scene.cpp:53
int main(int argc, char **argv)
Definition: demo_scene.cpp:95
const rclcpp::Logger LOGGER
Definition: async_test.h:31