urdf_model_marker.h
Go to the documentation of this file.
00001 #ifndef _URDF_MODEL_MARKER_H_
00002 #define _URDF_MODEL_MARKER_H_
00003 
00004 
00005 #include <ros/ros.h>
00006 
00007 #include <tf/tf.h>
00008 #include <tf/transform_listener.h>
00009 #include <tf/transform_broadcaster.h>
00010 
00011 #include <interactive_markers/interactive_marker_server.h>
00012 
00013 #include <interactive_markers/menu_handler.h>
00014 #include <jsk_interactive_marker/SetPose.h>
00015 #include <jsk_interactive_marker/MarkerSetPose.h>
00016 
00017 #include <math.h>
00018 #include <jsk_interactive_marker/MarkerMenu.h>
00019 #include <jsk_interactive_marker/MarkerPose.h>
00020 #include <jsk_interactive_marker/MoveObject.h>
00021 #include <jsk_interactive_marker/MoveModel.h>
00022 
00023 #include <std_msgs/Int8.h>
00024 #include <std_msgs/String.h>
00025 #include <std_srvs/Empty.h>
00026 #include <sensor_msgs/JointState.h>
00027 
00028 #include "urdf_parser/urdf_parser.h"
00029 #include <iostream>
00030 #include <fstream>
00031 
00032 #include <diagnostic_updater/diagnostic_updater.h>
00033 #include <diagnostic_updater/publisher.h>
00034 
00035 #include <jsk_recognition_msgs/Int32Stamped.h>
00036 
00037 #include <jsk_topic_tools/time_accumulator.h>
00038 
00039 #if ROS_VERSION_MINIMUM(1,12,0) // kinetic
00040 #include <urdf_model/types.h>
00041 #include <urdf_world/types.h>
00042 #else
00043 namespace urdf {
00044 typedef boost::shared_ptr<ModelInterface> ModelInterfaceSharedPtr;
00045 typedef boost::shared_ptr<const Link> LinkConstSharedPtr;
00046 typedef boost::shared_ptr<Joint> JointSharedPtr;
00047 }
00048 #endif
00049 
00050 using namespace urdf;
00051 using namespace std;
00052 
00053 
00054 class UrdfModelMarker {
00055  public:
00056   //  UrdfModelMarker(string file);
00057   UrdfModelMarker(string file, std::shared_ptr<interactive_markers::InteractiveMarkerServer> server);
00058   UrdfModelMarker(string model_name, string model_description, string model_file, string frame_id, geometry_msgs::PoseStamped  root_pose, geometry_msgs::Pose root_offset, double scale_factor, string mode, bool robot_mode, bool registration, vector<string> fixed_link, bool use_robot_description, bool use_visible_color, map<string, double> initial_pose_map, int index, std::shared_ptr<interactive_markers::InteractiveMarkerServer> server);
00059   UrdfModelMarker();
00060 
00061   void addMoveMarkerControl(visualization_msgs::InteractiveMarker &int_marker, LinkConstSharedPtr link, bool root);
00062   void addInvisibleMeshMarkerControl(visualization_msgs::InteractiveMarker &int_marker, LinkConstSharedPtr link, const std_msgs::ColorRGBA &color);
00063   void addGraspPointControl(visualization_msgs::InteractiveMarker &int_marker, std::string link_frame_name_);
00064 
00065   void publishBasePose( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00066   void publishBasePose( geometry_msgs::Pose pose, std_msgs::Header header);
00067   void publishMarkerPose ( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback);
00068   void publishMarkerPose ( geometry_msgs::Pose pose, std_msgs::Header header, std::string marker_name);
00069   void publishMarkerMenu( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback, int menu );
00070   void publishMoveObject( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00071   void publishJointState( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00072   void republishJointState( sensor_msgs::JointState js);
00073 
00074   void proc_feedback( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback, string parent_frame_id, string frame_id);
00075 
00076   void graspPoint_feedback( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback, string link_name);
00077   void moveCB( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00078   void setPoseCB();
00079   void setPoseCB( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00080   void hideMarkerCB( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00081   void hideAllMarkerCB( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00082 
00083   void hideModelMarkerCB( const std_msgs::EmptyConstPtr &msg);
00084   void showModelMarkerCB( const std_msgs::EmptyConstPtr &msg);
00085   void setUrdfCB( const std_msgs::StringConstPtr &msg);
00086 
00087   visualization_msgs::InteractiveMarkerControl makeMeshMarkerControl(const std::string &mesh_resource, const geometry_msgs::PoseStamped &stamped, geometry_msgs::Vector3 scale, const std_msgs::ColorRGBA &color, bool use_color);
00088   visualization_msgs::InteractiveMarkerControl makeMeshMarkerControl(const std::string &mesh_resource, const geometry_msgs::PoseStamped &stamped, geometry_msgs::Vector3 scale);
00089   visualization_msgs::InteractiveMarkerControl makeMeshMarkerControl(const std::string &mesh_resource, const geometry_msgs::PoseStamped &stamped, geometry_msgs::Vector3 scale, const std_msgs::ColorRGBA &color);
00090 
00091 
00092 
00093   visualization_msgs::InteractiveMarkerControl makeCylinderMarkerControl(const geometry_msgs::PoseStamped &stamped, double length, double radius, const std_msgs::ColorRGBA &color, bool use_color);
00094   visualization_msgs::InteractiveMarkerControl makeBoxMarkerControl(const geometry_msgs::PoseStamped &stamped, Vector3 dim, const std_msgs::ColorRGBA &color, bool use_color);
00095   visualization_msgs::InteractiveMarkerControl makeSphereMarkerControl(const geometry_msgs::PoseStamped &stamped, double rad, const std_msgs::ColorRGBA &color, bool use_color);
00096   //joint state methods
00097   void publishJointState();
00098   void getJointState();
00099   void getJointState(LinkConstSharedPtr link);
00100 
00101   void setJointState(LinkConstSharedPtr link, const sensor_msgs::JointStateConstPtr &js);
00102   void setJointAngle(LinkConstSharedPtr link, double joint_angle);
00103   geometry_msgs::Pose getRootPose(geometry_msgs::Pose pose);
00104   geometry_msgs::PoseStamped getOriginPoseStamped();
00105   void setOriginalPose(LinkConstSharedPtr link);
00106   void addChildLinkNames(LinkConstSharedPtr link, bool root, bool init);
00107   void addChildLinkNames(LinkConstSharedPtr link, bool root, bool init, bool use_color, int color_index);
00108 
00109   void callSetDynamicTf(string parent_frame_id, string frame_id, geometry_msgs::Transform transform);
00110   void callPublishTf();
00111 
00112   int main(string file);
00113 
00114   void graspPointCB( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00115   void jointMoveCB( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00116   void resetMarkerCB( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00117   void resetBaseMarkerCB( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00118   void resetBaseMsgCB( const std_msgs::EmptyConstPtr &msg);
00119   void resetBaseCB();
00120 
00121   void resetRobotBase();
00122   void resetRootForVisualization();
00123   void registrationCB( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00124   
00125   void setRootPoseCB( const geometry_msgs::PoseStampedConstPtr &msg );
00126   void setRootPose( geometry_msgs::PoseStamped ps);
00127   void resetJointStatesCB( const sensor_msgs::JointStateConstPtr &msg, bool update_root);
00128   void updateDiagnostic(diagnostic_updater::DiagnosticStatusWrapper &stat);
00129   bool lockJointStates(std_srvs::EmptyRequest& req,
00130                        std_srvs::EmptyRequest& res);
00131   bool unlockJointStates(std_srvs::EmptyRequest& req,
00132                          std_srvs::EmptyRequest& res);
00133 
00134  protected:
00135   ros::NodeHandle nh_;
00136   ros::NodeHandle pnh_;
00137   std::shared_ptr<interactive_markers::InteractiveMarkerServer> server_;
00138   
00139   /* diagnostics */
00140   std::shared_ptr<diagnostic_updater::Updater> diagnostic_updater_;
00141   jsk_topic_tools::TimeAccumulator reset_joint_states_check_time_acc_;
00142   jsk_topic_tools::TimeAccumulator dynamic_tf_check_time_acc_;
00143 
00144   /* publisher */
00145   ros::Publisher pub_;
00146   ros::Publisher pub_move_;
00147   ros::Publisher pub_move_object_;
00148   ros::Publisher pub_move_model_;
00149   ros::Publisher pub_joint_state_;
00150   ros::Publisher pub_base_pose_;
00151   ros::Publisher pub_selected_;
00152   ros::Publisher pub_selected_index_;
00153 
00154   /* subscriber */
00155   ros::Subscriber sub_reset_joints_;
00156   ros::Subscriber sub_reset_joints_and_root_;
00157   ros::Subscriber sub_set_root_pose_;
00158   ros::Subscriber hide_marker_;
00159   ros::Subscriber show_marker_;
00160   ros::Subscriber sub_set_urdf_;
00161 
00162   ros::ServiceServer serv_reset_;
00163   ros::ServiceServer serv_set_;
00164   ros::ServiceServer serv_markers_set_;
00165   ros::ServiceServer serv_markers_del_;
00166   ros::ServiceServer serv_lock_joint_states_;
00167   ros::ServiceServer serv_unlock_joint_states_;
00168   boost::mutex joint_states_mutex_;
00169   bool is_joint_states_locked_;
00170   interactive_markers::MenuHandler model_menu_;
00171 
00172   tf::TransformListener tfl_;
00173   tf::TransformBroadcaster tfb_;
00174 
00175   ros::ServiceClient dynamic_tf_publisher_client;
00176   ros::ServiceClient dynamic_tf_publisher_publish_tf_client;
00177 
00178   std::string server_name;
00179   std::string base_frame;
00180   std::string move_base_frame;
00181   std::string target_frame;
00182 
00183 
00184   ModelInterfaceSharedPtr model;
00185   std::string model_name_;
00186   std::string model_description_;
00187   std::string frame_id_;
00188   std::string model_file_;
00189   geometry_msgs::Pose root_pose_;
00190   geometry_msgs::Pose root_pose_origin_;
00191   geometry_msgs::Pose root_offset_;
00192   geometry_msgs::Pose fixed_link_offset_; //used when fixel_link_ is used
00193   double scale_factor_;
00194   bool robot_mode_;
00195   bool registration_;
00196   bool use_dynamic_tf_;
00197   string mode_;
00198   vector<string> fixed_link_;
00199   bool use_robot_description_;
00200   bool use_visible_color_;
00201   std::string tf_prefix_;
00202   map<string, double> initial_pose_map_;
00203   int index_;
00204   ros::Time init_stamp_;
00205 
00206   //joint states
00207   sensor_msgs::JointState joint_state_;
00208   sensor_msgs::JointState joint_state_origin_;
00209 
00210   struct graspPoint{
00211     graspPoint(){
00212       displayMoveMarker = false;
00213       displayGraspPoint = false;
00214       pose.orientation.x = 0;
00215       pose.orientation.y = 0;
00216       pose.orientation.z = 0;
00217       pose.orientation.w = 1;
00218     }
00219     bool displayGraspPoint;
00220     bool displayMoveMarker;
00221     geometry_msgs::Pose pose;
00222   };
00223 
00224 
00225   struct linkProperty{
00226     linkProperty(){
00227       displayMoveMarker = false;
00228       displayModelMarker = true;
00229       mesh_file = "";
00230     }
00231     bool displayMoveMarker;
00232     bool displayModelMarker;
00233     graspPoint gp;
00234     string frame_id;
00235     string movable_link;
00236     //pose from frame_id
00237     geometry_msgs::Pose pose;
00238     geometry_msgs::Pose origin;
00239     geometry_msgs::Pose initial_pose;
00240     urdf::Vector3 joint_axis;
00241     double joint_angle;
00242     int rotation_count;
00243     string mesh_file;
00244   };
00245 
00246   map<string, linkProperty> linkMarkerMap;
00247 };
00248 
00249 #endif


jsk_interactive_marker
Author(s): furuta
autogenerated on Wed May 1 2019 02:40:31