urdf_model_marker.h
Go to the documentation of this file.
1 #ifndef _URDF_MODEL_MARKER_H_
2 #define _URDF_MODEL_MARKER_H_
3 
4 
5 #include <ros/ros.h>
6 
7 #include <tf/tf.h>
10 
12 
14 #include <jsk_interactive_marker/SetPose.h>
15 #include <jsk_interactive_marker/MarkerSetPose.h>
16 
17 #include <math.h>
18 #include <jsk_interactive_marker/MarkerMenu.h>
19 #include <jsk_interactive_marker/MarkerPose.h>
20 #include <jsk_interactive_marker/MoveObject.h>
21 #include <jsk_interactive_marker/MoveModel.h>
22 
23 #include <std_msgs/Int8.h>
24 #include <std_msgs/String.h>
25 #include <std_srvs/Empty.h>
26 #include <sensor_msgs/JointState.h>
27 
28 #include "urdf_parser/urdf_parser.h"
29 #include <iostream>
30 #include <fstream>
31 
34 
35 #include <jsk_recognition_msgs/Int32Stamped.h>
36 
37 #include <jsk_topic_tools/time_accumulator.h>
38 
39 #if ROS_VERSION_MINIMUM(1,12,0) // kinetic
40 #include <urdf_model/types.h>
41 #include <urdf_world/types.h>
42 #else
43 namespace urdf {
47 }
48 #endif
49 
50 using namespace urdf;
51 using namespace std;
52 
53 
55  public:
56  // UrdfModelMarker(string file);
57  UrdfModelMarker(string file, std::shared_ptr<interactive_markers::InteractiveMarkerServer> server);
58  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);
60 
61  void addMoveMarkerControl(visualization_msgs::InteractiveMarker &int_marker, LinkConstSharedPtr link, bool root);
62  void addInvisibleMeshMarkerControl(visualization_msgs::InteractiveMarker &int_marker, LinkConstSharedPtr link, const std_msgs::ColorRGBA &color);
63  void addGraspPointControl(visualization_msgs::InteractiveMarker &int_marker, std::string link_frame_name_);
64 
65  void publishBasePose( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
66  void publishBasePose( geometry_msgs::Pose pose, std_msgs::Header header);
67  void publishMarkerPose ( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback);
68  void publishMarkerPose ( geometry_msgs::Pose pose, std_msgs::Header header, std::string marker_name);
69  void publishMarkerMenu( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback, int menu );
70  void publishMoveObject( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
71  void publishJointState( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
72  void republishJointState( sensor_msgs::JointState js);
73 
74  void proc_feedback( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback, string parent_frame_id, string frame_id);
75 
76  void graspPoint_feedback( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback, string link_name);
77  void moveCB( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
78  void setPoseCB();
79  void setPoseCB( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
80  void hideMarkerCB( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
81  void hideAllMarkerCB( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
82 
83  void hideModelMarkerCB( const std_msgs::EmptyConstPtr &msg);
84  void showModelMarkerCB( const std_msgs::EmptyConstPtr &msg);
85  void setUrdfCB( const std_msgs::StringConstPtr &msg);
86 
87  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);
88  visualization_msgs::InteractiveMarkerControl makeMeshMarkerControl(const std::string &mesh_resource, const geometry_msgs::PoseStamped &stamped, geometry_msgs::Vector3 scale);
89  visualization_msgs::InteractiveMarkerControl makeMeshMarkerControl(const std::string &mesh_resource, const geometry_msgs::PoseStamped &stamped, geometry_msgs::Vector3 scale, const std_msgs::ColorRGBA &color);
90 
91 
92 
93  visualization_msgs::InteractiveMarkerControl makeCylinderMarkerControl(const geometry_msgs::PoseStamped &stamped, double length, double radius, const std_msgs::ColorRGBA &color, bool use_color);
94  visualization_msgs::InteractiveMarkerControl makeBoxMarkerControl(const geometry_msgs::PoseStamped &stamped, Vector3 dim, const std_msgs::ColorRGBA &color, bool use_color);
95  visualization_msgs::InteractiveMarkerControl makeSphereMarkerControl(const geometry_msgs::PoseStamped &stamped, double rad, const std_msgs::ColorRGBA &color, bool use_color);
96  //joint state methods
97  void publishJointState();
98  void getJointState();
99  void getJointState(LinkConstSharedPtr link);
100 
101  void setJointState(LinkConstSharedPtr link, const sensor_msgs::JointStateConstPtr &js);
102  void setJointAngle(LinkConstSharedPtr link, double joint_angle);
103  geometry_msgs::Pose getRootPose(geometry_msgs::Pose pose);
104  geometry_msgs::PoseStamped getOriginPoseStamped();
105  void setOriginalPose(LinkConstSharedPtr link);
106  void addChildLinkNames(LinkConstSharedPtr link, bool root, bool init);
107  void addChildLinkNames(LinkConstSharedPtr link, bool root, bool init, bool use_color, int color_index);
108 
109  void callSetDynamicTf(string parent_frame_id, string frame_id, geometry_msgs::Transform transform);
110  void callPublishTf();
111 
112  int main(string file);
113 
114  void graspPointCB( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
115  void jointMoveCB( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
116  void resetMarkerCB( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
117  void resetBaseMarkerCB( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
118  void resetBaseMsgCB( const std_msgs::EmptyConstPtr &msg);
119  void resetBaseCB();
120 
121  void resetRobotBase();
122  void resetRootForVisualization();
123  void registrationCB( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
124 
125  void setRootPoseCB( const geometry_msgs::PoseStampedConstPtr &msg );
126  void setRootPose( geometry_msgs::PoseStamped ps);
127  void resetJointStatesCB( const sensor_msgs::JointStateConstPtr &msg, bool update_root);
128  void updateDiagnostic(diagnostic_updater::DiagnosticStatusWrapper &stat);
129  bool lockJointStates(std_srvs::EmptyRequest& req,
130  std_srvs::EmptyRequest& res);
131  bool unlockJointStates(std_srvs::EmptyRequest& req,
132  std_srvs::EmptyRequest& res);
133 
134  protected:
137  std::shared_ptr<interactive_markers::InteractiveMarkerServer> server_;
138 
139  /* diagnostics */
140  std::shared_ptr<diagnostic_updater::Updater> diagnostic_updater_;
141  jsk_topic_tools::TimeAccumulator reset_joint_states_check_time_acc_;
142  jsk_topic_tools::TimeAccumulator dynamic_tf_check_time_acc_;
143 
144  /* publisher */
153 
154  /* subscriber */
161 
171 
174 
177 
178  std::string server_name;
179  std::string base_frame;
180  std::string move_base_frame;
181  std::string target_frame;
182 
183 
185  std::string model_name_;
186  std::string model_description_;
187  std::string frame_id_;
188  std::string model_file_;
189  geometry_msgs::Pose root_pose_;
190  geometry_msgs::Pose root_pose_origin_;
191  geometry_msgs::Pose root_offset_;
192  geometry_msgs::Pose fixed_link_offset_; //used when fixel_link_ is used
197  string mode_;
201  std::string tf_prefix_;
202  map<string, double> initial_pose_map_;
203  int index_;
205 
206  //joint states
207  sensor_msgs::JointState joint_state_;
208  sensor_msgs::JointState joint_state_origin_;
209 
210  struct graspPoint{
212  displayMoveMarker = false;
213  displayGraspPoint = false;
214  pose.orientation.x = 0;
215  pose.orientation.y = 0;
216  pose.orientation.z = 0;
217  pose.orientation.w = 1;
218  }
221  geometry_msgs::Pose pose;
222  };
223 
224 
225  struct linkProperty{
227  displayMoveMarker = false;
228  displayModelMarker = true;
229  mesh_file = "";
230  }
234  string frame_id;
235  string movable_link;
236  //pose from frame_id
237  geometry_msgs::Pose pose;
238  geometry_msgs::Pose origin;
239  geometry_msgs::Pose initial_pose;
240  urdf::Vector3 joint_axis;
241  double joint_angle;
243  string mesh_file;
244  };
245 
246  map<string, linkProperty> linkMarkerMap;
247 };
248 
249 #endif
urdf::JointSharedPtr
boost::shared_ptr< Joint > JointSharedPtr
Definition: urdf_model_marker.h:46
im_utils::makeCylinderMarkerControl
visualization_msgs::InteractiveMarkerControl makeCylinderMarkerControl(const geometry_msgs::PoseStamped &stamped, double length, double radius, const std_msgs::ColorRGBA &color, bool use_color)
Definition: interactive_marker_utils.cpp:55
UrdfModelMarker::fixed_link_
vector< string > fixed_link_
Definition: urdf_model_marker.h:198
UrdfModelMarker::model_file_
std::string model_file_
Definition: urdf_model_marker.h:188
UrdfModelMarker::joint_state_origin_
sensor_msgs::JointState joint_state_origin_
Definition: urdf_model_marker.h:208
msg
msg
ros::Publisher
UrdfModelMarker::hide_marker_
ros::Subscriber hide_marker_
Definition: urdf_model_marker.h:158
UrdfModelMarker::registration_
bool registration_
Definition: urdf_model_marker.h:195
UrdfModelMarker::root_pose_
geometry_msgs::Pose root_pose_
Definition: urdf_model_marker.h:189
UrdfModelMarker::tfl_
tf::TransformListener tfl_
Definition: urdf_model_marker.h:172
UrdfModelMarker::serv_set_
ros::ServiceServer serv_set_
Definition: urdf_model_marker.h:163
UrdfModelMarker::joint_states_mutex_
boost::mutex joint_states_mutex_
Definition: urdf_model_marker.h:168
file
file
scale
scale
boost::shared_ptr< ModelInterface >
UrdfModelMarker::use_robot_description_
bool use_robot_description_
Definition: urdf_model_marker.h:199
UrdfModelMarker::linkProperty::initial_pose
geometry_msgs::Pose initial_pose
Definition: urdf_model_marker.h:239
UrdfModelMarker::fixed_link_offset_
geometry_msgs::Pose fixed_link_offset_
Definition: urdf_model_marker.h:192
UrdfModelMarker::linkProperty::mesh_file
string mesh_file
Definition: urdf_model_marker.h:243
UrdfModelMarker::reset_joint_states_check_time_acc_
jsk_topic_tools::TimeAccumulator reset_joint_states_check_time_acc_
Definition: urdf_model_marker.h:141
ros.h
UrdfModelMarker::pub_move_
ros::Publisher pub_move_
Definition: urdf_model_marker.h:146
mode
mode
UrdfModelMarker::linkProperty::frame_id
string frame_id
Definition: urdf_model_marker.h:234
UrdfModelMarker::pub_base_pose_
ros::Publisher pub_base_pose_
Definition: urdf_model_marker.h:150
UrdfModelMarker::dynamic_tf_publisher_client
ros::ServiceClient dynamic_tf_publisher_client
Definition: urdf_model_marker.h:175
UrdfModelMarker::initial_pose_map_
map< string, double > initial_pose_map_
Definition: urdf_model_marker.h:202
UrdfModelMarker::linkMarkerMap
map< string, linkProperty > linkMarkerMap
Definition: urdf_model_marker.h:246
UrdfModelMarker::linkProperty::pose
geometry_msgs::Pose pose
Definition: urdf_model_marker.h:237
UrdfModelMarker::linkProperty::gp
graspPoint gp
Definition: urdf_model_marker.h:233
UrdfModelMarker::pub_joint_state_
ros::Publisher pub_joint_state_
Definition: urdf_model_marker.h:149
UrdfModelMarker::pub_
ros::Publisher pub_
Definition: urdf_model_marker.h:145
UrdfModelMarker::model_menu_
interactive_markers::MenuHandler model_menu_
Definition: urdf_model_marker.h:170
menu_handler.h
UrdfModelMarker::pnh_
ros::NodeHandle pnh_
Definition: urdf_model_marker.h:136
UrdfModelMarker::model_description_
std::string model_description_
Definition: urdf_model_marker.h:186
im_utils::makeBoxMarkerControl
visualization_msgs::InteractiveMarkerControl makeBoxMarkerControl(const geometry_msgs::PoseStamped &stamped, Vector3 dim, const std_msgs::ColorRGBA &color, bool use_color)
Definition: interactive_marker_utils.cpp:73
im_utils::makeSphereMarkerControl
visualization_msgs::InteractiveMarkerControl makeSphereMarkerControl(const geometry_msgs::PoseStamped &stamped, double rad, const std_msgs::ColorRGBA &color, bool use_color)
Definition: interactive_marker_utils.cpp:92
UrdfModelMarker::root_offset_
geometry_msgs::Pose root_offset_
Definition: urdf_model_marker.h:191
UrdfModelMarker::serv_lock_joint_states_
ros::ServiceServer serv_lock_joint_states_
Definition: urdf_model_marker.h:166
main
int main(int argc, char **argv)
Definition: bounding_box_marker.cpp:124
UrdfModelMarker::model
ModelInterfaceSharedPtr model
Definition: urdf_model_marker.h:184
publisher.h
UrdfModelMarker::nh_
ros::NodeHandle nh_
Definition: urdf_model_marker.h:135
transform_broadcaster.h
diagnostic_updater.h
ros::ServiceServer
pose
pose
UrdfModelMarker::frame_id_
std::string frame_id_
Definition: urdf_model_marker.h:187
UrdfModelMarker::sub_reset_joints_and_root_
ros::Subscriber sub_reset_joints_and_root_
Definition: urdf_model_marker.h:156
UrdfModelMarker::pub_selected_index_
ros::Publisher pub_selected_index_
Definition: urdf_model_marker.h:152
interactive_markers::MenuHandler
UrdfModelMarker::pub_selected_
ros::Publisher pub_selected_
Definition: urdf_model_marker.h:151
UrdfModelMarker::server_name
std::string server_name
Definition: urdf_model_marker.h:178
mutex
boost::mutex mutex
Definition: bounding_box_marker.cpp:44
im_utils::makeMeshMarkerControl
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)
Definition: interactive_marker_utils.cpp:112
UrdfModelMarker::use_dynamic_tf_
bool use_dynamic_tf_
Definition: urdf_model_marker.h:196
UrdfModelMarker::index_
int index_
Definition: urdf_model_marker.h:203
UrdfModelMarker::serv_reset_
ros::ServiceServer serv_reset_
Definition: urdf_model_marker.h:162
UrdfModelMarker::mode_
string mode_
Definition: urdf_model_marker.h:197
UrdfModelMarker::diagnostic_updater_
std::shared_ptr< diagnostic_updater::Updater > diagnostic_updater_
Definition: urdf_model_marker.h:140
vector< string >
UrdfModelMarker::is_joint_states_locked_
bool is_joint_states_locked_
Definition: urdf_model_marker.h:169
UrdfModelMarker::graspPoint::graspPoint
graspPoint()
Definition: urdf_model_marker.h:211
UrdfModelMarker::linkProperty::joint_axis
urdf::Vector3 joint_axis
Definition: urdf_model_marker.h:240
UrdfModelMarker::show_marker_
ros::Subscriber show_marker_
Definition: urdf_model_marker.h:159
tf::TransformBroadcaster
UrdfModelMarker::linkProperty::movable_link
string movable_link
Definition: urdf_model_marker.h:235
UrdfModelMarker
Definition: urdf_model_marker.h:54
UrdfModelMarker::robot_mode_
bool robot_mode_
Definition: urdf_model_marker.h:194
ros::ServiceClient
UrdfModelMarker::linkProperty
Definition: urdf_model_marker.h:225
header
header
UrdfModelMarker::graspPoint
Definition: urdf_model_marker.h:210
UrdfModelMarker::init_stamp_
ros::Time init_stamp_
Definition: urdf_model_marker.h:204
menu
menu
UrdfModelMarker::serv_markers_set_
ros::ServiceServer serv_markers_set_
Definition: urdf_model_marker.h:164
transform_listener.h
tf.h
UrdfModelMarker::sub_set_urdf_
ros::Subscriber sub_set_urdf_
Definition: urdf_model_marker.h:160
UrdfModelMarker::linkProperty::displayModelMarker
bool displayModelMarker
Definition: urdf_model_marker.h:232
dummy_camera.frame_id
frame_id
Definition: dummy_camera.py:10
server
std::shared_ptr< interactive_markers::InteractiveMarkerServer > server
Definition: bounding_box_marker.cpp:43
UrdfModelMarker::base_frame
std::string base_frame
Definition: urdf_model_marker.h:179
interactive_marker_server.h
ros::Time
urdf::ModelInterfaceSharedPtr
boost::shared_ptr< ModelInterface > ModelInterfaceSharedPtr
Definition: interactive_marker_interface.h:23
urdf
UrdfModelMarker::server_
std::shared_ptr< interactive_markers::InteractiveMarkerServer > server_
Definition: urdf_model_marker.h:137
std
length
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
UrdfModelMarker::target_frame
std::string target_frame
Definition: urdf_model_marker.h:181
UrdfModelMarker::linkProperty::linkProperty
linkProperty()
Definition: urdf_model_marker.h:226
UrdfModelMarker::pub_move_model_
ros::Publisher pub_move_model_
Definition: urdf_model_marker.h:148
tf::TransformListener
index
char * index(char *sp, char c)
UrdfModelMarker::graspPoint::displayGraspPoint
bool displayGraspPoint
Definition: urdf_model_marker.h:219
UrdfModelMarker::model_name_
std::string model_name_
Definition: urdf_model_marker.h:185
diagnostic_updater::DiagnosticStatusWrapper
UrdfModelMarker::sub_set_root_pose_
ros::Subscriber sub_set_root_pose_
Definition: urdf_model_marker.h:157
UrdfModelMarker::linkProperty::joint_angle
double joint_angle
Definition: urdf_model_marker.h:241
UrdfModelMarker::linkProperty::origin
geometry_msgs::Pose origin
Definition: urdf_model_marker.h:238
UrdfModelMarker::use_visible_color_
bool use_visible_color_
Definition: urdf_model_marker.h:200
urdf::LinkConstSharedPtr
boost::shared_ptr< const Link > LinkConstSharedPtr
Definition: interactive_marker_utils.h:35
UrdfModelMarker::serv_unlock_joint_states_
ros::ServiceServer serv_unlock_joint_states_
Definition: urdf_model_marker.h:167
UrdfModelMarker::dynamic_tf_publisher_publish_tf_client
ros::ServiceClient dynamic_tf_publisher_publish_tf_client
Definition: urdf_model_marker.h:176
radius
GLdouble radius
UrdfModelMarker::tf_prefix_
std::string tf_prefix_
Definition: urdf_model_marker.h:201
root
root
UrdfModelMarker::linkProperty::displayMoveMarker
bool displayMoveMarker
Definition: urdf_model_marker.h:231
UrdfModelMarker::graspPoint::displayMoveMarker
bool displayMoveMarker
Definition: urdf_model_marker.h:220
UrdfModelMarker::serv_markers_del_
ros::ServiceServer serv_markers_del_
Definition: urdf_model_marker.h:165
UrdfModelMarker::dynamic_tf_check_time_acc_
jsk_topic_tools::TimeAccumulator dynamic_tf_check_time_acc_
Definition: urdf_model_marker.h:142
UrdfModelMarker::sub_reset_joints_
ros::Subscriber sub_reset_joints_
Definition: urdf_model_marker.h:155
UrdfModelMarker::root_pose_origin_
geometry_msgs::Pose root_pose_origin_
Definition: urdf_model_marker.h:190
UrdfModelMarker::tfb_
tf::TransformBroadcaster tfb_
Definition: urdf_model_marker.h:173
UrdfModelMarker::scale_factor_
double scale_factor_
Definition: urdf_model_marker.h:193
UrdfModelMarker::linkProperty::rotation_count
int rotation_count
Definition: urdf_model_marker.h:242
ros::NodeHandle
ros::Subscriber
UrdfModelMarker::pub_move_object_
ros::Publisher pub_move_object_
Definition: urdf_model_marker.h:147
init
void init(void)
UrdfModelMarker::graspPoint::pose
geometry_msgs::Pose pose
Definition: urdf_model_marker.h:221
UrdfModelMarker::joint_state_
sensor_msgs::JointState joint_state_
Definition: urdf_model_marker.h:207
UrdfModelMarker::move_base_frame
std::string move_base_frame
Definition: urdf_model_marker.h:180


jsk_interactive_marker
Author(s): furuta
autogenerated on Fri Aug 2 2024 08:50:24