libstp
Robotics library for Botball
Loading...
Searching...
No Matches
angle_utils.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Eigen/Geometry>
4#include <cmath>
5
6namespace libstp {
7namespace odometry {
8
9inline double wrapAngle(double angle_rad) {
10 double wrapped = std::fmod(angle_rad + M_PI, 2.0 * M_PI);
11 if (wrapped < 0.0) {
12 wrapped += 2.0 * M_PI;
13 }
14 return wrapped - M_PI;
15}
16
17inline double angularError(double current_rad, double target_rad) {
18 return wrapAngle(target_rad - current_rad);
19}
20
21inline double extractHeading(const Eigen::Quaternionf& orientation) {
22 const Eigen::Vector3f forward = orientation.normalized() * Eigen::Vector3f::UnitX();
23 return std::atan2(static_cast<double>(forward.y()),
24 static_cast<double>(forward.x()));
25}
26
27} // namespace odometry
28} // namespace libstp
double angularError(double current_rad, double target_rad)
double wrapAngle(double angle_rad)
double extractHeading(const Eigen::Quaternionf &orientation)