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 #include <jsk_interactive_marker/interactive_marker_helpers.h>
00034 
00035 #include <tf/tf.h>
00036 // #include <object_manipulator/tools/msg_helpers.h>
00037 
00038 namespace im_helpers {
00039 
00040 geometry_msgs::Pose createPoseMsg(const tf::Transform &transform)
00041 {
00042   geometry_msgs::Pose pose;
00043   tf::Vector3 pos = transform.getOrigin();
00044   tf::Quaternion rot = transform.getRotation();
00045   pose.position.x = pos[0];
00046   pose.position.y = pos[1];
00047   pose.position.z = pos[2];
00048   pose.orientation.x = rot.getX();
00049   pose.orientation.y = rot.getY();
00050   pose.orientation.z = rot.getZ();
00051   pose.orientation.w = rot.getW();
00052   return pose;
00053 }
00054   
00055 visualization_msgs::InteractiveMarker makeEmptyMarker( const char *frame_id )
00056 {
00057   visualization_msgs::InteractiveMarker int_marker;
00058   int_marker.header.frame_id = frame_id;
00059   int_marker.scale = 1;
00060 
00061   return int_marker;
00062 }
00063 
00064 visualization_msgs::Marker makeBox( float scale )
00065 {
00066   visualization_msgs::Marker marker;
00067 
00068   marker.type = visualization_msgs::Marker::CUBE;
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 visualization_msgs::Marker makeSphere( float scale )
00081 {
00082   visualization_msgs::Marker marker;
00083 
00084   marker.type = visualization_msgs::Marker::SPHERE;
00085   marker.scale.x = scale;
00086   marker.scale.y = scale;
00087   marker.scale.z = scale;
00088   marker.color.r = 1.0;
00089   marker.color.g = 1.0;
00090   marker.color.b = 1.0;
00091   marker.color.a = 1.0;
00092 
00093   return marker;
00094 }
00095 
00096   void add6DofControl( visualization_msgs::InteractiveMarker &msg, bool fixed)
00097 {
00098   visualization_msgs::InteractiveMarkerControl control;
00099 
00100   if(fixed)
00101     control.orientation_mode = visualization_msgs::InteractiveMarkerControl::FIXED;
00102 
00103   control.orientation.w = 1;
00104   control.orientation.x = 1;
00105   control.orientation.y = 0;
00106   control.orientation.z = 0;
00107   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00108   msg.controls.push_back(control);
00109   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
00110   msg.controls.push_back(control);
00111 
00112   control.orientation.w = 1;
00113   control.orientation.x = 0;
00114   control.orientation.y = 1;
00115   control.orientation.z = 0;
00116   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00117   msg.controls.push_back(control);
00118   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
00119   msg.controls.push_back(control);
00120 
00121   control.orientation.w = 1;
00122   control.orientation.x = 0;
00123   control.orientation.y = 0;
00124   control.orientation.z = 1;
00125   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00126   msg.controls.push_back(control);
00127   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
00128   msg.controls.push_back(control);
00129 }
00130 
00131   void addVisible6DofControl( visualization_msgs::InteractiveMarker &msg, bool fixed, bool visible)
00132   {
00133   visualization_msgs::InteractiveMarkerControl control;
00134   
00135   if(visible)
00136     control.always_visible = true;
00137 
00138   if(fixed)
00139     control.orientation_mode = visualization_msgs::InteractiveMarkerControl::FIXED;
00140 
00141   control.orientation.w = 1;
00142   control.orientation.x = 1;
00143   control.orientation.y = 0;
00144   control.orientation.z = 0;
00145   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00146   msg.controls.push_back(control);
00147   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
00148   msg.controls.push_back(control);
00149 
00150   control.orientation.w = 1;
00151   control.orientation.x = 0;
00152   control.orientation.y = 1;
00153   control.orientation.z = 0;
00154   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00155   msg.controls.push_back(control);
00156   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
00157   msg.controls.push_back(control);
00158 
00159   control.orientation.w = 1;
00160   control.orientation.x = 0;
00161   control.orientation.y = 0;
00162   control.orientation.z = 1;
00163   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00164   msg.controls.push_back(control);
00165   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
00166   msg.controls.push_back(control);
00167 }
00168 
00169 
00170 visualization_msgs::InteractiveMarkerControl& makeBoxControl( visualization_msgs::InteractiveMarker &msg )
00171 {
00172   visualization_msgs::InteractiveMarkerControl control;
00173   control.always_visible = true;
00174   control.markers.push_back( makeBox(msg.scale) );
00175   msg.controls.push_back( control );
00176 
00177   return msg.controls.back();
00178 }
00179 
00180 visualization_msgs::InteractiveMarkerControl& makeSphereControl( visualization_msgs::InteractiveMarker &msg )
00181 {
00182   visualization_msgs::InteractiveMarkerControl control;
00183   control.always_visible = true;
00184   control.markers.push_back( makeSphere(msg.scale) );
00185   msg.controls.push_back( control );
00186 
00187   return msg.controls.back();
00188 }
00189 
00190 visualization_msgs::MenuEntry makeMenuEntry(const char *title)
00191 {
00192   visualization_msgs::MenuEntry m;
00193   m.title = title;
00194   m.command = title;
00195   return m;
00196 }
00197 
00198 visualization_msgs::MenuEntry makeMenuEntry(const char *title, const char *command, int type  )
00199 {
00200   visualization_msgs::MenuEntry m;
00201   m.title = title;
00202   m.command = command;
00203   m.command_type = type;
00204   return m;
00205 }
00206 
00207 visualization_msgs::InteractiveMarker makePostureMarker( const char *name, const geometry_msgs::PoseStamped &stamped,
00208                                                          float scale, bool fixed, bool view_facing )
00209 {
00210   visualization_msgs::InteractiveMarker int_marker;
00211   int_marker.header =  stamped.header;
00212   int_marker.name = name;
00213   int_marker.scale = scale;
00214   int_marker.pose = stamped.pose;
00215 
00216   visualization_msgs::InteractiveMarkerControl control;
00217   control.orientation.w = 1;
00218   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00219   int_marker.controls.push_back(control);
00220 
00221   return int_marker;
00222 }
00223 
00224 visualization_msgs::InteractiveMarker makeHeadGoalMarker( const char *name, const geometry_msgs::PoseStamped &stamped,
00225                                                           float scale)
00226 {
00227   visualization_msgs::InteractiveMarker int_marker;
00228   int_marker.header =  stamped.header;
00229   int_marker.name = name;
00230   int_marker.scale = scale;
00231   int_marker.pose = stamped.pose;
00232 
00233   visualization_msgs::InteractiveMarkerControl control;
00234   control.orientation_mode = visualization_msgs::InteractiveMarkerControl::VIEW_FACING;
00235   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_PLANE;
00236   control.orientation.w = 1;
00237   control.markers.push_back( makeSphere(scale*0.7) );
00238   int_marker.controls.push_back(control);
00239   control.markers.clear();
00240 
00241   add6DofControl(int_marker);
00242 
00243   return int_marker;
00244 }
00245 
00246 visualization_msgs::InteractiveMarker makeMeshMarker( const std::string &name, const std::string &mesh_resource,
00247                                                       const geometry_msgs::PoseStamped &stamped, float scale, const std_msgs::ColorRGBA &color, bool use_color )
00248 {
00249   visualization_msgs::InteractiveMarker int_marker;
00250   int_marker.header =  stamped.header;
00251   int_marker.pose = stamped.pose;
00252   int_marker.name = name;
00253   int_marker.scale = scale;
00254 
00255   visualization_msgs::Marker mesh;
00256   if (use_color) mesh.color = color;
00257   mesh.mesh_resource = mesh_resource;
00258   mesh.mesh_use_embedded_materials = !use_color;
00259   mesh.type = visualization_msgs::Marker::MESH_RESOURCE;
00260   mesh.scale.x = scale;
00261   mesh.scale.y = scale;
00262   mesh.scale.z = scale;
00263 
00264   visualization_msgs::InteractiveMarkerControl control;
00265   control.markers.push_back( mesh );
00266   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00267   int_marker.controls.push_back( control );
00268 
00269   return int_marker;
00270 }
00271 
00272 visualization_msgs::InteractiveMarker makeMeshMarker( const std::string &name, const std::string &mesh_resource,
00273                                                       const geometry_msgs::PoseStamped &stamped, float scale)
00274 {
00275   std_msgs::ColorRGBA color;
00276   return makeMeshMarker( name, mesh_resource, stamped, scale, color, false);
00277 }
00278 
00279 visualization_msgs::InteractiveMarker makeMeshMarker( const std::string &name, const std::string &mesh_resource,
00280                                                       const geometry_msgs::PoseStamped &stamped, float scale, const std_msgs::ColorRGBA &color)
00281 {
00282   return makeMeshMarker( name, mesh_resource, stamped, scale, color, true);
00283 }
00284 
00285 visualization_msgs::InteractiveMarker makeButtonBox( const char *name, const geometry_msgs::PoseStamped &stamped, float scale, bool fixed, bool view_facing )
00286 {
00287   visualization_msgs::InteractiveMarker int_marker;
00288   int_marker.header =  stamped.header;
00289   int_marker.name = name;
00290   int_marker.scale = scale;
00291   int_marker.pose = stamped.pose;
00292   //int_marker.description = "This is the marker.";
00293 
00294   visualization_msgs::InteractiveMarkerControl &control = makeBoxControl(int_marker);
00295   //control.description = "This is the control";
00296   control.always_visible = false;
00297   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00298 
00299   return int_marker;
00300 }
00301 
00302 visualization_msgs::InteractiveMarker makeButtonSphere( const char *name, const geometry_msgs::PoseStamped &stamped,
00303                                                         float scale, bool fixed, bool view_facing)
00304 {
00305   std_msgs::ColorRGBA color;
00306   return makeButtonSphere(name, stamped, scale, fixed, view_facing, color);
00307 }
00308 
00309 visualization_msgs::InteractiveMarker makeButtonSphere( const char *name, const geometry_msgs::PoseStamped &stamped,
00310                                                         float scale, bool fixed, bool view_facing,
00311                                                         std_msgs::ColorRGBA color)
00312 {
00313   visualization_msgs::InteractiveMarker int_marker;
00314   int_marker.header =  stamped.header;
00315   int_marker.name = name;
00316   int_marker.scale = scale;
00317   int_marker.pose = stamped.pose;
00318   //int_marker.description = "This is the marker.";
00319 
00320   visualization_msgs::InteractiveMarkerControl &control = makeSphereControl(int_marker);
00321   //control.description = "This is the control";
00322   control.always_visible = false;
00323   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00324   control.markers.back().color = color;
00325 
00326   return int_marker;
00327 }
00328 
00329 visualization_msgs::InteractiveMarker makeListControl( const char *name, const geometry_msgs::PoseStamped &stamped, int num, int total, float scale)
00330 {
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   visualization_msgs::InteractiveMarkerControl control;
00339 
00340 //  control.orientation_mode = visualization_msgs::InteractiveMarkerControl::VIEW_FACING;
00341   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00342   std::stringstream ss;
00343   ss << "pose(" << num << "/" << total << ")";
00344   interactive_markers::makeViewFacingButton(int_marker, control, ss.str());
00345 
00346 //  control.orientation.w = 1;
00347 //  control.orientation.x = 0;
00348 //  control.orientation.y = -1;
00349 //  control.orientation.z = 0;
00350 
00351 //  interactive_markers::makeArrow( int_marker, control, 0.3*scale );
00352 //  control.markers.back().color.r = 1.0;
00353 //  control.markers.back().color.g = 0.0;
00354 //  control.markers.back().color.b = 0.0;
00355 //  control.name = "right";
00356 //  int_marker.controls.push_back(control);
00357 //
00358 //  control.markers.clear();
00359 //  interactive_markers::makeArrow( int_marker, control, -0.3*scale );
00360 //  control.markers.back().color.r = 0.0;
00361 //  control.markers.back().color.g = 1.0;
00362 //  control.markers.back().color.b = 0.0;
00363 //  control.name = "left";
00364   int_marker.controls.push_back(control);
00365 
00366   return int_marker;
00367 
00368 
00369 //  visualization_msgs::InteractiveMarker int_marker;
00370 //  int_marker.header =  stamped.header;
00371 //  int_marker.name = name;
00372 //  int_marker.scale = scale;
00373 //  int_marker.pose = stamped.pose;
00374 //  //int_marker.description = "This is the marker.";
00375 //
00376 //  visualization_msgs::InteractiveMarkerControl &control = makeSphereControl(int_marker);
00377 //  //control.description = "This is the control";
00378 //  control.always_visible = false;
00379 //  control.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00380 //
00381 //  return int_marker;
00382 }
00383 
00384 visualization_msgs::InteractiveMarker make6DofMarker( const char *name, const geometry_msgs::PoseStamped &stamped, float scale, bool fixed, bool view_facing )
00385 {
00386   visualization_msgs::InteractiveMarker int_marker;
00387   int_marker.header =  stamped.header;
00388   int_marker.name = name;
00389   int_marker.scale = scale;
00390   int_marker.pose = stamped.pose;
00391 
00392   if ( view_facing )
00393   {
00394     visualization_msgs::InteractiveMarkerControl control;
00395     control.orientation_mode = visualization_msgs::InteractiveMarkerControl::VIEW_FACING;
00396     //control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_ROTATE;
00397     control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00398     control.orientation.w = 1;
00399     int_marker.controls.push_back(control);
00400 
00401     control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_PLANE;
00402     control.markers.push_back( makeSphere(scale*0.5) );
00403     int_marker.controls.push_back(control);
00404   }
00405   else
00406   {
00407     add6DofControl(int_marker, fixed);
00408   }
00409 
00410   return int_marker;
00411 }
00412 
00413 visualization_msgs::InteractiveMarker makePlanarMarker( const char *name, const geometry_msgs::PoseStamped &stamped, float scale, bool fixed )
00414 {
00415   visualization_msgs::InteractiveMarker int_marker;
00416   int_marker.header =  stamped.header;
00417   int_marker.name = name;
00418   int_marker.scale = scale;
00419   int_marker.pose = stamped.pose;
00420 
00421   visualization_msgs::InteractiveMarkerControl control;
00422   control.orientation_mode = fixed ? (uint8_t)visualization_msgs::InteractiveMarkerControl::FIXED : (uint8_t)visualization_msgs::InteractiveMarkerControl::INHERIT;
00423   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_ROTATE;
00424   control.orientation.w = 1;
00425   control.orientation.x = 0;
00426   control.orientation.y = 1;
00427   control.orientation.z = 0;
00428   int_marker.controls.push_back(control);
00429 
00430   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_PLANE;
00431   interactive_markers::makeArrow( int_marker, control, 0 );
00432   control.markers.back().pose.orientation.w = 0;
00433   control.markers.back().pose.orientation.x = 0;
00434   control.markers.back().pose.orientation.y = 1;
00435   control.markers.back().pose.orientation.z = 0;
00436   control.markers.back().color.r = 0.0;
00437   control.markers.back().color.g = 1.0;
00438   control.markers.back().color.b = 0.0;
00439   int_marker.controls.push_back(control);
00440 
00441   return int_marker;
00442 }
00443 
00444 visualization_msgs::InteractiveMarker makeElevatorMarker( const char *name, const geometry_msgs::PoseStamped &stamped, float scale, bool fixed)
00445 {
00446   visualization_msgs::InteractiveMarker int_marker;
00447   int_marker.header =  stamped.header;
00448   int_marker.name = name;
00449   int_marker.scale = scale;
00450   int_marker.pose = stamped.pose;
00451 
00452   visualization_msgs::InteractiveMarkerControl control;
00453 
00454   if(fixed)
00455     control.orientation_mode = visualization_msgs::InteractiveMarkerControl::FIXED;
00456 
00457   control.orientation.w = 1;
00458   control.orientation.x = 0;
00459   control.orientation.y = -1;
00460   control.orientation.z = 0;
00461   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00462 
00463   interactive_markers::makeArrow( int_marker, control, 0.3 );
00464   control.markers.back().color.r = 0.0;
00465   control.markers.back().color.g = 1.0;
00466   control.markers.back().color.b = 0.0;
00467   control.name = "up";
00468   int_marker.controls.push_back(control);
00469 
00470   control.markers.clear();
00471   interactive_markers::makeArrow( int_marker, control, -0.3 );
00472   control.markers.back().color.r = 1.0;
00473   control.markers.back().color.g = 0.0;
00474   control.markers.back().color.b = 0.0;
00475   control.name = "down";
00476   int_marker.controls.push_back(control);
00477 
00478   return int_marker;
00479 }
00480 
00481 visualization_msgs::InteractiveMarker makeProjectorMarker( const char *name, const geometry_msgs::PoseStamped &stamped, float scale)
00482 {
00483   visualization_msgs::InteractiveMarker int_marker;
00484   int_marker.header =  stamped.header;
00485   int_marker.name = name;
00486   int_marker.scale = scale;
00487   int_marker.pose = stamped.pose;
00488 
00489   visualization_msgs::InteractiveMarkerControl control;
00490   control.orientation.w = 1;
00491   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00492   visualization_msgs::Marker marker;
00493   marker.type = visualization_msgs::Marker::CYLINDER;
00494   marker.scale.x = 0.03;
00495   marker.scale.y = 0.03;
00496   marker.scale.z = 0.04;
00497   marker.color.r = 1.0;
00498   marker.color.a = 0.8;
00499   control.markers.push_back(marker);
00500   int_marker.controls.push_back(control);
00501 
00502   return int_marker;
00503 }
00504 
00505 
00506 visualization_msgs::InteractiveMarker makeBaseMarker( const char *name, const geometry_msgs::PoseStamped &stamped, float scale, bool fixed)
00507 {
00508   visualization_msgs::InteractiveMarker int_marker;
00509   int_marker.header =  stamped.header;
00510   int_marker.name = name;
00511   int_marker.scale = scale;
00512   int_marker.pose = stamped.pose;
00513 
00514   visualization_msgs::InteractiveMarkerControl control;
00515 
00516   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00517   control.orientation.w = 1;
00518   control.orientation.y = -1;
00519   int_marker.controls.push_back(control);
00520 
00521 
00522   if(fixed)
00523     control.orientation_mode = visualization_msgs::InteractiveMarkerControl::FIXED;
00524 
00525   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00526   control.orientation.w = 1;
00527   control.orientation.y = 0;
00528 
00529   control.markers.clear();
00530   interactive_markers::makeArrow( int_marker, control, 0.9 );
00531   control.markers.back().color.r = 1.0;
00532   control.markers.back().color.g = 0.0;
00533   control.markers.back().color.b = 0.0;
00534   control.name = "forward";
00535   int_marker.controls.push_back(control);
00536 
00537   control.markers.clear();
00538   interactive_markers::makeArrow( int_marker, control, -0.9 );
00539   control.markers.back().color.r = 1.0;
00540   control.markers.back().color.g = 0.0;
00541   control.markers.back().color.b = 0.0;
00542   control.name = "back";
00543   int_marker.controls.push_back(control);
00544 
00545   control.orientation.z = 1;
00546   control.markers.clear();
00547   interactive_markers::makeArrow( int_marker, control, 0.9 );
00548   control.markers.back().color.r = 1.0;
00549   control.markers.back().color.g = 0.0;
00550   control.markers.back().color.b = 0.0;
00551   control.name = "left";
00552   int_marker.controls.push_back(control);
00553 
00554   control.markers.clear();
00555   interactive_markers::makeArrow( int_marker, control, -0.9 );
00556   control.markers.back().color.r = 1.0;
00557   control.markers.back().color.g = 0.0;
00558   control.markers.back().color.b = 0.0;
00559   control.name = "right";
00560   int_marker.controls.push_back(control);
00561 
00562   control.markers.clear();
00563   tf::quaternionTFToMsg( tf::Quaternion(tf::Vector3(0,0,1), 135*M_PI/180.0), control.orientation);
00564   interactive_markers::makeArrow( int_marker, control, 1.0 );
00565   control.markers.back().pose.position.x = 0.7;
00566   control.markers.back().color.r = 1.0;
00567   control.markers.back().color.g = 1.0;
00568   control.markers.back().color.b = 0.0;
00569   control.name = "rotate left";
00570   int_marker.controls.push_back(control);
00571 
00572   control.markers.clear();
00573   tf::quaternionTFToMsg( tf::Quaternion(tf::Vector3(0,0,1), -135*M_PI/180.0), control.orientation);
00574   interactive_markers::makeArrow( int_marker, control, 1.0 );
00575   control.markers.back().pose.position.x = 0.7;
00576   control.markers.back().color.r = 1.0;
00577   control.markers.back().color.g = 1.0;
00578   control.markers.back().color.b = 0.0;
00579   control.name = "rotate right";
00580   int_marker.controls.push_back(control);
00581   return int_marker;
00582 }
00583 
00584 visualization_msgs::InteractiveMarker makeGripperMarker( const char *name, const geometry_msgs::PoseStamped &stamped,
00585                                                          float scale, float angle, bool view_facing)
00586 {
00587   std_msgs::ColorRGBA color;
00588   return makeGripperMarker( name, stamped, scale, angle, view_facing, color, false);
00589 }
00590 
00591 visualization_msgs::InteractiveMarker makeGripperMarker( const char *name, const geometry_msgs::PoseStamped &stamped,
00592                                                          float scale, float angle, bool view_facing, std_msgs::ColorRGBA color )
00593 {
00594   return makeGripperMarker( name, stamped, scale, angle, view_facing, color, true);
00595 }
00596 
00597 
00598 visualization_msgs::InteractiveMarker makeGripperMarker( const char *name, const geometry_msgs::PoseStamped &stamped,
00599                                                          float scale, float angle, bool view_facing, std_msgs::ColorRGBA color, bool use_color )
00600 {
00601   visualization_msgs::InteractiveMarker int_marker;
00602   int_marker.header =  stamped.header;
00603   int_marker.name = name;
00604   int_marker.scale = 1.0; //scale;
00605   int_marker.pose = stamped.pose;
00606 
00607 //  add6DofControl(int_marker, false);
00608 
00609   visualization_msgs::InteractiveMarkerControl control;
00610 
00611   visualization_msgs::Marker mesh;
00612   mesh.mesh_use_embedded_materials = !use_color;
00613   mesh.type = visualization_msgs::Marker::MESH_RESOURCE;
00614   mesh.scale.x = scale;
00615   mesh.scale.y = scale;
00616   mesh.scale.z = scale;
00617   mesh.color = color;
00618 
00619   tf::Transform T1, T2;
00620   tf::Transform T_proximal, T_distal;
00621 
00622   T1.setOrigin(tf::Vector3(0.07691, 0.01, 0));
00623   T1.setRotation(tf::Quaternion(tf::Vector3(0,0,1),  angle));
00624   T2.setOrigin(tf::Vector3(0.09137, 0.00495, 0));
00625   T2.setRotation(tf::Quaternion(tf::Vector3(0,0,1), -angle));
00626   T_proximal = T1;
00627   T_distal = T1 * T2;
00628 
00629   mesh.mesh_resource = "package://pr2_description/meshes/gripper_v0/gripper_palm.dae";
00630   mesh.pose.orientation.w = 1;
00631   control.markers.push_back( mesh );
00632   mesh.mesh_resource = "package://pr2_description/meshes/gripper_v0/l_finger.dae";
00633   mesh.pose = createPoseMsg(T_proximal);
00634   control.markers.push_back( mesh );
00635   mesh.mesh_resource = "package://pr2_description/meshes/gripper_v0/l_finger_tip.dae";
00636   mesh.pose = createPoseMsg(T_distal);
00637   control.markers.push_back( mesh );
00638 
00639   T1.setOrigin(tf::Vector3(0.07691, -0.01, 0));
00640   T1.setRotation(tf::Quaternion(tf::Vector3(1,0,0), M_PI)*tf::Quaternion(tf::Vector3(0,0,1),  angle));
00641   T2.setOrigin(tf::Vector3(0.09137, 0.00495, 0));
00642   T2.setRotation(tf::Quaternion(tf::Vector3(0,0,1), -angle));
00643   T_proximal = T1;
00644   T_distal = T1 * T2;
00645 
00646   mesh.mesh_resource = "package://pr2_description/meshes/gripper_v0/l_finger.dae";
00647   mesh.pose = createPoseMsg(T_proximal);
00648   control.markers.push_back( mesh );
00649   mesh.mesh_resource = "package://pr2_description/meshes/gripper_v0/l_finger_tip.dae";
00650   mesh.pose = createPoseMsg(T_distal);
00651   control.markers.push_back( mesh );
00652 
00653   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00654   control.always_visible = true;
00655   int_marker.controls.push_back( control );
00656 
00657   return int_marker;
00658 }
00659 
00660 
00661 visualization_msgs::InteractiveMarker makeGraspMarker( const char * name, const geometry_msgs::PoseStamped &stamped, float scale, PoseState pose_state)
00662 {
00663   visualization_msgs::InteractiveMarker int_marker;
00664   int_marker.header =  stamped.header;
00665   int_marker.header.stamp = ros::Time(0);
00666   int_marker.name = name;
00667   int_marker.scale = scale;
00668   int_marker.pose = stamped.pose;
00669 
00670   visualization_msgs::InteractiveMarkerControl control;
00671   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00672   control.orientation.w = 1;
00673   visualization_msgs::Marker marker;
00674   marker.type = visualization_msgs::Marker::ARROW;
00675   //marker.header = int_marker.header;
00676   //marker.pose = int_marker.pose;
00677   marker.scale.x = 0.025*scale;
00678   marker.scale.y = 0.0025*scale;
00679   marker.scale.z = 0.0025*scale;
00680   marker.color.r = 1.0;
00681   marker.color.a = 1.0;
00682   control.markers.push_back(marker);
00683   marker.type = visualization_msgs::Marker::CUBE;
00684   marker.scale.x = 0.015*scale;
00685   marker.scale.y = 0.04*scale;
00686   marker.scale.z = 0.015*scale;
00687   switch (pose_state)
00688   {
00689   case UNTESTED:
00690     marker.color.g = 0.5;
00691     marker.color.b = 0.5;
00692     marker.color.r = 0.5;
00693     break;
00694   case VALID:
00695     marker.color.g = 1.0;
00696     marker.color.r = 0.0;
00697     break;
00698   case INVALID:
00699     marker.color.g = 0.0;
00700     marker.color.r = 1.0;
00701     break;
00702   }
00703   control.markers.push_back(marker);
00704 //  marker.points[0] = object_manipulator::msg::createPointMsg(0,0,0);
00705 //  marker.points[1] = object_manipulator::msg::createPointMsg(0,0.03,0);
00706 //  marker.color.r = 0;
00707 //  marker.color.g = 1.0;
00708 //  control.markers.push_back(marker);
00709 
00710   int_marker.controls.push_back(control);
00711 
00712   return int_marker;
00713 }
00714 
00715 
00716 visualization_msgs::InteractiveMarker makePosedMultiMeshMarker( const char * name, const geometry_msgs::PoseStamped &stamped,
00717                                                                 const std::vector< geometry_msgs::PoseStamped> &mesh_poses,
00718                                                                 const std::vector<std::string> &mesh_paths, const float &scale,
00719                                                                 const bool button_only)
00720 {
00721     //ROS_ERROR("Start create robot marker...");
00722     visualization_msgs::InteractiveMarker int_marker;
00723     int_marker.header =  stamped.header;
00724     int_marker.name = name;
00725     int_marker.scale = scale;
00726     int_marker.pose = stamped.pose;
00727 
00728     bool fixed = false;
00729     visualization_msgs::InteractiveMarkerControl control;
00730     if( !button_only )
00731     {
00732         control.orientation_mode = fixed ? (uint8_t)visualization_msgs::InteractiveMarkerControl::FIXED : (uint8_t)visualization_msgs::InteractiveMarkerControl::INHERIT;
00733         control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00734         control.orientation.w = 1;
00735         control.orientation.x = 0;
00736         control.orientation.y = 1;
00737         control.orientation.z = 0;
00738         int_marker.controls.push_back(control);
00739     }
00740 
00741     control.markers.clear();
00742     if (button_only) {
00743       control.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00744     }
00745     else {
00746       control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_PLANE;
00747     }
00748     control.always_visible = true;
00749     for(size_t i = 0; i < mesh_poses.size(); i++)
00750     {
00751         visualization_msgs::Marker mesh;
00752         mesh.color = std_msgs::ColorRGBA();
00753         mesh.mesh_resource = mesh_paths[i];
00754         mesh.mesh_use_embedded_materials = true;
00755         mesh.type = visualization_msgs::Marker::MESH_RESOURCE;
00756         mesh.scale.x = mesh.scale.y = mesh.scale.z = scale;
00757         mesh.pose = mesh_poses[i].pose;
00758         control.markers.push_back( mesh );
00759     }
00760     int_marker.controls.push_back( control );
00761 
00762     return int_marker;
00763 
00764 }
00765 
00766 visualization_msgs::InteractiveMarker makeFollowerMultiMeshMarker( const char * name, const geometry_msgs::PoseStamped &stamped,
00767                                                                    const std::vector<std::string> &mesh_frames,
00768                                                                    const std::vector<std::string> &mesh_paths,
00769                                                                    const float &scale)
00770 {
00771     visualization_msgs::InteractiveMarker int_marker;
00772     int_marker.header =  stamped.header;
00773     int_marker.name = name;
00774     int_marker.scale = scale;
00775     int_marker.pose = stamped.pose;
00776 
00777     if(mesh_frames.size() != mesh_paths.size())
00778     {
00779       ROS_ERROR("The number of mesh frames and mesh paths is not equal!");
00780       return int_marker;
00781     }
00782 
00783     visualization_msgs::InteractiveMarkerControl control;
00784 
00785     control.markers.clear();
00786     control.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00787     control.always_visible = true;
00788     for(size_t i = 0; i < mesh_frames.size(); i++)
00789     {
00790         visualization_msgs::Marker mesh;
00791         mesh.color = std_msgs::ColorRGBA();
00792         mesh.mesh_resource = mesh_paths[i];
00793         mesh.mesh_use_embedded_materials = true;
00794         mesh.type = visualization_msgs::Marker::MESH_RESOURCE;
00795         mesh.scale.x = mesh.scale.y = mesh.scale.z = scale;
00796         mesh.pose.orientation.w = 1;
00797         mesh.header.frame_id = mesh_frames[i];
00798         control.markers.push_back( mesh );
00799         mesh.frame_locked = true;
00800     }
00801     int_marker.controls.push_back( control );
00802 
00803     return int_marker;
00804 }
00805 
00806 } // namespace im_helpers


jsk_interactive_marker
Author(s): furuta
autogenerated on Sun Sep 13 2015 22:29:27