urdf_model_marker_main.cpp
Go to the documentation of this file.
1 #include "urdf_parser/urdf_parser.h"
2 #include <iostream>
3 #include <memory>
8 #include <geometry_msgs/PoseArray.h>
10 
11 using namespace urdf;
12 using namespace std;
13 using namespace im_utils;
14 
16 private:
20  std::shared_ptr<interactive_markers::InteractiveMarkerServer> server_;
21  string model_name_;
23  double scale_factor_;
24  geometry_msgs::PoseStamped pose_stamped_;
25  geometry_msgs::Pose root_offset_;
27  string mode_;
28  string model_file_;
31  string frame_id_;
34  bool display_;
35  map<string, double> initial_pose_map_;
36 
37  typedef std::shared_ptr<UrdfModelMarker> umm_ptr;
39  umm_vec umm_vec_;
40 
41 public:
42  void displayMarkerArrayCB(const geometry_msgs::PoseArrayConstPtr &msg) {
43  std_msgs::Header header = msg->header;
44  geometry_msgs::PoseStamped ps;
45  ps.header = header;
46 
47  int msg_size = msg->poses.size();
48  int umm_vec_size = umm_vec_.size();
49 
50  if (msg_size <= umm_vec_size) {
51  for (int i = 0; i < msg_size; i++) {
52  //change pose
53  ps.pose = msg->poses[i];
54  umm_vec_[i]->setRootPose(ps);
55  }
56  for (int i = msg_size; i< umm_vec_size; i++) {
57  //move far away
58  ps.pose.position.x = ps.pose.position.y = ps.pose.position.z = 1000000;
59  ps.pose.orientation.w = 1;
60  umm_vec_[i]->setRootPose(ps);
61  }
62  }
63  else {
64  for (int i = 0; i < umm_vec_size; i++) {
65  //change pose
66  ps.pose = msg->poses[i];
67  umm_vec_[i]->setRootPose(ps);
68  }
69  for (int i = umm_vec_size; i < msg_size; i++) {
70  //geometry_msgs::PoseStamped pose = msg->poses[i];
71  ps.pose = msg->poses[i];
72  umm_vec_.push_back(umm_ptr(new UrdfModelMarker(model_name_, model_description_, model_file_, header.frame_id, ps, root_offset_, scale_factor_, mode_ , robot_mode_, registration_,fixed_link_, use_robot_description_, use_visible_color_, initial_pose_map_, i, server_)));
73  }
74  }
75  }
76 
77  void init() {
78  //name
79  model_name_.assign(model_config_["name"]);
80 
81  //description
82  model_description_ = "";
83  if (model_config_.hasMember("description")) {
84  model_description_.assign(model_config_["description"]);
85  }
86  //scale
87  scale_factor_ = 1.02;
88  if (model_config_.hasMember("scale")) {
89  scale_factor_ = getXmlValue(model_config_["scale"]);
90  }
91  //pose
92  if (model_config_.hasMember("pose")) {
93  pose_stamped_.pose = getPose(model_config_["pose"]);
94  }
95  else {
96  pose_stamped_.pose = geometry_msgs::Pose();
97  pose_stamped_.pose.orientation.w = 1.0;
98  }
99  pose_stamped_.header.stamp = ros::Time::now();
100 
101  if (model_config_.hasMember("offset")) {
102  root_offset_ = getPose(model_config_["offset"]);
103  }
104  else {
105  root_offset_ = geometry_msgs::Pose();
106  root_offset_.orientation.w = 1.0;
107  }
108 
109  //color
110  use_visible_color_ = false;
111  if (model_config_.hasMember("use_visible_color")) {
112  use_visible_color_ = model_config_["use_visible_color"];
113  }
114  ROS_INFO_STREAM("use_visible_color: " << use_visible_color_);
115  //frame id
116  frame_id_.assign(model_config_["frame-id"]);
117 
118  //mode
119  mode_ = "model";
120  model_file_ = "";
121  registration_ = false;
122  if (model_config_.hasMember("registration")) {
123  registration_ = model_config_["registration"];
124  mode_ = "registration";
125  }
126 
127  if (model_config_.hasMember("fixed_link")) {
128  XmlRpc::XmlRpcValue fixed_links = model_config_["fixed_link"];
129  if (fixed_links.getType() == XmlRpc::XmlRpcValue::TypeString) {
130  fixed_link_.push_back( fixed_links );
131  }
132  else if (fixed_links.getType() == XmlRpc::XmlRpcValue::TypeArray) {
133  for(int i=0; i< fixed_links.size(); i++) {
134  fixed_link_.push_back(fixed_links[i]);
135  }
136  }
137  }
138 
139  if (model_config_.hasMember("model")) {
140  model_file_.assign(model_config_["model"]);
141  }
142  use_robot_description_ = false;
143  if (model_config_.hasMember("use_robot_description")) {
144  model_file_ = "/robot_description";
145  use_robot_description_ = model_config_["use_robot_description"];
146  }
147  if (model_config_.hasMember("model_param")) {
148  use_robot_description_ = true;
149  model_file_.assign(model_config_["model_param"]);
150  }
151  if (model_config_["robot"]) {
152  mode_ = "robot";
153  }
154  if (model_config_.hasMember("mode")) {
155  mode_.assign(model_config_["mode"]);
156  }
157 
158  robot_mode_ = model_config_["robot"];
159 
160  //initial pose
161  if (model_config_.hasMember("initial_joint_state")) {
162  XmlRpc::XmlRpcValue initial_pose = model_config_["initial_joint_state"];
163  for(int i=0; i< initial_pose.size(); i++) {
164  XmlRpc::XmlRpcValue v = initial_pose[i];
165  string name;
166  double position;
167  if (v.hasMember("name") && v.hasMember("position")) {
168  name.assign(v["name"]);
169  position = getXmlValue(v["position"]);
170  initial_pose_map_[name] = position;
171  }
172  }
173  }
174 
175  //default display
176  if (model_config_.hasMember("display")) {
177  display_ = model_config_["display"];
178  }
179  else {
180  display_ = true;
181  }
182  ROS_INFO("Loading model config");
183  ROS_INFO("model_name: %s", model_name_.c_str());
184  ROS_INFO("model_description: %s", model_description_.c_str());
185  ROS_INFO("scale_factor: %f", scale_factor_);
186  ROS_INFO_STREAM("pose_stamped: " << pose_stamped_);
187  ROS_INFO_STREAM("root_offset: " << root_offset_);
188  ROS_INFO_STREAM("frame_id: " << frame_id_);
189  ROS_INFO_STREAM("mode: " << mode_);
190  ROS_INFO_STREAM("registration: " << registration_);
191 
192 
193  //ROS_INFO_STREAM("fixed_link: " << fixed_link_);
194  ROS_INFO_STREAM("model_file: " << model_file_);
195  ROS_INFO_STREAM("use_robot_description: " << use_robot_description_);
196  }
197 
198  void addUrdfMarker() {
199  new UrdfModelMarker(model_name_, model_description_, model_file_, frame_id_, pose_stamped_ ,root_offset_, scale_factor_, mode_ , robot_mode_, registration_,fixed_link_, use_robot_description_, use_visible_color_,initial_pose_map_, -1, server_);
200  }
201 
202  UrdfModelSettings(XmlRpc::XmlRpcValue model, std::shared_ptr<interactive_markers::InteractiveMarkerServer> server) : pnh_("~") {
203  model_config_ = model;
204  server_ = server;
205  init();
206 
207  if (display_) {
208  addUrdfMarker();
209  }
210  display_marker_sub_ = pnh_.subscribe<geometry_msgs::PoseArray> (model_name_ + "/pose_array", 1, boost::bind( &UrdfModelSettings::displayMarkerArrayCB, this, _1));
211  }
212 };
213 
214 
215 
216 int main(int argc, char** argv)
217 {
218  ros::init(argc, argv, "jsk_model_marker_interface");
220  ros::NodeHandle pnh_("~");
221 
222  string server_name;
223  pnh_.param("server_name", server_name, std::string ("") );
224  if (server_name == "") {
225  server_name = ros::this_node::getName();
226  }
227 
228  std::shared_ptr<interactive_markers::InteractiveMarkerServer> server;
229  server.reset( new interactive_markers::InteractiveMarkerServer(server_name, "", false) );
230 
232  pnh_.param("model_config", v, v);
233  for (int i=0; i< v.size(); i++) {
234  new UrdfModelSettings(v[i], server);
235  }
236  ros::spin();
237  return 0;
238 }
239 
240 
ros::Subscriber display_marker_sub_
vector< umm_ptr > umm_vec
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
geometry_msgs::Pose getPose(XmlRpc::XmlRpcValue val)
std::shared_ptr< interactive_markers::InteractiveMarkerServer > server_
int size() const
GLfloat n[6][3]
int main(int argc, char **argv)
geometry_msgs::PoseStamped pose_stamped_
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROSCPP_DECL const std::string & getName()
map< string, double > initial_pose_map_
Type const & getType() const
ROSCPP_DECL void spin(Spinner &spinner)
UrdfModelSettings(XmlRpc::XmlRpcValue model, std::shared_ptr< interactive_markers::InteractiveMarkerServer > server)
double getXmlValue(XmlRpc::XmlRpcValue val)
geometry_msgs::Pose root_offset_
#define ROS_INFO(...)
bool param(const std::string &param_name, T &param_val, const T &default_val) const
header
void displayMarkerArrayCB(const geometry_msgs::PoseArrayConstPtr &msg)
pointer size
std::shared_ptr< UrdfModelMarker > umm_ptr
vector< string > fixed_link_
void init(void)
bool hasMember(const std::string &name) const
XmlRpc::XmlRpcValue model_config_
#define ROS_INFO_STREAM(args)
GLfloat v[8][3]
static Time now()
std::shared_ptr< interactive_markers::InteractiveMarkerServer > server


jsk_interactive_marker
Author(s): furuta
autogenerated on Sat Mar 20 2021 03:03:33