odom.cpp
Go to the documentation of this file.
2 
3 #include <cmath>
4 
5 #define TAU (2.0 * M_PI)
6 
8 
9 Odom Odom::update(const ros::Time &stamp, const double left_vel, const double right_vel, const double turret_pos) const
10 {
11  const double v_left = left_vel * wheel_radius_; // rad/s -> m/s
12  const double v_right = right_vel * wheel_radius_; // rad/s -> m/s
13 
14  const double delta = (stamp - stamp_).toSec(); // s
15  // std::cout << v_left << ", " << v_right << ", " << turret_pos << ", " << delta << std::endl;
16 
18 
19  const double v_avg = (v_left + v_right) / 2;
20 
21  if (v_right == v_left)
22  {
23  ret.x_ = x_ + v_avg * cos(heading_) * delta;
24  ret.y_ = y_ + v_avg * sin(heading_) * delta;
25  ret.heading_ = heading_;
26  ret.heading_offset_ = turret_pos;
27  ret.vel_x_ = v_avg;
28  ret.vel_y_ = v_avg;
29  ret.vel_heading_ = 0.;
30 
31  return ret;
32  }
33 
34 
35  const double R = wheel_separation_ / 2 * (v_left + v_right) / (v_right - v_left);
36  const double w = (v_right - v_left) / wheel_separation_;
37 
38  const double icc_x = x_ - R * sin(heading_);
39  const double icc_y = y_ - R * cos(heading_);
40 
41 
42  ret.vel_heading_ = w;
43 
44  ret.x_ = cos(w * delta) * (x_ - icc_x) - sin(w * delta) * (y_ - icc_y) + icc_x;
45  ret.y_ = sin(w * delta) * (x_ - icc_x) + cos(w * delta) * (y_ - icc_y) + icc_y;
46  ret.heading_ = heading_ + ret.vel_heading_ * delta;
47  ret.heading_offset_ = turret_pos;
48 
49  ret.vel_x_ = (ret.x_ - x_) / delta;
50  ret.vel_y_ = (ret.y_ - y_) / delta;
51 
52  return ret;
53 }
54 
55 double Odom::getX() const
56 {
57  return x_;
58 }
59 
60 double Odom::getY() const
61 {
62  return y_;
63 }
64 
65 double Odom::getHeading() const
66 {
67  return heading_;
68 }
69 
70 double Odom::getVelX() const
71 {
72  return vel_x_;
73 }
74 
75 double Odom::getVelY() const
76 {
77  return vel_y_;
78 }
79 
80 double Odom::getVelHeading() const
81 {
82  return vel_heading_;
83 }
84 
85 Odom Odom::zero(const ros::Time &stamp, const double wheel_separation, const double wheel_radius)
86 {
87  return Odom(stamp, wheel_separation, wheel_radius);
88 }
89 
90 Odom::Odom(const ros::Time &stamp, const double wheel_separation, const double wheel_radius)
91  : stamp_(stamp)
92  , wheel_separation_(wheel_separation)
93  , wheel_radius_(wheel_radius)
94  , x_(0.0)
95  , y_(0.0)
96  , heading_(0.0)
97  , heading_offset_(0.0)
98  , vel_x_(0.0)
99  , vel_y_(0.0)
100  , vel_heading_(0.0)
101 {
102 }
103 
104 std::ostream &operator <<(std::ostream &o, const quori_holonomic_drive_controller::Odom &odom)
105 {
106  return o << "Odom {" << std::endl
107  << " vel_x (m/s): " << odom.getVelX() << std::endl
108  << " vel_y (m/s): " << odom.getVelY() << std::endl
109  << " vel_heading (rad/s): " << odom.getVelHeading() << std::endl
110  << " x (m): " << odom.getX() << std::endl
111  << " y (m): " << odom.getY() << std::endl
112  << " heading (rad): " << odom.getHeading() << std::endl
113  << "}";
114 }
quori_holonomic_drive_controller::Odom::heading_offset_
double heading_offset_
Definition: odom.hpp:35
quori_holonomic_drive_controller::Odom::y_
double y_
Definition: odom.hpp:33
quori_holonomic_drive_controller::Odom::getX
double getX() const
Definition: odom.cpp:55
quori_holonomic_drive_controller::Odom::vel_y_
double vel_y_
Definition: odom.hpp:38
quori_holonomic_drive_controller::Odom::getY
double getY() const
Definition: odom.cpp:60
quori_holonomic_drive_controller::Odom::getVelX
double getVelX() const
Definition: odom.cpp:70
quori_holonomic_drive_controller::Odom::stamp_
ros::Time stamp_
Definition: odom.hpp:27
quori_holonomic_drive_controller::Odom::vel_heading_
double vel_heading_
Definition: odom.hpp:39
quori_holonomic_drive_controller::Odom::vel_x_
double vel_x_
Definition: odom.hpp:37
quori_holonomic_drive_controller::Odom::heading_
double heading_
Definition: odom.hpp:34
quori_holonomic_drive_controller
Definition: holonomic.hpp:5
quori_holonomic_drive_controller::Odom::x_
double x_
Definition: odom.hpp:32
quori_holonomic_drive_controller::Odom::wheel_radius_
double wheel_radius_
Definition: odom.hpp:30
operator<<
std::ostream & operator<<(std::ostream &o, const quori_holonomic_drive_controller::Odom &odom)
Definition: odom.cpp:104
quori_holonomic_drive_controller::Odom::Odom
Odom(const ros::Time &stamp, const double wheel_separation, const double wheel_radius)
Definition: odom.cpp:90
quori_holonomic_drive_controller::Odom::update
Odom update(const ros::Time &stamp, const double left_vel, const double right_vel, const double turret_pos) const
Definition: odom.cpp:9
quori_holonomic_drive_controller::Odom::getVelY
double getVelY() const
Definition: odom.cpp:75
ros::Time
quori_holonomic_drive_controller::Odom::wheel_separation_
double wheel_separation_
Definition: odom.hpp:29
quori_holonomic_drive_controller::Odom::getVelHeading
double getVelHeading() const
Definition: odom.cpp:80
quori_holonomic_drive_controller::Odom::getHeading
double getHeading() const
Definition: odom.cpp:65
odom.hpp
quori_holonomic_drive_controller::Odom::zero
static Odom zero(const ros::Time &stamp, const double wheel_separation, const double wheel_radius)
Definition: odom.cpp:85
quori_holonomic_drive_controller::Odom
Definition: odom.hpp:8


quori_holonomic_drive_controller
Author(s):
autogenerated on Wed Mar 2 2022 00:53:24