18 #include <nav_msgs/Odometry.h> 20 #ifndef COB_ODOMETRY_TRACKER_H 21 #define COB_ODOMETRY_TRACKER_H 27 OdometryTracker(
const std::string &from =
"odom",
const std::string &to =
"base_footprint" ,
double cov_pose = 0.1,
double cov_twist = 0.1) {
28 odom_.header.frame_id = from;
29 odom_.child_frame_id = to;
30 for(
int i = 0; i < 6; i++){
31 odom_.pose.covariance[i*6+i] = cov_pose;
32 odom_.twist.covariance[6*i+i] = cov_twist;
43 odom_.header.stamp = now;
45 odom_.twist.twist.linear.x = 0;
46 odom_.twist.twist.linear.y = 0;
47 odom_.twist.twist.angular.z = 0;
49 odom_.pose.pose.position.x = 0;
50 odom_.pose.pose.position.y = 0;
57 void track(
const ros::Time &now,
double dt,
double vel_x,
double vel_y,
double vel_theta){
61 odom_.header.stamp = now;
63 double vel_x_mid = (vel_x+odom_.twist.twist.linear.x)/2.0;
64 double vel_y_mid = (vel_y+odom_.twist.twist.linear.y)/2.0;
66 double sin_theta = sin(theta_rob_rad_);
67 double cos_theta = cos(theta_rob_rad_);
68 theta_rob_rad_ += vel_theta * dt;
70 odom_.pose.pose.position.x += (vel_x_mid * cos_theta - vel_y_mid * sin_theta) * dt;
71 odom_.pose.pose.position.y += (vel_x_mid * sin_theta + vel_y_mid * cos_theta) * dt;
74 odom_.twist.twist.linear.x = vel_x;
75 odom_.twist.twist.linear.y = vel_y;
76 odom_.twist.twist.angular.z = vel_theta;
const nav_msgs::Odometry & getOdometry()
void init(const ros::Time &now)
void track(const ros::Time &now, double dt, double vel_x, double vel_y, double vel_theta)
static geometry_msgs::Quaternion createQuaternionMsgFromYaw(double yaw)
OdometryTracker(const std::string &from="odom", const std::string &to="base_footprint", double cov_pose=0.1, double cov_twist=0.1)