00001 #ifndef EFFORT_DISPLAY_H 00002 #define EFFORT_DISPLAY_H 00003 00004 #include <message_filters/subscriber.h> 00005 #include <tf/message_filter.h> 00006 #include <sensor_msgs/JointState.h> 00007 #include <rviz/display.h> 00008 00009 namespace Ogre 00010 { 00011 class SceneNode; 00012 } 00013 00014 namespace urdf 00015 { 00016 class Model; 00017 } 00018 00019 namespace tf 00020 { 00021 class MessageFilterJointState; 00022 } 00023 00024 namespace jsk_rviz_plugin 00025 { 00026 00027 struct JointInfo; 00028 typedef std::set<JointInfo*> S_JointInfo; 00029 typedef std::vector<std::string> V_string; 00030 00031 class EfforVisual; 00032 00033 class EffortDisplay: public rviz::Display 00034 { 00035 public: 00036 // Constructor. pluginlib::ClassLoader creates instances by calling 00037 // the default constructor, so make sure you have one. 00038 EffortDisplay(); 00039 virtual ~EffortDisplay(); 00040 00041 // Overrides of public virtual functions from the Display class. 00042 virtual void onInitialize(); 00043 virtual void fixedFrameChanged(); 00044 virtual void reset(); 00045 virtual void createProperties(); 00046 00047 // Setter and getter functions for user-editable properties. 00048 void setTopic(const std::string& topic); 00049 const std::string& getTopic() { return topic_; } 00050 00051 void setAlpha( float alpha ); 00052 float getAlpha() { return alpha_; } 00053 00054 void setWidth( float width ); 00055 float getWidth() { return width_; } 00056 00057 void setScale( float scale ); 00058 float getScale() { return scale_; } 00059 00060 void setHistoryLength( int history_length ); 00061 int getHistoryLength() const { return history_length_; } 00062 00063 void load(); 00064 void setRobotDescription( const std::string& description_param ); 00065 std::string& getRobotDescription() { return description_param_; } 00066 00067 bool getAllEnabled() { return all_enabled_; } 00068 void setAllEnabled(bool enabled); 00069 00070 void setJointEnabled(JointInfo* joint, bool enabled); 00071 00072 00073 // Overrides of protected virtual functions from Display. As much 00074 // as possible, when Displays are not enabled, they should not be 00075 // subscribed to incoming data and should not show anything in the 00076 // 3D view. These functions are where these connections are made 00077 // and broken. 00078 protected: 00079 //void updateJoints(V_string joints); 00080 JointInfo* createJoint(const std::string &joint); 00081 void updateJoint(JointInfo* joint); 00082 void deleteJoint(JointInfo* joint, bool delete_properties); 00083 00084 JointInfo* getJointInfo(const std::string &joint); 00085 00086 virtual void onEnable(); 00087 virtual void onDisable(); 00088 00089 // Function to handle an incoming ROS message. 00090 private: 00091 void incomingMessage( const sensor_msgs::JointState::ConstPtr& msg ); 00092 00093 // Internal helpers which do the work of subscribing and 00094 // unsubscribing from the ROS topic. 00095 void subscribe(); 00096 void unsubscribe(); 00097 00098 // A helper to clear this display back to the initial state. 00099 void clear(); 00100 00101 // Helper function to apply color and alpha to all visuals. 00102 void updateColorAndAlpha(); 00103 00104 // Storage for the list of visuals par each joint intem 00105 typedef std::vector<EffortVisual*> MapEffortVisual; 00106 MapEffortVisual visuals_; 00107 00108 // A node in the Ogre scene tree to be the parent of all our visuals. 00109 Ogre::SceneNode* scene_node_; 00110 00111 // Data input: Subscriber and tf message filter. 00112 message_filters::Subscriber<sensor_msgs::JointState> sub_; 00113 tf::MessageFilterJointState* tf_filter_; 00114 int messages_received_; 00115 00116 typedef std::map<std::string, JointInfo*> M_JointInfo; 00117 M_JointInfo joints_; 00118 00119 // User-editable property variables. 00120 std::string topic_, description_param_; 00121 float alpha_, width_, scale_; 00122 int history_length_; 00123 bool all_enabled_; 00124 00125 // Property objects for user-editable properties. 00126 rviz::ROSTopicStringPropertyWPtr topic_property_; 00127 rviz::FloatPropertyWPtr alpha_property_, width_property_, scale_property_; 00128 rviz::IntPropertyWPtr history_length_property_; 00129 00130 rviz::StringPropertyWPtr robot_description_property_; 00131 rviz::CategoryPropertyWPtr joints_category_; 00132 rviz::BoolPropertyWPtr all_enabled_property_; 00133 00134 // The object for urdf model 00135 boost::shared_ptr<urdf::Model> urdfModel; 00136 }; 00137 } // end namespace rviz_plugin_tutorials 00138 00139 #endif // EFFORT_DISPLAY_H