local_transform.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
2 #include <tf2_ros/buffer.h>
7 #include <geometry_msgs/PoseStamped.h>
8 
9 geometry_msgs::TransformStamped tf_ugv_od_ugv_bl;
10 //tf::StampedTransform *tf_scout_bl_ugv_bl;
12 
13 
14 void cb_local_tf(const geometry_msgs::PoseStamped& msg){
15  geometry_msgs::Pose pose_ugv_od_to_ugv_bl;
16  geometry_msgs::PoseStamped final_pose_ugv;
17  tf2::Transform ugv_od_ugv_bl_transform;
18 
19  tf2::fromMsg(tf_ugv_od_ugv_bl.transform, ugv_od_ugv_bl_transform); // Get transformation matrix from tf
20  tf2::toMsg(ugv_od_ugv_bl_transform, pose_ugv_od_to_ugv_bl); // Create pose msg from transformation matrix
21  ROS_INFO("OK");
22  final_pose_ugv.header = msg.header;
23  final_pose_ugv.header.frame_id = "ugv_odom";
24  final_pose_ugv.pose = pose_ugv_od_to_ugv_bl;
25  pub.publish(final_pose_ugv);
26 }
27 
28 int main(int argc, char** argv){
29  ros::init(argc, argv, "local_transform_node");
30  ros::Time::init();
31  ros::Rate r(10);
32  ros::NodeHandle node;
33  ros::Subscriber sub = node.subscribe("odometry/filtered/local", 1000, &cb_local_tf);
34  pub = node.advertise<geometry_msgs::PoseStamped>("/odometry/filtered/ugv_nav", 1);
35 
36  tf2_ros::Buffer tfBuffer;
37  tf2_ros::TransformListener tfListener(tfBuffer);
38 
39 
40  while (node.ok()){
41  try{
42  tf_ugv_od_ugv_bl = tfBuffer.lookupTransform( "ugv_odom", "ugv_base_link", ros::Time(0));
43  }
44  catch (tf2::TransformException &ex){
45  ROS_ERROR("%s",ex.what());
46  continue;
47  }
48  ros::spinOnce();
49  r.sleep();
50  }
51 
52 
53 
54  return 0;
55 };
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void cb_local_tf(const geometry_msgs::PoseStamped &msg)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ros::Publisher pub
#define ROS_INFO(...)
static void init()
void fromMsg(const A &, B &b)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
bool sleep()
B toMsg(const A &a)
bool ok() const
int main(int argc, char **argv)
ROSCPP_DECL void spinOnce()
#define ROS_ERROR(...)
geometry_msgs::TransformStamped tf_ugv_od_ugv_bl


earth_rover_localization
Author(s):
autogenerated on Wed Apr 28 2021 02:15:34