specific_transform_publisher.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
2 #include <tf/tf.h>
5 #include <iostream>
6 
7 int main(int argc, char** argv)
8 {
9  ros::init(argc, argv, "jsk_model_marker_interface");
11  ros::NodeHandle pnh_("~");
13 
14  ros::Publisher pub_ = pnh_.advertise<tf::tfMessage> ("/specific_transform", 1);
15 
16  std::vector<std::string> parent_frame;
17  std::vector<std::string> child_frame;
18 
19  {
20  XmlRpc::XmlRpcValue param_val;
21  pnh_.getParam("parent_frame", param_val);
22  if (param_val.getType() == XmlRpc::XmlRpcValue::TypeArray) {
23  for(int i = 0; i < param_val.size(); i++) {
24  std::string st = param_val[i];
25  parent_frame.push_back(st);
26  }
27  } else if (param_val.getType() == XmlRpc::XmlRpcValue::TypeString) {
28  std::string st = param_val;
29  parent_frame.push_back(st);
30  }
31  }
32  {
33  XmlRpc::XmlRpcValue param_val;
34  pnh_.getParam("child_frame", param_val);
35  if (param_val.getType() == XmlRpc::XmlRpcValue::TypeArray) {
36  for(int i = 0; i < param_val.size(); i++) {
37  std::string st = param_val[i];
38  child_frame.push_back(st);
39  }
40  } else if (param_val.getType() == XmlRpc::XmlRpcValue::TypeString) {
41  std::string st = param_val;
42  child_frame.push_back(st);
43  }
44  }
45 
46  if (parent_frame.size() != child_frame.size()) {
47  ROS_FATAL("size difference between parent frames and child frames");
48  }
49 
50  double loop_hz;
51  pnh_.param("loop_hz", loop_hz, 1.0 );
52 
53  for(int i = 0; i < parent_frame.size(); i++) {
54  ROS_INFO_STREAM("parent->child: " << parent_frame[i] << " -> " << child_frame[i]);
55  }
56  ROS_INFO_STREAM("loop_hz:" << loop_hz);
57 
58  ros::Rate rate(loop_hz);
59 
60  while (ros::ok())
61  {
62  tf::tfMessage tf_msg;
63  for(int i = 0; i < parent_frame.size(); i++) {
64  geometry_msgs::TransformStamped tfs_msg;
66  try {
67  tfl_.lookupTransform(parent_frame[i], child_frame[i], ros::Time(0), stf);
68  tf::transformStampedTFToMsg(stf, tfs_msg);
69  tf_msg.transforms.push_back(tfs_msg);
70  } catch(tf::TransformException ex) {
71  ROS_INFO_STREAM("missing transform: " << parent_frame[i] << " to " << child_frame[i]);
72  }
73  }
74  pub_.publish(tf_msg);
75 
76  ros::spinOnce();
77  rate.sleep();
78  }
79 }
#define ROS_FATAL(...)
void publish(const boost::shared_ptr< M > &message) const
int size() const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
int main(int argc, char **argv)
Type const & getType() const
bool param(const std::string &param_name, T &param_val, const T &default_val) const
ROSCPP_DECL bool ok()
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void lookupTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &time, StampedTransform &transform) const
bool sleep()
#define ROS_INFO_STREAM(args)
bool getParam(const std::string &key, std::string &s) const
static void transformStampedTFToMsg(const StampedTransform &bt, geometry_msgs::TransformStamped &msg)
ROSCPP_DECL void spinOnce()


jsk_topic_tools
Author(s): Kei Okada , Yusuke Furuta
autogenerated on Tue Feb 6 2018 03:45:19