test_obstacle_publisher_node.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #include <ros/ros.h>
19 #include <geometry_msgs/Pose.h>
20 #include <moveit_msgs/CollisionObject.h>
21 #include <shape_msgs/SolidPrimitive.h>
24 
25 #include <boost/variant.hpp>
26 #include <boost/shared_ptr.hpp>
27 
28 
29 int main(int argc, char** argv)
30 {
31  ros::init(argc, argv, "test_obstacle_publisher_node");
33  ros::Publisher pub = n.advertise<moveit_msgs::CollisionObject>("/collision_object", 1);
34  ros::Duration(1.0).sleep();
35 
36  // primitive sphere
37  moveit_msgs::CollisionObject col_sphere_msg;
38  col_sphere_msg.id = "sphere_primitive";
39  col_sphere_msg.header.frame_id = "odom_combined";
40  col_sphere_msg.operation = moveit_msgs::CollisionObject::ADD;
41 
42  shape_msgs::SolidPrimitive sphere;
43  sphere.type = shape_msgs::SolidPrimitive::SPHERE;
44  sphere.dimensions.push_back(0.1);
45 
46  geometry_msgs::Pose pose;
47  pose.position.x = 1.0;
48  pose.position.y = 0.0;
49  pose.position.z = 0.0;
50  pose.orientation.w = 1.0;
51 
52  col_sphere_msg.primitives.push_back(sphere);
53  col_sphere_msg.primitive_poses.push_back(pose);
54 
55  pub.publish(col_sphere_msg);
56  ros::Duration(0.1).sleep();
57 
58  // mesh sphere
59  moveit_msgs::CollisionObject col_sphere_mesh_msg;
60  col_sphere_mesh_msg.id = "sphere_mesh";
61  col_sphere_mesh_msg.header.frame_id = "odom_combined";
62  col_sphere_mesh_msg.operation = moveit_msgs::CollisionObject::ADD;
63 
64  shapes::Mesh* sphere_shape = shapes::createMeshFromResource("package://cob_obstacle_distance_moveit/files/sphere.stl");
65  shapes::ShapeMsg sphere_mesh_msg;
66  shapes::constructMsgFromShape(sphere_shape, sphere_mesh_msg);
67  shape_msgs::Mesh sphere_mesh = boost::get<shape_msgs::Mesh>(sphere_mesh_msg);
68 
69  pose.position.x = 1.0;
70  // pose.position.y = 1.0;
71  pose.position.z = 0.0;
72  pose.orientation.w = 1.0;
73 
74  col_sphere_mesh_msg.meshes.push_back(sphere_mesh);
75  col_sphere_mesh_msg.mesh_poses.push_back(pose);
76 
77  pub.publish(col_sphere_mesh_msg);
78  ros::Duration(0.1).sleep();
79 
80  // primitive box
81  moveit_msgs::CollisionObject col_box_msg;
82  col_box_msg.id = "box_primitive";
83  col_box_msg.header.frame_id = "odom_combined";
84  col_box_msg.operation = moveit_msgs::CollisionObject::ADD;
85 
86  shape_msgs::SolidPrimitive box;
87  box.type = shape_msgs::SolidPrimitive::BOX;
88  box.dimensions.push_back(0.1);
89  box.dimensions.push_back(0.1);
90  box.dimensions.push_back(0.1);
91 
92  pose.position.x = 1.0;
93  pose.position.y = 0.0;
94  pose.position.z = 1.0;
95  pose.orientation.w = 1.0;
96 
97  col_box_msg.primitives.push_back(box);
98  col_box_msg.primitive_poses.push_back(pose);
99 
100  pub.publish(col_box_msg);
101  ros::Duration(0.1).sleep();
102 
103  // mesh box
104  moveit_msgs::CollisionObject col_box_mesh_msg;
105  col_box_mesh_msg.id = "box_mesh";
106  col_box_mesh_msg.header.frame_id = "odom_combined";
107  col_box_mesh_msg.operation = moveit_msgs::CollisionObject::ADD;
108 
109  shapes::Mesh* box_shape = shapes::createMeshFromResource("package://cob_obstacle_distance_moveit/files/box.stl");
110  shapes::ShapeMsg box_mesh_msg;
111  shapes::constructMsgFromShape(box_shape, box_mesh_msg);
112  shape_msgs::Mesh box_mesh = boost::get<shape_msgs::Mesh>(box_mesh_msg);
113 
114  pose.position.x = 1.0;
115  // pose.position.y = 1.0;
116  pose.position.z = 1.0;
117  pose.orientation.w = 1.0;
118 
119  col_box_mesh_msg.meshes.push_back(box_mesh);
120  col_box_mesh_msg.mesh_poses.push_back(pose);
121 
122  pub.publish(col_box_mesh_msg);
123  ros::Duration(0.1).sleep();
124 
125  // primitive cylinder
126  moveit_msgs::CollisionObject col_cylinder_msg;
127  col_cylinder_msg.id = "cylinder_primitive";
128  col_cylinder_msg.header.frame_id = "odom_combined";
129  col_cylinder_msg.operation = moveit_msgs::CollisionObject::ADD;
130 
131  shape_msgs::SolidPrimitive cylinder;
132  cylinder.type = shape_msgs::SolidPrimitive::CYLINDER;
133  cylinder.dimensions.push_back(0.1);
134  cylinder.dimensions.push_back(0.1);
135 
136  pose.position.x = 1.0;
137  pose.position.y = 0.0;
138  pose.position.z = 2.0;
139  pose.orientation.w = 1.0;
140 
141  col_cylinder_msg.primitives.push_back(cylinder);
142  col_cylinder_msg.primitive_poses.push_back(pose);
143 
144  pub.publish(col_cylinder_msg);
145  ros::Duration(0.1).sleep();
146 
147  // mesh cylinder
148  moveit_msgs::CollisionObject col_cylinder_mesh_msg;
149  col_cylinder_mesh_msg.id = "cylinder_mesh";
150  col_cylinder_mesh_msg.header.frame_id = "odom_combined";
151  col_cylinder_mesh_msg.operation = moveit_msgs::CollisionObject::ADD;
152 
153  shapes::Mesh* cylinder_shape = shapes::createMeshFromResource("package://cob_obstacle_distance_moveit/files/cylinder.stl");
154  shapes::ShapeMsg cylinder_mesh_msg;
155  shapes::constructMsgFromShape(cylinder_shape, cylinder_mesh_msg);
156  shape_msgs::Mesh cylinder_mesh = boost::get<shape_msgs::Mesh>(cylinder_mesh_msg);
157 
158  pose.position.x = 1.0;
159  // pose.position.y = 1.0;
160  pose.position.z = 2.0;
161  pose.orientation.w = 1.0;
162 
163  col_cylinder_mesh_msg.meshes.push_back(cylinder_mesh);
164  col_cylinder_mesh_msg.mesh_poses.push_back(pose);
165 
166  pub.publish(col_cylinder_mesh_msg);
167  ros::Duration(0.1).sleep();
168 
169 
170 
171 
172 
173 
175  // test primitive
176  moveit_msgs::CollisionObject test_col_prim_msg;
177  test_col_prim_msg.id = "test_primitive";
178  test_col_prim_msg.header.frame_id = "odom_combined";
179  test_col_prim_msg.operation = moveit_msgs::CollisionObject::ADD;
180 
181  shape_msgs::SolidPrimitive test_prim;
182  //test_prim.type = shape_msgs::SolidPrimitive::SPHERE;
183  //test_prim.type = shape_msgs::SolidPrimitive::BOX;
184  test_prim.type = shape_msgs::SolidPrimitive::CYLINDER;
185  test_prim.dimensions.push_back(0.1);
186  test_prim.dimensions.push_back(0.1);
187  //test_prim.dimensions.push_back(0.1);
188 
189  geometry_msgs::Pose test_pose;
190  test_pose.position.x = 2.0;
191  test_pose.position.y = 0.0;
192  test_pose.position.z = 1.0;
193  test_pose.orientation.w = 1.0;
194 
195  test_col_prim_msg.primitives.push_back(test_prim);
196  test_col_prim_msg.primitive_poses.push_back(test_pose);
197 
198  pub.publish(test_col_prim_msg);
199  ros::Duration(0.1).sleep();
200 
201  // test mesh
202  moveit_msgs::CollisionObject test_col_mesh_msg;
203  test_col_mesh_msg.id = "test_mesh";
204  test_col_mesh_msg.header.frame_id = "odom_combined";
205  test_col_mesh_msg.operation = moveit_msgs::CollisionObject::ADD;
206 
207  //shapes::Mesh* test_shape = shapes::createMeshFromResource("package://cob_obstacle_distance_moveit/files/sphere.stl");
208  //shapes::Mesh* test_shape = shapes::createMeshFromResource("package://cob_obstacle_distance_moveit/files/box.stl");
209  shapes::Mesh* test_shape = shapes::createMeshFromResource("package://cob_obstacle_distance_moveit/files/cylinder.stl");
210  shapes::ShapeMsg test_mesh_msg;
211  shapes::constructMsgFromShape(test_shape, test_mesh_msg);
212  shape_msgs::Mesh test_mesh = boost::get<shape_msgs::Mesh>(test_mesh_msg);
213 
214  test_pose.position.x = 2.0;
215  // test_pose.position.y = 1.0;
216  test_pose.position.z = 1.0;
217  test_pose.orientation.w = 1.0;
218 
219  test_col_mesh_msg.meshes.push_back(test_mesh);
220  test_col_mesh_msg.mesh_poses.push_back(test_pose);
221 
222  pub.publish(test_col_mesh_msg);
223  ros::Duration(0.1).sleep();
224 
225 
226 
227  ROS_INFO("Done");
228 
229  return 0;
230 }
231 
void publish(const boost::shared_ptr< M > &message) const
bool sleep() const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
#define ROS_INFO(...)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
int main(int argc, char **argv)
bool constructMsgFromShape(const Shape *shape, ShapeMsg &shape_msg)
Mesh * createMeshFromResource(const std::string &resource)
boost::variant< shape_msgs::SolidPrimitive, shape_msgs::Mesh, shape_msgs::Plane > ShapeMsg


cob_obstacle_distance_moveit
Author(s): Florian Koehler , Felix Messmer
autogenerated on Sun Dec 6 2020 03:26:02