18#ifndef STEERING_CONTROLLERS_LIBRARY__STEERING_ODOMETRY_HPP_
19#define STEERING_CONTROLLERS_LIBRARY__STEERING_ODOMETRY_HPP_
25#include <rclcpp/time.hpp>
26#include "rcppmath/rolling_mean_accumulator.hpp"
28namespace steering_odometry
30const unsigned int BICYCLE_CONFIG = 0;
31const unsigned int TRICYCLE_CONFIG = 1;
32const unsigned int ACKERMANN_CONFIG = 2;
34inline bool is_close_to_zero(
double val) {
return std::fabs(val) < 1e-6; }
56 void init(
const rclcpp::Time & time);
66 const double traction_wheel_pos,
const double steer_pos,
const double dt);
77 const double right_traction_wheel_pos,
const double left_traction_wheel_pos,
78 const double steer_pos,
const double dt);
90 const double right_traction_wheel_pos,
const double left_traction_wheel_pos,
91 const double right_steer_pos,
const double left_steer_pos,
const double dt);
101 const double traction_wheel_vel,
const double steer_pos,
const double dt);
112 const double right_traction_wheel_vel,
const double left_traction_wheel_vel,
113 const double steer_pos,
const double dt);
125 const double right_traction_wheel_vel,
const double left_traction_wheel_vel,
126 const double right_steer_pos,
const double left_steer_pos,
const double dt);
134 void update_open_loop(
const double v_bx,
const double omega_bz,
const double dt);
176 const double wheel_radius,
const double wheelbase = 0.0,
const double wheel_track = 0.0);
193 std::tuple<std::vector<double>, std::vector<double>>
get_commands(
194 const double v_bx,
const double omega_bz,
const bool open_loop =
true,
195 const bool reduce_wheel_speed_until_steering_reached =
false);
209 bool update_odometry(
const double v_bx,
const double omega_bz,
const double dt);
217 void integrate_runge_kutta_2(
const double v_bx,
const double omega_bz,
const double dt);
225 void integrate_fk(
const double v_bx,
const double omega_bz,
const double dt);
232 double convert_twist_to_steering_angle(
const double v_bx,
const double omega_bz);
240 double get_linear_velocity_double_traction_axle(
241 const double right_traction_wheel_vel,
const double left_traction_wheel_vel,
242 const double steer_pos);
247 void reset_accumulators();
250 rclcpp::Time timestamp_;
265 double wheel_radius_;
268 int config_type_ = -1;
271 double traction_wheel_old_pos_;
272 double traction_right_wheel_old_pos_;
273 double traction_left_wheel_old_pos_;
275 size_t velocity_rolling_window_size_;
276 rcppmath::RollingMeanAccumulator<double> linear_acc_;
277 rcppmath::RollingMeanAccumulator<double> angular_acc_;
The Odometry class handles odometry readings (2D pose and velocity with related timestamp)
Definition steering_odometry.hpp:41
double get_heading() const
heading getter
Definition steering_odometry.hpp:146
std::tuple< std::vector< double >, std::vector< double > > get_commands(const double v_bx, const double omega_bz, const bool open_loop=true, const bool reduce_wheel_speed_until_steering_reached=false)
Calculates inverse kinematics for the desired linear and angular velocities.
Definition steering_odometry.cpp:220
bool update_from_position(const double traction_wheel_pos, const double steer_pos, const double dt)
Updates the odometry class with latest wheels position.
Definition steering_odometry.cpp:76
void set_wheel_params(const double wheel_radius, const double wheelbase=0.0, const double wheel_track=0.0)
Sets the wheel parameters: radius, separation and wheelbase.
Definition steering_odometry.cpp:194
double get_linear() const
linear velocity getter
Definition steering_odometry.hpp:164
double get_angular() const
angular velocity getter
Definition steering_odometry.hpp:170
double get_x() const
x position getter
Definition steering_odometry.hpp:152
void set_velocity_rolling_window_size(const size_t velocity_rolling_window_size)
Velocity rolling window size setter.
Definition steering_odometry.cpp:201
void update_open_loop(const double v_bx, const double omega_bz, const double dt)
Updates the odometry class with latest velocity command.
Definition steering_odometry.cpp:184
bool update_from_velocity(const double traction_wheel_vel, const double steer_pos, const double dt)
Updates the odometry class with latest wheels position.
Definition steering_odometry.cpp:122
double get_y() const
y position getter
Definition steering_odometry.hpp:158
void reset_odometry()
Reset poses, heading, and accumulators.
Definition steering_odometry.cpp:335
void init(const rclcpp::Time &time)
Initialize the odometry.
Definition steering_odometry.cpp:47
void set_odometry_type(const unsigned int type)
Set odometry type.
Definition steering_odometry.cpp:208