ros2_control - galactic
Loading...
Searching...
No Matches
ros2_controllers
diff_drive_controller
include
diff_drive_controller
odometry.hpp
1
// Copyright 2020 PAL Robotics S.L.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
/*
16
* Author: Luca Marchionni
17
* Author: Bence Magyar
18
* Author: Enrique Fernández
19
* Author: Paul Mathieu
20
*/
21
22
#ifndef DIFF_DRIVE_CONTROLLER__ODOMETRY_HPP_
23
#define DIFF_DRIVE_CONTROLLER__ODOMETRY_HPP_
24
25
#include <cmath>
26
27
#include "diff_drive_controller/rolling_mean_accumulator.hpp"
28
#include "rclcpp/time.hpp"
29
30
namespace
diff_drive_controller
31
{
32
class
Odometry
33
{
34
public
:
35
explicit
Odometry
(
size_t
velocity_rolling_window_size = 10);
36
37
void
init(
const
rclcpp::Time & time);
38
bool
update(
double
left_pos,
double
right_pos,
const
rclcpp::Time & time);
39
bool
updateFromVelocity(
double
left_vel,
double
right_vel,
const
rclcpp::Time & time);
40
void
updateOpenLoop
(
double
linear,
double
angular,
const
rclcpp::Time & time);
41
void
resetOdometry();
42
43
double
getX()
const
{
return
x_; }
44
double
getY()
const
{
return
y_; }
45
double
getHeading()
const
{
return
heading_; }
46
double
getLinear()
const
{
return
linear_; }
47
double
getAngular()
const
{
return
angular_; }
48
49
void
setWheelParams(
double
wheel_separation,
double
left_wheel_radius,
double
right_wheel_radius);
50
void
setVelocityRollingWindowSize(
size_t
velocity_rolling_window_size);
51
52
private
:
53
using
RollingMeanAccumulator
=
diff_drive_controller::RollingMeanAccumulator<double>
;
54
55
void
integrateRungeKutta2(
double
linear,
double
angular);
56
void
integrateExact(
double
linear,
double
angular);
57
void
resetAccumulators();
58
59
// Current timestamp:
60
rclcpp::Time timestamp_;
61
62
// Current pose:
63
double
x_;
// [m]
64
double
y_;
// [m]
65
double
heading_;
// [rad]
66
67
// Current velocity:
68
double
linear_;
// [m/s]
69
double
angular_;
// [rad/s]
70
71
// Wheel kinematic parameters [m]:
72
double
wheel_separation_;
73
double
left_wheel_radius_;
74
double
right_wheel_radius_;
75
76
// Previous wheel position/state [rad]:
77
double
left_wheel_old_pos_;
78
double
right_wheel_old_pos_;
79
80
// Rolling mean accumulators for the linear and angular velocities:
81
size_t
velocity_rolling_window_size_;
82
RollingMeanAccumulator
linear_accumulator_;
83
RollingMeanAccumulator
angular_accumulator_;
84
};
85
86
}
// namespace diff_drive_controller
87
88
#endif
// DIFF_DRIVE_CONTROLLER__ODOMETRY_HPP_
diff_drive_controller::Odometry
Definition
odometry.hpp:33
diff_drive_controller::Odometry::updateOpenLoop
void updateOpenLoop(double linear, double angular, const rclcpp::Time &time)
Definition
odometry.cpp:98
diff_drive_controller::RollingMeanAccumulator< double >
Generated by
1.9.8