00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include <ros/ros.h>
00040 #include <tf/tf.h>
00041 #include <tf/transform_listener.h>
00042 #include <geometry_msgs/PoseWithCovarianceStamped.h>
00043
00044
00045 static std::string fixed_frame_;
00046 static std::vector<double> cov_fixed_;
00047
00048
00049
00050 void poseCallback(const geometry_msgs::PoseWithCovarianceStampedConstPtr& pose)
00051 {
00052 geometry_msgs::PoseWithCovarianceStamped pose_fixed;
00053 ros::NodeHandle node_top;
00054 static tf::TransformListener tf;
00055 static ros::Publisher pub = node_top.advertise<geometry_msgs::PoseWithCovarianceStamped>("pose_out", 10);
00056
00057
00058 ROS_DEBUG("Measurement in frame %s: %f, %f, %f, %f, %f, %f, %f",
00059 pose->header.frame_id.c_str(),
00060 pose->pose.pose.position.x,
00061 pose->pose.pose.position.y,
00062 pose->pose.pose.position.z,
00063 pose->pose.pose.orientation.x,
00064 pose->pose.pose.orientation.y,
00065 pose->pose.pose.orientation.z,
00066 pose->pose.pose.orientation.w);
00067
00068
00069 tf::Stamped<tf::Pose> tf_stamped_pose;
00070 tf::poseMsgToTF(pose->pose.pose, tf_stamped_pose);
00071 tf_stamped_pose.stamp_ = pose->header.stamp;
00072 tf_stamped_pose.frame_id_ = pose->header.frame_id;
00073
00074
00075 if (!tf.waitForTransform(fixed_frame_, pose->header.frame_id, pose->header.stamp, ros::Duration(0.5))){
00076 ROS_ERROR("Could not transform from %s to %s at time %f", fixed_frame_.c_str(), pose->header.frame_id.c_str(), pose->header.stamp.toSec());
00077 return;
00078 }
00079 tf.transformPose(fixed_frame_, tf_stamped_pose, tf_stamped_pose);
00080
00081
00082 pose_fixed = *pose;
00083 tf::poseTFToMsg(tf_stamped_pose, pose_fixed.pose.pose);
00084 pose_fixed.header.frame_id = fixed_frame_;
00085
00086 ROS_DEBUG("Measurement in frame %s: %f, %f, %f, %f, %f, %f, %f",
00087 fixed_frame_.c_str(),
00088 pose_fixed.pose.pose.position.x,
00089 pose_fixed.pose.pose.position.y,
00090 pose_fixed.pose.pose.position.z,
00091 pose_fixed.pose.pose.orientation.x,
00092 pose_fixed.pose.pose.orientation.y,
00093 pose_fixed.pose.pose.orientation.z,
00094 pose_fixed.pose.pose.orientation.w);
00095
00096
00097 for (unsigned int i=0; i<6; i++)
00098 pose_fixed.pose.covariance[6*i+i] = cov_fixed_[i];
00099 pub.publish(pose_fixed);
00100 }
00101
00102
00103
00104 int main(int argc, char** argv){
00105 ros::init(argc, argv, "covariance_inserter");
00106 ros::NodeHandle node("~");
00107 cov_fixed_.resize(6);
00108
00109 node.param("fixed_frame", fixed_frame_, std::string("fixed_frame_not_specified"));
00110 node.param("cov_fixed1", cov_fixed_[0], 0.0);
00111 node.param("cov_fixed2", cov_fixed_[1], 0.0);
00112 node.param("cov_fixed3", cov_fixed_[2], 0.0);
00113 node.param("cov_fixed4", cov_fixed_[3], 0.0);
00114 node.param("cov_fixed5", cov_fixed_[4], 0.0);
00115 node.param("cov_fixed6", cov_fixed_[5], 0.0);
00116
00117 ros::NodeHandle node_top;
00118 ros::Subscriber sub = node_top.subscribe<geometry_msgs::PoseWithCovarianceStamped>("pose_in", 10, &poseCallback);
00119
00120 ros::spin();
00121 return 0;
00122 }