interactive_marker_helpers.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 // author: Adam Leeper
00031 
00032 #include <interactive_marker_helpers/interactive_marker_helpers.h>
00033 
00034 #include <tf/tf.h>
00035 #include <object_manipulator/tools/msg_helpers.h>
00036 
00037 namespace im_helpers {
00038 
00039 visualization_msgs::InteractiveMarker makeEmptyMarker( const char *frame_id )
00040 {
00041   visualization_msgs::InteractiveMarker int_marker;
00042   int_marker.header.frame_id = frame_id;
00043   int_marker.scale = 1;
00044 
00045   return int_marker;
00046 }
00047 
00048 visualization_msgs::Marker makeBox( float scale )
00049 {
00050   visualization_msgs::Marker marker;
00051 
00052   marker.type = visualization_msgs::Marker::CUBE;
00053   marker.scale.x = scale;
00054   marker.scale.y = scale;
00055   marker.scale.z = scale;
00056   marker.color.r = 1.0;
00057   marker.color.g = 1.0;
00058   marker.color.b = 1.0;
00059   marker.color.a = 1.0;
00060 
00061   return marker;
00062 }
00063 
00064 visualization_msgs::Marker makeSphere( float scale )
00065 {
00066   visualization_msgs::Marker marker;
00067 
00068   marker.type = visualization_msgs::Marker::SPHERE;
00069   marker.scale.x = scale;
00070   marker.scale.y = scale;
00071   marker.scale.z = scale;
00072   marker.color.r = 1.0;
00073   marker.color.g = 1.0;
00074   marker.color.b = 1.0;
00075   marker.color.a = 1.0;
00076 
00077   return marker;
00078 }
00079 
00080 void add6DofControl( visualization_msgs::InteractiveMarker &msg, bool fixed )
00081 {
00082   visualization_msgs::InteractiveMarkerControl control;
00083 
00084   if(fixed)
00085     control.orientation_mode = visualization_msgs::InteractiveMarkerControl::FIXED;
00086 
00087   control.orientation.w = 1;
00088   control.orientation.x = 1;
00089   control.orientation.y = 0;
00090   control.orientation.z = 0;
00091   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00092   msg.controls.push_back(control);
00093   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
00094   msg.controls.push_back(control);
00095 
00096   control.orientation.w = 1;
00097   control.orientation.x = 0;
00098   control.orientation.y = 1;
00099   control.orientation.z = 0;
00100   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00101   msg.controls.push_back(control);
00102   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
00103   msg.controls.push_back(control);
00104 
00105   control.orientation.w = 1;
00106   control.orientation.x = 0;
00107   control.orientation.y = 0;
00108   control.orientation.z = 1;
00109   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00110   msg.controls.push_back(control);
00111   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
00112   msg.controls.push_back(control);
00113 }
00114 
00115 
00116 visualization_msgs::InteractiveMarkerControl& makeBoxControl( visualization_msgs::InteractiveMarker &msg )
00117 {
00118   visualization_msgs::InteractiveMarkerControl control;
00119   control.always_visible = true;
00120   control.markers.push_back( makeBox(msg.scale) );
00121   msg.controls.push_back( control );
00122 
00123   return msg.controls.back();
00124 }
00125 
00126 visualization_msgs::InteractiveMarkerControl& makeSphereControl( visualization_msgs::InteractiveMarker &msg )
00127 {
00128   visualization_msgs::InteractiveMarkerControl control;
00129   control.always_visible = true;
00130   control.markers.push_back( makeSphere(msg.scale) );
00131   msg.controls.push_back( control );
00132 
00133   return msg.controls.back();
00134 }
00135 
00136 visualization_msgs::MenuEntry makeMenuEntry(const char *title)
00137 {
00138   visualization_msgs::MenuEntry m;
00139   m.title = title;
00140   m.command = title;
00141   return m;
00142 }
00143 
00144 visualization_msgs::MenuEntry makeMenuEntry(const char *title, const char *command, int type  )
00145 {
00146   visualization_msgs::MenuEntry m;
00147   m.title = title;
00148   m.command = command;
00149   m.command_type = type;
00150   return m;
00151 }
00152 
00153 visualization_msgs::InteractiveMarker makePostureMarker( const char *name, const geometry_msgs::PoseStamped &stamped,
00154                                                          float scale, bool fixed, bool view_facing )
00155 {
00156   visualization_msgs::InteractiveMarker int_marker;
00157   int_marker.header =  stamped.header;
00158   int_marker.name = name;
00159   int_marker.scale = scale;
00160   int_marker.pose = stamped.pose;
00161 
00162   visualization_msgs::InteractiveMarkerControl control;
00163   control.orientation.w = 1;
00164   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00165   int_marker.controls.push_back(control);
00166 
00167   return int_marker;
00168 }
00169 
00170 visualization_msgs::InteractiveMarker makeHeadGoalMarker( const char *name, const geometry_msgs::PoseStamped &stamped,
00171                                                           float scale)
00172 {
00173   visualization_msgs::InteractiveMarker int_marker;
00174   int_marker.header =  stamped.header;
00175   int_marker.name = name;
00176   int_marker.scale = scale;
00177   int_marker.pose = stamped.pose;
00178 
00179   visualization_msgs::InteractiveMarkerControl control;
00180   control.orientation_mode = visualization_msgs::InteractiveMarkerControl::VIEW_FACING;
00181   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_PLANE;
00182   control.orientation.w = 1;
00183   control.markers.push_back( makeSphere(scale*0.7) );
00184   int_marker.controls.push_back(control);
00185   control.markers.clear();
00186 
00187   add6DofControl(int_marker);
00188 
00189   return int_marker;
00190 }
00191 
00192 visualization_msgs::InteractiveMarker makeMeshMarker( const std::string &name, const std::string &mesh_resource,
00193                                                       const geometry_msgs::PoseStamped &stamped, float scale, const std_msgs::ColorRGBA &color, bool use_color )
00194 {
00195   visualization_msgs::InteractiveMarker int_marker;
00196   int_marker.header =  stamped.header;
00197   int_marker.pose = stamped.pose;
00198   int_marker.name = name;
00199   int_marker.scale = scale;
00200 
00201   visualization_msgs::Marker mesh;
00202   if (use_color) mesh.color = color;
00203   mesh.mesh_resource = mesh_resource;
00204   mesh.mesh_use_embedded_materials = !use_color;
00205   mesh.type = visualization_msgs::Marker::MESH_RESOURCE;
00206   mesh.scale.x = scale;
00207   mesh.scale.y = scale;
00208   mesh.scale.z = scale;
00209 
00210   visualization_msgs::InteractiveMarkerControl control;
00211   control.markers.push_back( mesh );
00212   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00213   int_marker.controls.push_back( control );
00214 
00215   return int_marker;
00216 }
00217 
00218 visualization_msgs::InteractiveMarker makeMeshMarker( const std::string &name, const std::string &mesh_resource,
00219                                                       const geometry_msgs::PoseStamped &stamped, float scale)
00220 {
00221   std_msgs::ColorRGBA color;
00222   return makeMeshMarker( name, mesh_resource, stamped, scale, color, false);
00223 }
00224 
00225 visualization_msgs::InteractiveMarker makeMeshMarker( const std::string &name, const std::string &mesh_resource,
00226                                                       const geometry_msgs::PoseStamped &stamped, float scale, const std_msgs::ColorRGBA &color)
00227 {
00228   return makeMeshMarker( name, mesh_resource, stamped, scale, color, true);
00229 }
00230 
00231 visualization_msgs::InteractiveMarker makeButtonBox( const char *name, const geometry_msgs::PoseStamped &stamped, float scale, bool fixed, bool view_facing )
00232 {
00233   visualization_msgs::InteractiveMarker int_marker;
00234   int_marker.header =  stamped.header;
00235   int_marker.name = name;
00236   int_marker.scale = scale;
00237   int_marker.pose = stamped.pose;
00238   //int_marker.description = "This is the marker.";
00239 
00240   visualization_msgs::InteractiveMarkerControl &control = makeBoxControl(int_marker);
00241   //control.description = "This is the control";
00242   control.always_visible = false;
00243   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00244 
00245   return int_marker;
00246 }
00247 
00248 visualization_msgs::InteractiveMarker makeButtonSphere( const char *name, const geometry_msgs::PoseStamped &stamped,
00249                                                         float scale, bool fixed, bool view_facing)
00250 {
00251   std_msgs::ColorRGBA color;
00252   return makeButtonSphere(name, stamped, scale, fixed, view_facing, color);
00253 }
00254 
00255 visualization_msgs::InteractiveMarker makeButtonSphere( const char *name, const geometry_msgs::PoseStamped &stamped,
00256                                                         float scale, bool fixed, bool view_facing,
00257                                                         std_msgs::ColorRGBA color)
00258 {
00259   visualization_msgs::InteractiveMarker int_marker;
00260   int_marker.header =  stamped.header;
00261   int_marker.name = name;
00262   int_marker.scale = scale;
00263   int_marker.pose = stamped.pose;
00264   //int_marker.description = "This is the marker.";
00265 
00266   visualization_msgs::InteractiveMarkerControl &control = makeSphereControl(int_marker);
00267   //control.description = "This is the control";
00268   control.always_visible = false;
00269   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00270   control.markers.back().color = color;
00271 
00272   return int_marker;
00273 }
00274 
00275 visualization_msgs::InteractiveMarker makeListControl( const char *name, const geometry_msgs::PoseStamped &stamped, int num, int total, float scale)
00276 {
00277 
00278   visualization_msgs::InteractiveMarker int_marker;
00279   int_marker.header =  stamped.header;
00280   int_marker.name = name;
00281   int_marker.scale = scale;
00282   int_marker.pose = stamped.pose;
00283 
00284   visualization_msgs::InteractiveMarkerControl control;
00285 
00286 //  control.orientation_mode = visualization_msgs::InteractiveMarkerControl::VIEW_FACING;
00287   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00288   std::stringstream ss;
00289   ss << "pose(" << num << "/" << total << ")";
00290   interactive_markers::makeViewFacingButton(int_marker, control, ss.str());
00291 
00292 //  control.orientation.w = 1;
00293 //  control.orientation.x = 0;
00294 //  control.orientation.y = -1;
00295 //  control.orientation.z = 0;
00296 
00297 //  interactive_markers::makeArrow( int_marker, control, 0.3*scale );
00298 //  control.markers.back().color.r = 1.0;
00299 //  control.markers.back().color.g = 0.0;
00300 //  control.markers.back().color.b = 0.0;
00301 //  control.name = "right";
00302 //  int_marker.controls.push_back(control);
00303 //
00304 //  control.markers.clear();
00305 //  interactive_markers::makeArrow( int_marker, control, -0.3*scale );
00306 //  control.markers.back().color.r = 0.0;
00307 //  control.markers.back().color.g = 1.0;
00308 //  control.markers.back().color.b = 0.0;
00309 //  control.name = "left";
00310   int_marker.controls.push_back(control);
00311 
00312   return int_marker;
00313 
00314 
00315 //  visualization_msgs::InteractiveMarker int_marker;
00316 //  int_marker.header =  stamped.header;
00317 //  int_marker.name = name;
00318 //  int_marker.scale = scale;
00319 //  int_marker.pose = stamped.pose;
00320 //  //int_marker.description = "This is the marker.";
00321 //
00322 //  visualization_msgs::InteractiveMarkerControl &control = makeSphereControl(int_marker);
00323 //  //control.description = "This is the control";
00324 //  control.always_visible = false;
00325 //  control.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00326 //
00327 //  return int_marker;
00328 }
00329 
00330 visualization_msgs::InteractiveMarker make6DofMarker( const char *name, const geometry_msgs::PoseStamped &stamped, float scale, bool fixed, bool view_facing )
00331 {
00332   visualization_msgs::InteractiveMarker int_marker;
00333   int_marker.header =  stamped.header;
00334   int_marker.name = name;
00335   int_marker.scale = scale;
00336   int_marker.pose = stamped.pose;
00337 
00338   if ( view_facing )
00339   {
00340     visualization_msgs::InteractiveMarkerControl control;
00341     control.orientation_mode = visualization_msgs::InteractiveMarkerControl::VIEW_FACING;
00342     //control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_ROTATE;
00343     control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00344     control.orientation.w = 1;
00345     int_marker.controls.push_back(control);
00346 
00347     control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_PLANE;
00348     control.markers.push_back( makeSphere(scale*0.5) );
00349     int_marker.controls.push_back(control);
00350   }
00351   else
00352   {
00353     add6DofControl(int_marker, fixed);
00354   }
00355 
00356   return int_marker;
00357 }
00358 
00359 visualization_msgs::InteractiveMarker makePlanarMarker( const char *name, const geometry_msgs::PoseStamped &stamped, float scale, bool fixed )
00360 {
00361   visualization_msgs::InteractiveMarker int_marker;
00362   int_marker.header =  stamped.header;
00363   int_marker.name = name;
00364   int_marker.scale = scale;
00365   int_marker.pose = stamped.pose;
00366 
00367   visualization_msgs::InteractiveMarkerControl control;
00368   control.orientation_mode = fixed ? (uint8_t)visualization_msgs::InteractiveMarkerControl::FIXED : (uint8_t)visualization_msgs::InteractiveMarkerControl::INHERIT;
00369   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_ROTATE;
00370   control.orientation.w = 1;
00371   control.orientation.x = 0;
00372   control.orientation.y = 1;
00373   control.orientation.z = 0;
00374   int_marker.controls.push_back(control);
00375 
00376   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_PLANE;
00377   interactive_markers::makeArrow( int_marker, control, 0 );
00378   control.markers.back().pose.orientation.w = 0;
00379   control.markers.back().pose.orientation.x = 0;
00380   control.markers.back().pose.orientation.y = 1;
00381   control.markers.back().pose.orientation.z = 0;
00382   control.markers.back().color.r = 0.0;
00383   control.markers.back().color.g = 1.0;
00384   control.markers.back().color.b = 0.0;
00385   int_marker.controls.push_back(control);
00386 
00387   return int_marker;
00388 }
00389 
00390 visualization_msgs::InteractiveMarker makeElevatorMarker( const char *name, const geometry_msgs::PoseStamped &stamped, float scale, bool fixed)
00391 {
00392   visualization_msgs::InteractiveMarker int_marker;
00393   int_marker.header =  stamped.header;
00394   int_marker.name = name;
00395   int_marker.scale = scale;
00396   int_marker.pose = stamped.pose;
00397 
00398   visualization_msgs::InteractiveMarkerControl control;
00399 
00400   if(fixed)
00401     control.orientation_mode = visualization_msgs::InteractiveMarkerControl::FIXED;
00402 
00403   control.orientation.w = 1;
00404   control.orientation.x = 0;
00405   control.orientation.y = -1;
00406   control.orientation.z = 0;
00407   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00408 
00409   interactive_markers::makeArrow( int_marker, control, 0.3 );
00410   control.markers.back().color.r = 0.0;
00411   control.markers.back().color.g = 1.0;
00412   control.markers.back().color.b = 0.0;
00413   control.name = "up";
00414   int_marker.controls.push_back(control);
00415 
00416   control.markers.clear();
00417   interactive_markers::makeArrow( int_marker, control, -0.3 );
00418   control.markers.back().color.r = 1.0;
00419   control.markers.back().color.g = 0.0;
00420   control.markers.back().color.b = 0.0;
00421   control.name = "down";
00422   int_marker.controls.push_back(control);
00423 
00424   return int_marker;
00425 }
00426 
00427 visualization_msgs::InteractiveMarker makeProjectorMarker( const char *name, const geometry_msgs::PoseStamped &stamped, float scale)
00428 {
00429   visualization_msgs::InteractiveMarker int_marker;
00430   int_marker.header =  stamped.header;
00431   int_marker.name = name;
00432   int_marker.scale = scale;
00433   int_marker.pose = stamped.pose;
00434 
00435   visualization_msgs::InteractiveMarkerControl control;
00436   control.orientation.w = 1;
00437   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00438   visualization_msgs::Marker marker;
00439   marker.type = visualization_msgs::Marker::CYLINDER;
00440   marker.scale.x = 0.03;
00441   marker.scale.y = 0.03;
00442   marker.scale.z = 0.04;
00443   marker.color.r = 1.0;
00444   marker.color.a = 0.8;
00445   control.markers.push_back(marker);
00446   int_marker.controls.push_back(control);
00447 
00448   return int_marker;
00449 }
00450 
00451 
00452 visualization_msgs::InteractiveMarker makeBaseMarker( const char *name, const geometry_msgs::PoseStamped &stamped, float scale, bool fixed)
00453 {
00454   visualization_msgs::InteractiveMarker int_marker;
00455   int_marker.header =  stamped.header;
00456   int_marker.name = name;
00457   int_marker.scale = scale;
00458   int_marker.pose = stamped.pose;
00459 
00460   visualization_msgs::InteractiveMarkerControl control;
00461 
00462   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00463   control.orientation.w = 1;
00464   control.orientation.y = -1;
00465   int_marker.controls.push_back(control);
00466 
00467 
00468   if(fixed)
00469     control.orientation_mode = visualization_msgs::InteractiveMarkerControl::FIXED;
00470 
00471   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00472   control.orientation.w = 1;
00473   control.orientation.y = 0;
00474 
00475   control.markers.clear();
00476   interactive_markers::makeArrow( int_marker, control, 0.9 );
00477   control.markers.back().color.r = 1.0;
00478   control.markers.back().color.g = 0.0;
00479   control.markers.back().color.b = 0.0;
00480   control.name = "forward";
00481   int_marker.controls.push_back(control);
00482 
00483   control.markers.clear();
00484   interactive_markers::makeArrow( int_marker, control, -0.9 );
00485   control.markers.back().color.r = 1.0;
00486   control.markers.back().color.g = 0.0;
00487   control.markers.back().color.b = 0.0;
00488   control.name = "back";
00489   int_marker.controls.push_back(control);
00490 
00491   control.orientation.z = 1;
00492   control.markers.clear();
00493   interactive_markers::makeArrow( int_marker, control, 0.9 );
00494   control.markers.back().color.r = 1.0;
00495   control.markers.back().color.g = 0.0;
00496   control.markers.back().color.b = 0.0;
00497   control.name = "left";
00498   int_marker.controls.push_back(control);
00499 
00500   control.markers.clear();
00501   interactive_markers::makeArrow( int_marker, control, -0.9 );
00502   control.markers.back().color.r = 1.0;
00503   control.markers.back().color.g = 0.0;
00504   control.markers.back().color.b = 0.0;
00505   control.name = "right";
00506   int_marker.controls.push_back(control);
00507 
00508   control.markers.clear();
00509   tf::quaternionTFToMsg( tf::Quaternion(tf::Vector3(0,0,1), 135*M_PI/180.0), control.orientation);
00510   interactive_markers::makeArrow( int_marker, control, 1.0 );
00511   control.markers.back().pose.position.x = 0.7;
00512   control.markers.back().color.r = 1.0;
00513   control.markers.back().color.g = 1.0;
00514   control.markers.back().color.b = 0.0;
00515   control.name = "rotate left";
00516   int_marker.controls.push_back(control);
00517 
00518   control.markers.clear();
00519   tf::quaternionTFToMsg( tf::Quaternion(tf::Vector3(0,0,1), -135*M_PI/180.0), control.orientation);
00520   interactive_markers::makeArrow( int_marker, control, 1.0 );
00521   control.markers.back().pose.position.x = 0.7;
00522   control.markers.back().color.r = 1.0;
00523   control.markers.back().color.g = 1.0;
00524   control.markers.back().color.b = 0.0;
00525   control.name = "rotate right";
00526   int_marker.controls.push_back(control);
00527   return int_marker;
00528 }
00529 
00530 visualization_msgs::InteractiveMarker makeGripperMarker( const char *name, const geometry_msgs::PoseStamped &stamped,
00531                                                          float scale, float angle, bool view_facing)
00532 {
00533   std_msgs::ColorRGBA color;
00534   return makeGripperMarker( name, stamped, scale, angle, view_facing, color, false);
00535 }
00536 
00537 visualization_msgs::InteractiveMarker makeGripperMarker( const char *name, const geometry_msgs::PoseStamped &stamped,
00538                                                          float scale, float angle, bool view_facing, std_msgs::ColorRGBA color )
00539 {
00540   return makeGripperMarker( name, stamped, scale, angle, view_facing, color, true);
00541 }
00542 
00543 
00544 visualization_msgs::InteractiveMarker makeGripperMarker( const char *name, const geometry_msgs::PoseStamped &stamped,
00545                                                          float scale, float angle, bool view_facing, std_msgs::ColorRGBA color, bool use_color )
00546 {
00547   visualization_msgs::InteractiveMarker int_marker;
00548   int_marker.header =  stamped.header;
00549   int_marker.name = name;
00550   int_marker.scale = 1.0; //scale;
00551   int_marker.pose = stamped.pose;
00552 
00553 //  add6DofControl(int_marker, false);
00554 
00555   visualization_msgs::InteractiveMarkerControl control;
00556 
00557   visualization_msgs::Marker mesh;
00558   mesh.mesh_use_embedded_materials = !use_color;
00559   mesh.type = visualization_msgs::Marker::MESH_RESOURCE;
00560   mesh.scale.x = scale;
00561   mesh.scale.y = scale;
00562   mesh.scale.z = scale;
00563   mesh.color = color;
00564 
00565   tf::Transform T1, T2;
00566   tf::Transform T_proximal, T_distal;
00567 
00568   T1.setOrigin(tf::Vector3(0.07691, 0.01, 0));
00569   T1.setRotation(tf::Quaternion(tf::Vector3(0,0,1),  angle));
00570   T2.setOrigin(tf::Vector3(0.09137, 0.00495, 0));
00571   T2.setRotation(tf::Quaternion(tf::Vector3(0,0,1), -angle));
00572   T_proximal = T1;
00573   T_distal = T1 * T2;
00574 
00575   mesh.mesh_resource = "package://pr2_description/meshes/gripper_v0/gripper_palm.dae";
00576   mesh.pose.orientation.w = 1;
00577   control.markers.push_back( mesh );
00578   mesh.mesh_resource = "package://pr2_description/meshes/gripper_v0/l_finger.dae";
00579   mesh.pose = object_manipulator::msg::createPoseMsg(T_proximal);
00580   control.markers.push_back( mesh );
00581   mesh.mesh_resource = "package://pr2_description/meshes/gripper_v0/l_finger_tip.dae";
00582   mesh.pose = object_manipulator::msg::createPoseMsg(T_distal);
00583   control.markers.push_back( mesh );
00584 
00585   T1.setOrigin(tf::Vector3(0.07691, -0.01, 0));
00586   T1.setRotation(tf::Quaternion(tf::Vector3(1,0,0), M_PI)*tf::Quaternion(tf::Vector3(0,0,1),  angle));
00587   T2.setOrigin(tf::Vector3(0.09137, 0.00495, 0));
00588   T2.setRotation(tf::Quaternion(tf::Vector3(0,0,1), -angle));
00589   T_proximal = T1;
00590   T_distal = T1 * T2;
00591 
00592   mesh.mesh_resource = "package://pr2_description/meshes/gripper_v0/l_finger.dae";
00593   mesh.pose = object_manipulator::msg::createPoseMsg(T_proximal);
00594   control.markers.push_back( mesh );
00595   mesh.mesh_resource = "package://pr2_description/meshes/gripper_v0/l_finger_tip.dae";
00596   mesh.pose = object_manipulator::msg::createPoseMsg(T_distal);
00597   control.markers.push_back( mesh );
00598 
00599   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00600   int_marker.controls.push_back( control );
00601 
00602   return int_marker;
00603 }
00604 
00605 
00606 visualization_msgs::InteractiveMarker makeGraspMarker( const char * name, const geometry_msgs::PoseStamped &stamped, float scale, PoseState pose_state)
00607 {
00608   visualization_msgs::InteractiveMarker int_marker;
00609   int_marker.header =  stamped.header;
00610   int_marker.header.stamp = ros::Time(0);
00611   int_marker.name = name;
00612   int_marker.scale = scale;
00613   int_marker.pose = stamped.pose;
00614 
00615   visualization_msgs::InteractiveMarkerControl control;
00616   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00617   control.orientation.w = 1;
00618   visualization_msgs::Marker marker;
00619   marker.type = visualization_msgs::Marker::ARROW;
00620   //marker.header = int_marker.header;
00621   //marker.pose = int_marker.pose;
00622   marker.scale.x = 0.10*scale;
00623   marker.scale.y = 0.05*scale;
00624   marker.scale.z = 0.05*scale;
00625   marker.color.r = 1.0;
00626   marker.color.a = 1.0;
00627   control.markers.push_back(marker);
00628   marker.type = visualization_msgs::Marker::CUBE;
00629   marker.scale.x = 0.015*scale;
00630   marker.scale.y = 0.04*scale;
00631   marker.scale.z = 0.015*scale;
00632   switch (pose_state)
00633   {
00634   case UNTESTED:
00635     marker.color.g = 0.5;
00636     marker.color.b = 0.5;
00637     marker.color.r = 0.5;
00638     break;
00639   case VALID:
00640     marker.color.g = 1.0;
00641     marker.color.r = 0.0;
00642     break;
00643   case INVALID:
00644     marker.color.g = 0.0;
00645     marker.color.r = 1.0;
00646     break;
00647   }
00648   control.markers.push_back(marker);
00649 //  marker.points[0] = object_manipulator::msg::createPointMsg(0,0,0);
00650 //  marker.points[1] = object_manipulator::msg::createPointMsg(0,0.03,0);
00651 //  marker.color.r = 0;
00652 //  marker.color.g = 1.0;
00653 //  control.markers.push_back(marker);
00654 
00655   int_marker.controls.push_back(control);
00656 
00657   return int_marker;
00658 }
00659 
00660 
00661 visualization_msgs::InteractiveMarker makePosedMultiMeshMarker( const char * name, const geometry_msgs::PoseStamped &stamped,
00662                                                                 const std::vector< geometry_msgs::PoseStamped> &mesh_poses,
00663                                                                 const std::vector<std::string> &mesh_paths, const float &scale,
00664                                                                 const bool button_only)
00665 {
00666     //ROS_ERROR("Start create robot marker...");
00667     visualization_msgs::InteractiveMarker int_marker;
00668     int_marker.header =  stamped.header;
00669     int_marker.name = name;
00670     int_marker.scale = scale;
00671     int_marker.pose = stamped.pose;
00672 
00673     bool fixed = false;
00674     visualization_msgs::InteractiveMarkerControl control;
00675     if( !button_only )
00676     {
00677         control.orientation_mode = fixed ? (uint8_t)visualization_msgs::InteractiveMarkerControl::FIXED : (uint8_t)visualization_msgs::InteractiveMarkerControl::INHERIT;
00678         control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00679         control.orientation.w = 1;
00680         control.orientation.x = 0;
00681         control.orientation.y = 1;
00682         control.orientation.z = 0;
00683         int_marker.controls.push_back(control);
00684     }
00685 
00686     control.markers.clear();
00687     control.interaction_mode = button_only ? (visualization_msgs::InteractiveMarkerControl::BUTTON) : (visualization_msgs::InteractiveMarkerControl::MOVE_PLANE);
00688     for(size_t i = 0; i < mesh_poses.size(); i++)
00689     {
00690         visualization_msgs::Marker mesh;
00691         mesh.color = std_msgs::ColorRGBA();
00692         mesh.mesh_resource = mesh_paths[i];
00693         mesh.mesh_use_embedded_materials = true;
00694         mesh.type = visualization_msgs::Marker::MESH_RESOURCE;
00695         mesh.scale.x = mesh.scale.y = mesh.scale.z = scale;
00696         mesh.pose = mesh_poses[i].pose;
00697         control.markers.push_back( mesh );
00698     }
00699     int_marker.controls.push_back( control );
00700 
00701     return int_marker;
00702 
00703 }
00704 
00705 visualization_msgs::InteractiveMarker makeFollowerMultiMeshMarker( const char * name, const geometry_msgs::PoseStamped &stamped,
00706                                                                    const std::vector<std::string> &mesh_frames,
00707                                                                    const std::vector<std::string> &mesh_paths,
00708                                                                    const float &scale)
00709 {
00710     visualization_msgs::InteractiveMarker int_marker;
00711     int_marker.header =  stamped.header;
00712     int_marker.name = name;
00713     int_marker.scale = scale;
00714     int_marker.pose = stamped.pose;
00715 
00716     if(mesh_frames.size() != mesh_paths.size())
00717     {
00718       ROS_ERROR("The number of mesh frames and mesh paths is not equal!");
00719       return int_marker;
00720     }
00721 
00722     visualization_msgs::InteractiveMarkerControl control;
00723 
00724     control.markers.clear();
00725     control.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00726     for(size_t i = 0; i < mesh_frames.size(); i++)
00727     {
00728         visualization_msgs::Marker mesh;
00729         mesh.color = std_msgs::ColorRGBA();
00730         mesh.mesh_resource = mesh_paths[i];
00731         mesh.mesh_use_embedded_materials = true;
00732         mesh.type = visualization_msgs::Marker::MESH_RESOURCE;
00733         mesh.scale.x = mesh.scale.y = mesh.scale.z = scale;
00734         mesh.pose.orientation.w = 1;
00735         mesh.header.frame_id = mesh_frames[i];
00736         control.markers.push_back( mesh );
00737         mesh.frame_locked = true;
00738     }
00739     int_marker.controls.push_back( control );
00740 
00741     return int_marker;
00742 }
00743 
00744 } // namespace im_helpers


interactive_marker_helpers
Author(s): Adam Leeper
autogenerated on Thu Jan 2 2014 11:39:55