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/version.h>
46 #if RCLCPP_VERSION_GTE(20, 0, 0)
47 #include <rclcpp/event_handler.hpp>
48 #else
49 #include <rclcpp/qos_event.hpp>
50 #endif
51 #include <rclcpp/time.hpp>
52 #include <rclcpp/utilities.hpp>
53 
54 static const std::string ROBOT_DESCRIPTION = "robot_description";
55 
56 void sendKnife(const rclcpp::Node::SharedPtr& node)
57 {
58  auto pub_aco = node->create_publisher<moveit_msgs::msg::AttachedCollisionObject>("attached_collision_object", 10);
59  moveit_msgs::msg::AttachedCollisionObject aco;
60  aco.link_name = "r_wrist_roll_link";
61  aco.touch_links.push_back("r_wrist_roll_link");
62  aco.touch_links.push_back("r_gripper_palm_link");
63  aco.touch_links.push_back("r_gripper_led_frame");
64  aco.touch_links.push_back("r_gripper_motor_accelerometer_link");
65  aco.touch_links.push_back("r_gripper_tool_frame");
66  aco.touch_links.push_back("r_gripper_motor_slider_link");
67  aco.touch_links.push_back("r_gripper_motor_screw_link");
68  aco.touch_links.push_back("r_gripper_l_finger_link");
69  aco.touch_links.push_back("r_gripper_l_finger_tip_link");
70  aco.touch_links.push_back("r_gripper_r_finger_link");
71  aco.touch_links.push_back("r_gripper_r_finger_tip_link");
72  aco.touch_links.push_back("r_gripper_l_finger_tip_frame");
73 
74  moveit_msgs::msg::CollisionObject& co = aco.object;
75  co.id = "knife";
76  co.header.stamp = rclcpp::Clock().now();
77  co.header.frame_id = aco.link_name;
78  co.pose.orientation.w = 1.0;
79  co.operation = moveit_msgs::msg::CollisionObject::ADD;
80  co.primitives.resize(1);
81  co.primitives[0].type = shape_msgs::msg::SolidPrimitive::BOX;
82  co.primitives[0].dimensions.push_back(0.1);
83  co.primitives[0].dimensions.push_back(0.1);
84  co.primitives[0].dimensions.push_back(0.4);
85  co.primitive_poses.resize(1);
86  co.primitive_poses[0].position.x = 0.1;
87  co.primitive_poses[0].position.y = 0;
88  co.primitive_poses[0].position.z = -0.2;
89 
90  using namespace std::chrono_literals;
91  pub_aco->publish(aco);
92  rclcpp::sleep_for(1s);
93  pub_aco->publish(aco);
94  RCLCPP_INFO(node->get_logger(), "Object published.");
95  rclcpp::sleep_for(1500ms);
96 }
97 
98 int main(int argc, char** argv)
99 {
100  rclcpp::init(argc, argv);
101 
102  auto node = rclcpp::Node::make_shared("demo_scene");
103 
104  sendKnife(node);
105 
106  rclcpp::spin(node);
107 
108  return 0;
109 }
void sendKnife(const rclcpp::Node::SharedPtr &node)
Definition: demo_scene.cpp:56
int main(int argc, char **argv)
Definition: demo_scene.cpp:98