Program Listing for File odometry.hpp
↰ Return to documentation for file (include/diff_drive_controller/odometry.hpp
)
// Copyright 2020 PAL Robotics S.L.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* Author: Luca Marchionni
* Author: Bence Magyar
* Author: Enrique Fernández
* Author: Paul Mathieu
*/
#ifndef DIFF_DRIVE_CONTROLLER__ODOMETRY_HPP_
#define DIFF_DRIVE_CONTROLLER__ODOMETRY_HPP_
#include <cmath>
#include "rclcpp/time.hpp"
#include "rcpputils/rolling_mean_accumulator.hpp"
namespace diff_drive_controller
{
class Odometry
{
public:
explicit Odometry(size_t velocity_rolling_window_size = 10);
void init(const rclcpp::Time & time);
bool update(double left_pos, double right_pos, const rclcpp::Time & time);
bool updateFromVelocity(double left_vel, double right_vel, const rclcpp::Time & time);
void updateOpenLoop(double linear, double angular, const rclcpp::Time & time);
void resetOdometry();
double getX() const { return x_; }
double getY() const { return y_; }
double getHeading() const { return heading_; }
double getLinear() const { return linear_; }
double getAngular() const { return angular_; }
void setWheelParams(double wheel_separation, double left_wheel_radius, double right_wheel_radius);
void setVelocityRollingWindowSize(size_t velocity_rolling_window_size);
private:
using RollingMeanAccumulator = rcpputils::RollingMeanAccumulator<double>;
void integrateRungeKutta2(double linear, double angular);
void integrateExact(double linear, double angular);
void resetAccumulators();
// Current timestamp:
rclcpp::Time timestamp_;
// Current pose:
double x_; // [m]
double y_; // [m]
double heading_; // [rad]
// Current velocity:
double linear_; // [m/s]
double angular_; // [rad/s]
// Wheel kinematic parameters [m]:
double wheel_separation_;
double left_wheel_radius_;
double right_wheel_radius_;
// Previous wheel position/state [rad]:
double left_wheel_old_pos_;
double right_wheel_old_pos_;
// Rolling mean accumulators for the linear and angular velocities:
size_t velocity_rolling_window_size_;
RollingMeanAccumulator linear_accumulator_;
RollingMeanAccumulator angular_accumulator_;
};
} // namespace diff_drive_controller
#endif // DIFF_DRIVE_CONTROLLER__ODOMETRY_HPP_