Go to the documentation of this file.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
00040
00041
00042 #include <mecanum_drive_controller/odometry.h>
00043
00044 #include <tf/transform_datatypes.h>
00045
00046 #include <boost/bind.hpp>
00047
00048 namespace mecanum_drive_controller
00049 {
00050
00051 namespace bacc = boost::accumulators;
00052
00054 Odometry::Odometry(size_t velocity_rolling_window_size)
00055 : timestamp_(0.0)
00056 , x_(0.0)
00057 , y_(0.0)
00058 , heading_(0.0)
00059 , linearX_(0.0)
00060 , linearY_(0.0)
00061 , angular_(0.0)
00062 , wheels_k_(0.0)
00063 , wheels_radius_(0.0)
00064 , velocity_rolling_window_size_(velocity_rolling_window_size)
00065 , linearX_acc_(RollingWindow::window_size = velocity_rolling_window_size)
00066 , linearY_acc_(RollingWindow::window_size = velocity_rolling_window_size)
00067 , angular_acc_(RollingWindow::window_size = velocity_rolling_window_size)
00068 , integrate_fun_(boost::bind(&Odometry::integrateExact, this, _1, _2, _3))
00069 {
00070 }
00071
00073 void Odometry::init(const ros::Time& time)
00074 {
00075
00076 linearX_acc_ = RollingMeanAcc(RollingWindow::window_size = velocity_rolling_window_size_);
00077 linearY_acc_ = RollingMeanAcc(RollingWindow::window_size = velocity_rolling_window_size_);
00078 angular_acc_ = RollingMeanAcc(RollingWindow::window_size = velocity_rolling_window_size_);
00079
00080
00081 timestamp_ = time;
00082 }
00083
00085 bool Odometry::update(double wheel0_vel, double wheel1_vel, double wheel2_vel, double wheel3_vel, const ros::Time &time)
00086 {
00088 const double dt = (time - timestamp_).toSec();
00089 if (dt < 0.0001)
00090 return false;
00091
00092 timestamp_ = time;
00093
00099 linearX_ = 0.25 * wheels_radius_ * ( wheel0_vel + wheel1_vel + wheel2_vel + wheel3_vel);
00100 linearY_ = 0.25 * wheels_radius_ * (-wheel0_vel + wheel1_vel - wheel2_vel + wheel3_vel);
00101 angular_ = 0.25 * wheels_radius_ / wheels_k_ * (-wheel0_vel - wheel1_vel + wheel2_vel + wheel3_vel);
00102
00104 integrate_fun_(linearX_ * dt, linearY_ * dt, angular_ * dt);
00105
00106 return true;
00107 }
00108
00110 void Odometry::updateOpenLoop(double linearX, double linearY, double angular, const ros::Time &time)
00111 {
00113 linearX_ = linearX;
00114 linearY_ = linearY;
00115 angular_ = angular;
00116
00118 const double dt = (time - timestamp_).toSec();
00119 timestamp_ = time;
00120 integrate_fun_(linearX * dt, linearY * dt, angular * dt);
00121 }
00122
00124 void Odometry::setWheelsParams(double wheels_k, double wheels_radius)
00125 {
00126 wheels_k_ = wheels_k;
00127
00128 wheels_radius_ = wheels_radius;
00129 }
00130
00132 void Odometry::integrateExact(double linearX, double linearY, double angular)
00133 {
00135 heading_ += angular;
00136
00139 tf::Matrix3x3 R_m_odom = tf::Matrix3x3(tf::createQuaternionFromYaw(heading_));
00140 tf::Vector3 vel_inOdom = R_m_odom * tf::Vector3(linearX, linearY, 0.0);
00141
00143 x_ += vel_inOdom.x();
00144 y_ += vel_inOdom.y();
00145 }
00146
00147 }