ros2_control - foxy
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, Borong Yuan
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 "tricycle_controller/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::Time & time);
35 void updateOpenLoop(double linear, double angular, const rclcpp::Time & time);
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:
49
50 void integrateRungeKutta2(double linear, double angular);
51 void integrateExact(double linear, double angular);
52 void resetAccumulators();
53
54 // Current timestamp:
55 rclcpp::Time timestamp_;
56
57 // Current pose:
58 double x_; // [m]
59 double y_; // [m]
60 double heading_; // [rad]
61
62 // Current velocity:
63 double linear_; // [m/s]
64 double angular_; // [rad/s]
65
66 // Wheel kinematic parameters [m]:
67 double wheelbase_;
68 double wheel_radius_;
69
70 // Rolling mean accumulators for the linear and angular velocities:
71 size_t velocity_rolling_window_size_;
72 RollingMeanAccumulator linear_accumulator_;
73 RollingMeanAccumulator angular_accumulator_;
74};
75
76} // namespace tricycle_controller
77
78#endif // TRICYCLE_CONTROLLER__ODOMETRY_HPP_
Definition odometry.hpp:30
void updateOpenLoop(double linear, double angular, const rclcpp::Time &time)
Definition odometry.cpp:62
Simplification of boost::accumulators::accumulator_set<double, bacc::stats<bacc::tag::rolling_mean>> ...
Definition rolling_mean_accumulator.hpp:35