ros2_control - humble
Loading...
Searching...
No Matches
odometry.hpp
1// Copyright 2022 Pixel Robotics.
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: Tony Najjar
17 */
18
19#ifndef TRICYCLE_CONTROLLER__ODOMETRY_HPP_
20#define TRICYCLE_CONTROLLER__ODOMETRY_HPP_
21
22#include <cmath>
23
24#include "rclcpp/time.hpp"
25#include "rcppmath/rolling_mean_accumulator.hpp"
26
27namespace tricycle_controller
28{
30{
31public:
32 explicit Odometry(size_t velocity_rolling_window_size = 10);
33
34 bool update(double left_vel, double right_vel, const rclcpp::Duration & dt);
35 void updateOpenLoop(double linear, double angular, const rclcpp::Duration & dt);
36 void resetOdometry();
37
38 double getX() const { return x_; }
39 double getY() const { return y_; }
40 double getHeading() const { return heading_; }
41 double getLinear() const { return linear_; }
42 double getAngular() const { return angular_; }
43
44 void setWheelParams(double wheel_separation, double wheel_radius);
45 void setVelocityRollingWindowSize(size_t velocity_rolling_window_size);
46
47private:
48 using RollingMeanAccumulator = rcppmath::RollingMeanAccumulator<double>;
49
50 void integrateRungeKutta2(double linear, double angular);
51 void integrateExact(double linear, double angular);
52 void resetAccumulators();
53
54 // Current pose:
55 double x_; // [m]
56 double y_; // [m]
57 double heading_; // [rad]
58
59 // Current velocity:
60 double linear_; // [m/s]
61 double angular_; // [rad/s]
62
63 // Wheel kinematic parameters [m]:
64 double wheelbase_;
65 double wheel_radius_;
66
67 // Rolling mean accumulators for the linear and angular velocities:
68 size_t velocity_rolling_window_size_;
69 RollingMeanAccumulator linear_accumulator_;
70 RollingMeanAccumulator angular_accumulator_;
71};
72
73} // namespace tricycle_controller
74
75#endif // TRICYCLE_CONTROLLER__ODOMETRY_HPP_
Definition odometry.hpp:30
void updateOpenLoop(double linear, double angular, const rclcpp::Duration &dt)
Definition odometry.cpp:57