odometry.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2013, PAL Robotics, S.L.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the PAL Robotics nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /*
36  * Author: Luca Marchionni
37  * Author: Bence Magyar
38  * Author: Enrique Fernández
39  * Author: Paul Mathieu
40  */
41 
43 
44 #include <tf/transform_datatypes.h>
45 
46 #include <boost/bind.hpp>
47 
49 {
50 
51 namespace bacc = boost::accumulators;
52 
54 Odometry::Odometry(size_t velocity_rolling_window_size)
55 : timestamp_(0.0)
56 , x_(0.0)
57 , y_(0.0)
58 , heading_(0.0)
59 , linear_(0.0)
60 , angular_(0.0)
61 , wheel_radius_(0.0)
62 , wheel_separation_(0.0)
63 , velocity_rolling_window_size_(velocity_rolling_window_size)
64 , linear_acc_(RollingWindow::window_size = velocity_rolling_window_size)
65 , angular_acc_(RollingWindow::window_size = velocity_rolling_window_size)
66 , integrate_fun_(boost::bind(&Odometry::integrateExact, this, _1, _2))
67 {
68 }
69 
71 void Odometry::init(const ros::Time& time)
72 {
73  // Reset accumulators:
74  linear_acc_ = RollingMeanAcc(RollingWindow::window_size = velocity_rolling_window_size_);
75  angular_acc_ = RollingMeanAcc(RollingWindow::window_size = velocity_rolling_window_size_);
76 
77  // Reset timestamp:
78  timestamp_ = time;
79 }
80 
82 bool Odometry::update(double drive_motor_vel, double steer_motor_vel, const ros::Time &time)
83 {
85  const double dt = (time - timestamp_).toSec();
86  if (dt < 0.0001)
87  return false; // Interval too small to integrate with
88 
89  timestamp_ = time;
90 
91  linear_ = wheel_radius_ * (1 / drive_motor_gear_ratio_) * drive_motor_vel;
92  angular_ = (1 / steer_motor_gear_ratio_) * steer_motor_vel * (wheel_separation_ / 2.0) * wheel_radius_;
93 
95  integrate_fun_(linear_ * dt, angular_ * dt);
96 
97  return true;
98 }
99 
101 void Odometry::updateOpenLoop(double linear, double angular, const ros::Time &time)
102 {
104  linear_ = linear;
105  angular_ = angular;
106 
108  const double dt = (time - timestamp_).toSec();
109  timestamp_ = time;
110  integrate_fun_(linear * dt, angular * dt);
111 }
112 
114 void Odometry::setWheelsParams(double wheel_radius, double wheel_separation)
115 {
116  wheel_radius_ = wheel_radius;
117  wheel_separation_ = wheel_separation;
118 }
119 
120 
121 void Odometry::setGearRatios(double drive_motor_gear_ratio, double steer_motor_gear_ratio)
122 {
123  drive_motor_gear_ratio_ = drive_motor_gear_ratio;
124  steer_motor_gear_ratio_ = steer_motor_gear_ratio;
125 }
126 
128 void Odometry::integrateExact(double linear, double angular)
129 {
131  heading_ += angular;
132 
136  tf::Vector3 vel_inOdom = R_m_odom * tf::Vector3(linear, 0.0, 0.0);
137 
139  x_ += vel_inOdom.x();
140  y_ += vel_inOdom.y();
141 }
142 
143 } // namespace double_diff_drive_controller
bacc::accumulator_set< double, bacc::stats< bacc::tag::rolling_mean > > RollingMeanAcc
Rolling mean accumulator and window:
Definition: odometry.h:160
IntegrationFunction integrate_fun_
Integration funcion, used to integrate the odometry:
Definition: odometry.h:192
void integrateExact(double linear, double angular)
Integrates the velocities (linear and angular) using exact method.
Definition: odometry.cpp:128
void setGearRatios(double drive_motor_gear_ratio, double steer_motor_gear_ratio)
Sets the gear ratio parameters: gear ratio.
Definition: odometry.cpp:121
double linear_
Current velocity:
Definition: odometry.h:179
The Odometry class handles odometry readings (2D pose and velocity with related timestamp) ...
Definition: odometry.h:60
TFSIMD_FORCE_INLINE const tfScalar & x() const
Odometry(size_t velocity_rolling_window_size=10)
Constructor Timestamp will get the current time value Value will be set to zero.
Definition: odometry.cpp:54
static Quaternion createQuaternionFromYaw(double yaw)
void updateOpenLoop(double linear, double angular, const ros::Time &time)
Updates the odometry class with latest velocity command.
Definition: odometry.cpp:101
TFSIMD_FORCE_INLINE const tfScalar & y() const
ros::Time timestamp_
Current timestamp:
Definition: odometry.h:171
bacc::tag::rolling_window RollingWindow
Definition: odometry.h:161
void init(const ros::Time &time)
Initialize the odometry.
Definition: odometry.cpp:71
void setWheelsParams(double wheel_radius, double wheel_separation)
Sets the wheels parameters: radius and seperation.
Definition: odometry.cpp:114
bool update(double drive_motor_vel, double steer_motor_vel, const ros::Time &time)
Updates the odometry class with latest wheels position.
Definition: odometry.cpp:82
size_t velocity_rolling_window_size_
Rolling mean accumulators for the linar and angular velocities:
Definition: odometry.h:187
double wheel_radius_
Wheels kinematic parameters [m]:
Definition: odometry.h:183


moose_control
Author(s): Tony Baltovski
autogenerated on Wed Mar 10 2021 03:43:55