2 #include <sensor_msgs/Imu.h>
3 #include <nav_msgs/Odometry.h>
4 #include <geometry_msgs/PoseWithCovarianceStamped.h>
5 #include <tf/transform_broadcaster.h>
6 #include <tf/transform_listener.h>
19 nav_msgs::Odometry
gps;
36 geometry_msgs::PoseStamped pose;
37 pose.header.frame_id =
"/base_footprint";
38 pose.pose.position.x =
gps.pose.pose.position.x;
39 pose.pose.position.y =
gps.pose.pose.position.y;
44 transform.setOrigin(Vector3(pose.pose.position.x, pose.pose.position.y, 0.0));
46 quaternionMsgToTF(pose.pose.orientation, q);
47 transform.setRotation(q);
48 tf_broadcaster->sendTransform(StampedTransform(transform, ros::Time::now(),
"map",
"base_footprint"));
53 geometry_msgs::QuaternionStamped q;
54 q.header.stamp = ros::Time(0);
55 q.header.frame_id = msg->header.frame_id;
56 q.quaternion = msg->orientation;
57 tf_listener->waitForTransform(
"base_footprint", msg->header.frame_id, ros::Time(0), ros::Duration(10.0));
58 geometry_msgs::QuaternionStamped transformed;
59 tf_listener->transformQuaternion(
"base_footprint", q, transformed);
67 tf_listener->waitForTransform(
"base_footprint", msg->header.frame_id, ros::Time(0), ros::Duration(10.0));
68 geometry_msgs::PoseStamped p;
69 p.header.stamp = ros::Time(0);
70 p.header.frame_id = msg->header.frame_id;
71 p.pose = msg->pose.pose;
72 geometry_msgs::PoseStamped transformed;
73 tf_listener->transformPose(
"base_footprint", p, transformed);
74 gps.pose.pose = transformed.pose;
87 int main(
int argc,
char** argv)
89 ros::init(argc, argv,
"pose_tracker");
91 tf_broadcaster = std::unique_ptr<TransformBroadcaster>(
new TransformBroadcaster);
93 tf_listener = std::unique_ptr<TransformListener>(
new TransformListener);
97 ros::Subscriber imu_sub = nh.subscribe(
"/imu", 1,
imu_callback);
99 ros::Subscriber gps_sub = nh.subscribe(
"/gps_odom", 1,
gps_callback);
101 pose_pub = nh.advertise<geometry_msgs::PoseStamped>(
"/odom_combined", 1);
103 origin_pub = nh.advertise<geometry_msgs::PointStamped>(
"/map_origin", 1);
117 geometry_msgs::PointStamped msg;
118 msg.header.stamp = ros::Time::now();
119 msg.header.frame_id =
"/world";
121 origin_pub.publish(msg);
std::unique_ptr< TransformBroadcaster > tf_broadcaster
geometry_msgs::Quaternion orientation
ros::Publisher origin_pub
geometry_msgs::Point origin
std::unique_ptr< TransformListener > tf_listener
void gps_callback(const nav_msgs::OdometryConstPtr &msg)
int main(int argc, char **argv)
void imu_callback(const sensor_msgs::ImuConstPtr &msg)
bool orientationIsValid()