00001 #include "pose2d_odom_alg.h" 00002 00003 Pose2dOdomAlgorithm::Pose2dOdomAlgorithm() 00004 { 00005 } 00006 00007 Pose2dOdomAlgorithm::~Pose2dOdomAlgorithm() 00008 { 00009 } 00010 00011 void Pose2dOdomAlgorithm::config_update(const Config& new_cfg, uint32_t level) 00012 { 00013 this->lock(); 00014 00015 // save the current configuration 00016 this->config_=new_cfg; 00017 00018 this->unlock(); 00019 } 00020 00021 // Pose2dOdomAlgorithm Public API 00022 00023 00024 void Pose2dOdomAlgorithm::getOdometry(nav_msgs::Odometry & o, geometry_msgs::TransformStamped & t) 00025 { 00026 00027 double dT = ( new_time_ - old_time_ ).toSec(); // [s] 00028 double dx = ( new_pose2D_.x - old_pose2D_.x ) / dT; // [m/s] 00029 double dy = ( new_pose2D_.y - old_pose2D_.y ) / dT; // [m/s] 00030 double dth = ( new_pose2D_.theta - old_pose2D_.theta ) / dT; // [m/s] 00031 00032 geometry_msgs::Quaternion or_q = tf::createQuaternionMsgFromYaw( new_pose2D_.theta ); 00033 00034 o.header.stamp = new_time_; 00035 o.header.frame_id = parent_id_; 00036 o.child_frame_id = frame_id_; 00037 00038 o.pose.pose.position.x = new_pose2D_.x; 00039 o.pose.pose.position.y = new_pose2D_.y; 00040 o.pose.pose.position.z = 0.0; 00041 o.pose.pose.orientation = or_q; 00042 00043 o.pose.covariance[0] = 00044 o.pose.covariance[7] = 00045 o.pose.covariance[14] = 00046 o.pose.covariance[21] = 00047 o.pose.covariance[28] = 00048 o.pose.covariance[35] = 0.031; 00049 00050 o.twist.twist.linear.x = dx; 00051 o.twist.twist.linear.y = dy; 00052 o.twist.twist.linear.z = 0.0; 00053 o.twist.twist.angular.x = 0.0; 00054 o.twist.twist.angular.y = 0.0; 00055 o.twist.twist.angular.z = dth; 00056 00057 o.twist.covariance[0] = 00058 o.twist.covariance[7] = 00059 o.twist.covariance[14] = 00060 o.twist.covariance[21] = 00061 o.twist.covariance[28] = 00062 o.twist.covariance[35] = 999; 00063 00064 t.header.stamp = new_time_; 00065 t.header.frame_id = parent_id_; 00066 t.child_frame_id = frame_id_; 00067 00068 t.transform.translation.x = new_pose2D_.x; 00069 t.transform.translation.y = new_pose2D_.y; 00070 t.transform.translation.z = 0.0; 00071 t.transform.rotation = or_q; 00072 00073 }