frame_marker.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2013, 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  * Author: Mario Prats
00030  */
00031 
00032 #ifndef BT_FRAME_MARKER
00033 #define BT_FRAME_MARKER
00034 
00035 #include <rviz/display_context.h>
00036 #include <rviz/default_plugin/interactive_markers/interactive_marker.h>
00037 
00038 #include <moveit/robot_interaction/robot_interaction.h>
00039 #include <moveit/robot_state/robot_state.h>
00040 
00041 #include <QObject>
00042 
00043 #include <string>
00044 
00045 namespace benchmark_tool
00046 {
00047 
00048 class MotionPlanningDisplay;
00049 
00054 class FrameMarker
00055 {
00056 public:
00057   visualization_msgs::InteractiveMarker imarker_msg;
00058   boost::shared_ptr<rviz::InteractiveMarker> imarker;
00059 
00061   FrameMarker(const FrameMarker &frame_marker): receiver_(NULL), receiver_method_(NULL)
00062   {
00063     imarker_msg = frame_marker.imarker_msg;
00064 
00065     visible_x_ = frame_marker.visible_x_;
00066     visible_y_ = frame_marker.visible_y_;
00067     visible_z_ = frame_marker.visible_z_;
00068 
00069     parent_node_ = frame_marker.parent_node_;
00070     context_ = frame_marker.context_;
00071 
00072     selected_ = frame_marker.selected_;
00073     color_ = frame_marker.color_;
00074 
00075     position_ = frame_marker.imarker->getPosition();
00076     orientation_ = frame_marker.imarker->getOrientation();
00077 
00078     rebuild();
00079   }
00080 
00092   FrameMarker(Ogre::SceneNode *parent_node, rviz::DisplayContext *context, const std::string &name,
00093               const std::string &frame_id, const geometry_msgs::Pose &pose, double scale, const std_msgs::ColorRGBA &color,
00094               bool is_selected = false, bool visible_x = true, bool visible_y = true, bool visible_z = true);
00095 
00096   FrameMarker(Ogre::SceneNode *parent_node, rviz::DisplayContext *context, const std::string &name,
00097               const std::string &frame_id, const geometry_msgs::Pose &pose, double scale, const float color[4],
00098               bool is_selected = false, bool visible_x = true, bool visible_y = true, bool visible_z = true);
00099 
00100   virtual void updateMarker(void)
00101   {
00102     imarker->processMessage(imarker_msg);
00103   }
00104 
00105   virtual void hide(void);
00106   virtual void show(Ogre::SceneNode *scene_node, rviz::DisplayContext *context);
00107 
00108   virtual void showDescription(const std::string &description);
00109   virtual void hideDescription();
00110 
00111   virtual void setAxisVisibility(bool x, bool y, bool z)
00112   {
00113     visible_x_ = x;
00114     visible_y_ = y;
00115     visible_z_ = z;
00116     rebuild();
00117   }
00118 
00119   virtual void setColor(float r, float g, float b, float a);
00120 
00121   virtual void getPosition(geometry_msgs::Point &position);
00122   virtual void getOrientation(geometry_msgs::Quaternion &orientation);
00123   virtual void getPose(Eigen::Affine3d &pose);
00124   virtual void setPose(Eigen::Affine3d &pose);
00125 
00126   virtual void select(void);
00127   virtual void unselect(void);
00128 
00129   virtual void setMenu(std::vector<visualization_msgs::MenuEntry> entries)
00130   {
00131     menu_entries_ = entries;
00132     rebuild();
00133   }
00134 
00135   const std::string &getName()
00136   {
00137     return imarker_msg.name;
00138   }
00139 
00140   void setName(const std::string &name)
00141   {
00142     imarker_msg.name = name;
00143   }
00144 
00145   bool isSelected(void)
00146   {
00147     return selected_;
00148   }
00149 
00150   bool isVisible()
00151   {
00152     return (imarker);
00153   }
00154 
00155   void connect(const QObject * receiver, const char * method)
00156   {
00157     receiver_ = receiver;
00158     receiver_method_ = method;
00159     QObject::connect( imarker.get(), SIGNAL( userFeedback(visualization_msgs::InteractiveMarkerFeedback &)), receiver, method );
00160   }
00161 
00162   virtual ~FrameMarker()
00163   {}
00164 
00165 protected:
00166   virtual void buildFrom(const std::string &name, const std::string &frame_id, const geometry_msgs::Pose &pose, double scale, const std_msgs::ColorRGBA &color);
00167   virtual void rebuild();
00168 
00169   std::vector<visualization_msgs::MenuEntry> menu_entries_;
00170 
00171   Ogre::SceneNode *parent_node_;
00172   rviz::DisplayContext* context_;
00173 
00174   bool selected_;
00175   bool visible_x_, visible_y_, visible_z_;
00176   std_msgs::ColorRGBA color_;
00177 
00178   Ogre::Vector3 position_;
00179   Ogre::Quaternion orientation_;
00180 
00181   const QObject *receiver_;
00182   const char *receiver_method_;
00183 };
00184 
00185 
00190 class GripperMarker : public FrameMarker
00191 {
00192 public:
00193   typedef enum
00194   {
00195     NOT_TESTED, PROCESSING, REACHABLE, NOT_REACHABLE, IN_COLLISION
00196   } GripperMarkerState;
00197 
00199   GripperMarker(const GripperMarker &gripper_marker) : FrameMarker(gripper_marker)
00200   {
00201     robot_state_ = gripper_marker.robot_state_;
00202     eef_ = gripper_marker.eef_;
00203     state_ = gripper_marker.state_;
00204     display_gripper_mesh_ = gripper_marker.display_gripper_mesh_;
00205 
00206     rebuild();
00207   }
00208 
00222   GripperMarker(const robot_state::RobotState& robot_state, Ogre::SceneNode *parent_node, rviz::DisplayContext *context, const std::string &name,
00223                 const std::string &frame_id, const robot_interaction::RobotInteraction::EndEffector &eef, const geometry_msgs::Pose &pose, double scale,
00224                 const GripperMarkerState &state, bool is_selected = false, bool visible_x = true, bool visible_y = true, bool visible_z = true);
00225 
00226   virtual void select(bool display_gripper_mesh = true);
00227   virtual void unselect(bool display_gripper_mesh = false);
00228 
00229   virtual void setState(const GripperMarkerState &state)
00230   {
00231     if (state != state_)
00232     {
00233       state_ = state;
00234       const float *color = stateToColor(state);
00235       setColor(color[0], color[1], color[2], color[3]);
00236     }
00237   }
00238 
00239   const GripperMarkerState &getState()
00240   {
00241     return state_;
00242   }
00243 
00244   void setRobotState(const robot_state::RobotState& robot_state)
00245   {
00246     robot_state_ = &robot_state;
00247   }
00248 
00249   const robot_state::RobotState *getRobotState()
00250   {
00251     return robot_state_;
00252   }
00253 
00254   void setEndEffector(const robot_interaction::RobotInteraction::EndEffector &eef)
00255   {
00256     eef_ = eef;
00257   }
00258 
00259   const robot_interaction::RobotInteraction::EndEffector getEndEffector()
00260   {
00261     return eef_;
00262   }
00263 
00264 protected:
00265   static const float GOAL_NOT_TESTED_COLOR[4];
00266   static const float GOAL_PROCESSING_COLOR[4];
00267   static const float GOAL_NOT_REACHABLE_COLOR[4];
00268   static const float GOAL_REACHABLE_COLOR[4];
00269   static const float GOAL_COLLISION_COLOR[4];
00270 
00271   virtual void buildFrom(const std::string &name, const std::string &frame_id, const geometry_msgs::Pose &pose, double scale, const std_msgs::ColorRGBA &color);
00272 
00273   const float *stateToColor(const GripperMarkerState &state);
00274 
00275   const robot_state::RobotState *robot_state_;
00276   robot_interaction::RobotInteraction::EndEffector eef_;
00277 
00278   bool display_gripper_mesh_;
00279   GripperMarkerState state_;
00280 };
00281 
00282 typedef boost::shared_ptr<GripperMarker> GripperMarkerPtr;
00283 
00284 } //namespace
00285 #endif


benchmarks_gui
Author(s): Mario Prats
autogenerated on Mon Oct 6 2014 02:34:25