test_obstacle_publisher_node.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *   http://www.apache.org/licenses/LICENSE-2.0
00009 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016  
00017 
00018 #include <ros/ros.h>
00019 #include <geometry_msgs/Pose.h>
00020 #include <moveit_msgs/CollisionObject.h>
00021 #include <shape_msgs/SolidPrimitive.h>
00022 #include <geometric_shapes/shape_operations.h>
00023 #include <geometric_shapes/mesh_operations.h>
00024 
00025 #include <boost/variant.hpp>
00026 #include <boost/shared_ptr.hpp>
00027 
00028 
00029 int main(int argc, char** argv)
00030 {
00031   ros::init(argc, argv, "test_obstacle_publisher_node");
00032   ros::NodeHandle n;
00033   ros::Publisher pub = n.advertise<moveit_msgs::CollisionObject>("/collision_object", 1);
00034   ros::Duration(1.0).sleep();
00035 
00036   // primitive sphere
00037   moveit_msgs::CollisionObject col_sphere_msg;
00038   col_sphere_msg.id = "sphere_primitive";
00039   col_sphere_msg.header.frame_id = "odom_combined";
00040   col_sphere_msg.operation = moveit_msgs::CollisionObject::ADD;
00041 
00042   shape_msgs::SolidPrimitive sphere;
00043   sphere.type = shape_msgs::SolidPrimitive::SPHERE;
00044   sphere.dimensions.push_back(0.1);
00045 
00046   geometry_msgs::Pose pose;
00047   pose.position.x = 1.0;
00048   pose.position.y = 0.0;
00049   pose.position.z = 0.0;
00050   pose.orientation.w = 1.0;
00051 
00052   col_sphere_msg.primitives.push_back(sphere);
00053   col_sphere_msg.primitive_poses.push_back(pose);
00054 
00055   pub.publish(col_sphere_msg);
00056   ros::Duration(0.1).sleep();
00057 
00058   // mesh sphere
00059   moveit_msgs::CollisionObject col_sphere_mesh_msg;
00060   col_sphere_mesh_msg.id = "sphere_mesh";
00061   col_sphere_mesh_msg.header.frame_id = "odom_combined";
00062   col_sphere_mesh_msg.operation = moveit_msgs::CollisionObject::ADD;
00063 
00064   shapes::Mesh* sphere_shape = shapes::createMeshFromResource("package://cob_obstacle_distance_moveit/files/sphere.stl");
00065   shapes::ShapeMsg sphere_mesh_msg;
00066   shapes::constructMsgFromShape(sphere_shape, sphere_mesh_msg);
00067   shape_msgs::Mesh sphere_mesh = boost::get<shape_msgs::Mesh>(sphere_mesh_msg);
00068 
00069   pose.position.x = 1.0;
00070   // pose.position.y = 1.0;
00071   pose.position.z = 0.0;
00072   pose.orientation.w = 1.0;
00073 
00074   col_sphere_mesh_msg.meshes.push_back(sphere_mesh);
00075   col_sphere_mesh_msg.mesh_poses.push_back(pose);
00076 
00077   pub.publish(col_sphere_mesh_msg);
00078   ros::Duration(0.1).sleep();
00079 
00080   // primitive box
00081   moveit_msgs::CollisionObject col_box_msg;
00082   col_box_msg.id = "box_primitive";
00083   col_box_msg.header.frame_id = "odom_combined";
00084   col_box_msg.operation = moveit_msgs::CollisionObject::ADD;
00085 
00086   shape_msgs::SolidPrimitive box;
00087   box.type = shape_msgs::SolidPrimitive::BOX;
00088   box.dimensions.push_back(0.1);
00089   box.dimensions.push_back(0.1);
00090   box.dimensions.push_back(0.1);
00091 
00092   pose.position.x = 1.0;
00093   pose.position.y = 0.0;
00094   pose.position.z = 1.0;
00095   pose.orientation.w = 1.0;
00096 
00097   col_box_msg.primitives.push_back(box);
00098   col_box_msg.primitive_poses.push_back(pose);
00099 
00100   pub.publish(col_box_msg);
00101   ros::Duration(0.1).sleep();
00102 
00103   // mesh box
00104   moveit_msgs::CollisionObject col_box_mesh_msg;
00105   col_box_mesh_msg.id = "box_mesh";
00106   col_box_mesh_msg.header.frame_id = "odom_combined";
00107   col_box_mesh_msg.operation = moveit_msgs::CollisionObject::ADD;
00108 
00109   shapes::Mesh* box_shape = shapes::createMeshFromResource("package://cob_obstacle_distance_moveit/files/box.stl");
00110   shapes::ShapeMsg box_mesh_msg;
00111   shapes::constructMsgFromShape(box_shape, box_mesh_msg);
00112   shape_msgs::Mesh box_mesh = boost::get<shape_msgs::Mesh>(box_mesh_msg);
00113 
00114   pose.position.x = 1.0;
00115   // pose.position.y = 1.0;
00116   pose.position.z = 1.0;
00117   pose.orientation.w = 1.0;
00118 
00119   col_box_mesh_msg.meshes.push_back(box_mesh);
00120   col_box_mesh_msg.mesh_poses.push_back(pose);
00121 
00122   pub.publish(col_box_mesh_msg);
00123   ros::Duration(0.1).sleep();
00124 
00125   // primitive cylinder
00126   moveit_msgs::CollisionObject col_cylinder_msg;
00127   col_cylinder_msg.id = "cylinder_primitive";
00128   col_cylinder_msg.header.frame_id = "odom_combined";
00129   col_cylinder_msg.operation = moveit_msgs::CollisionObject::ADD;
00130 
00131   shape_msgs::SolidPrimitive cylinder;
00132   cylinder.type = shape_msgs::SolidPrimitive::CYLINDER;
00133   cylinder.dimensions.push_back(0.1);
00134   cylinder.dimensions.push_back(0.1);
00135 
00136   pose.position.x = 1.0;
00137   pose.position.y = 0.0;
00138   pose.position.z = 2.0;
00139   pose.orientation.w = 1.0;
00140 
00141   col_cylinder_msg.primitives.push_back(cylinder);
00142   col_cylinder_msg.primitive_poses.push_back(pose);
00143 
00144   pub.publish(col_cylinder_msg);
00145   ros::Duration(0.1).sleep();
00146 
00147   // mesh cylinder
00148   moveit_msgs::CollisionObject col_cylinder_mesh_msg;
00149   col_cylinder_mesh_msg.id = "cylinder_mesh";
00150   col_cylinder_mesh_msg.header.frame_id = "odom_combined";
00151   col_cylinder_mesh_msg.operation = moveit_msgs::CollisionObject::ADD;
00152 
00153   shapes::Mesh* cylinder_shape = shapes::createMeshFromResource("package://cob_obstacle_distance_moveit/files/cylinder.stl");
00154   shapes::ShapeMsg cylinder_mesh_msg;
00155   shapes::constructMsgFromShape(cylinder_shape, cylinder_mesh_msg);
00156   shape_msgs::Mesh cylinder_mesh = boost::get<shape_msgs::Mesh>(cylinder_mesh_msg);
00157 
00158   pose.position.x = 1.0;
00159   // pose.position.y = 1.0;
00160   pose.position.z = 2.0;
00161   pose.orientation.w = 1.0;
00162 
00163   col_cylinder_mesh_msg.meshes.push_back(cylinder_mesh);
00164   col_cylinder_mesh_msg.mesh_poses.push_back(pose);
00165 
00166   pub.publish(col_cylinder_mesh_msg);
00167   ros::Duration(0.1).sleep();
00168 
00169 
00170 
00171 
00172 
00173 
00175   // test primitive
00176   moveit_msgs::CollisionObject test_col_prim_msg;
00177   test_col_prim_msg.id = "test_primitive";
00178   test_col_prim_msg.header.frame_id = "odom_combined";
00179   test_col_prim_msg.operation = moveit_msgs::CollisionObject::ADD;
00180 
00181   shape_msgs::SolidPrimitive test_prim;
00182   //test_prim.type = shape_msgs::SolidPrimitive::SPHERE;
00183   //test_prim.type = shape_msgs::SolidPrimitive::BOX;
00184   test_prim.type = shape_msgs::SolidPrimitive::CYLINDER;
00185   test_prim.dimensions.push_back(0.1);
00186   test_prim.dimensions.push_back(0.1);
00187   //test_prim.dimensions.push_back(0.1);
00188 
00189   geometry_msgs::Pose test_pose;
00190   test_pose.position.x = 2.0;
00191   test_pose.position.y = 0.0;
00192   test_pose.position.z = 1.0;
00193   test_pose.orientation.w = 1.0;
00194 
00195   test_col_prim_msg.primitives.push_back(test_prim);
00196   test_col_prim_msg.primitive_poses.push_back(test_pose);
00197 
00198   pub.publish(test_col_prim_msg);
00199   ros::Duration(0.1).sleep();
00200 
00201   // test mesh
00202   moveit_msgs::CollisionObject test_col_mesh_msg;
00203   test_col_mesh_msg.id = "test_mesh";
00204   test_col_mesh_msg.header.frame_id = "odom_combined";
00205   test_col_mesh_msg.operation = moveit_msgs::CollisionObject::ADD;
00206 
00207   //shapes::Mesh* test_shape = shapes::createMeshFromResource("package://cob_obstacle_distance_moveit/files/sphere.stl");
00208   //shapes::Mesh* test_shape = shapes::createMeshFromResource("package://cob_obstacle_distance_moveit/files/box.stl");
00209   shapes::Mesh* test_shape = shapes::createMeshFromResource("package://cob_obstacle_distance_moveit/files/cylinder.stl");
00210   shapes::ShapeMsg test_mesh_msg;
00211   shapes::constructMsgFromShape(test_shape, test_mesh_msg);
00212   shape_msgs::Mesh test_mesh = boost::get<shape_msgs::Mesh>(test_mesh_msg);
00213 
00214   test_pose.position.x = 2.0;
00215   // test_pose.position.y = 1.0;
00216   test_pose.position.z = 1.0;
00217   test_pose.orientation.w = 1.0;
00218 
00219   test_col_mesh_msg.meshes.push_back(test_mesh);
00220   test_col_mesh_msg.mesh_poses.push_back(test_pose);
00221 
00222   pub.publish(test_col_mesh_msg);
00223   ros::Duration(0.1).sleep();
00224 
00225 
00226 
00227   ROS_INFO("Done");
00228 
00229   return 0;
00230 }
00231 


cob_obstacle_distance_moveit
Author(s): Florian Koehler , Felix Messmer
autogenerated on Thu Jun 6 2019 21:23:10