libstp
Robotics library for Botball
Loading...
Searching...
No Matches
kinematics.hpp
Go to the documentation of this file.
1#pragma once
2#include <array>
3#include <cstddef>
4#include <limits>
5#include <vector>
6
8#include "hal/IMotor.hpp"
9
10namespace libstp::kinematics
11{
20 {
21 std::vector<double> wheel_velocities{};
22 bool saturated_any{false};
23 std::uint32_t saturation_mask{0};
24 };
25
35 {
36 virtual ~IKinematics() = default;
37
39 [[nodiscard]] virtual std::size_t wheelCount() const = 0;
40
54 [[nodiscard]] virtual double maxYawRateForArcRadius(double /*radius_m*/,
55 bool /*lateral*/) const
56 {
57 return std::numeric_limits<double>::infinity();
58 }
59
68 virtual MotorCommands applyCommand(const foundation::ChassisVelocity& cmd, double dt) = 0;
69
76 [[nodiscard]] virtual foundation::ChassisVelocity estimateState() const = 0;
77
79 virtual void hardStop() = 0;
80
86 [[nodiscard]] virtual bool supportsLateralMotion() const = 0;
87
94 virtual void resetEncoders() = 0;
95
100 [[nodiscard]] virtual double getWheelRadius() const = 0;
101
110 [[nodiscard]] virtual std::vector<hal::motor::IMotor*> getMotors() = 0;
111
124 {
125 std::array<std::array<float, 4>, 3> inv_matrix{};
126 std::array<float, 4> ticks_to_rad{};
127 std::array<std::array<float, 3>, 4> fwd_matrix{};
128 std::array<float, 4> bemf_offset{};
129 };
130
131 // Non-const: needs to look up motor handles via getMotors() to
132 // reorder kinematics-slot data into hardware-port order.
133 [[nodiscard]] virtual StmOdometryConfig getStmOdometryConfig() = 0;
134
148 virtual void setVelocityCommandGains(double /*gx*/, double /*gy*/, double /*gw*/) {}
149 [[nodiscard]] virtual std::array<double, 3> getVelocityCommandGains() const
150 {
151 return {1.0, 1.0, 1.0};
152 }
153
174 virtual void applyPowerCommand(const foundation::ChassisVelocity& direction,
175 int power_percent) = 0;
176 };
177}
std::array< std::array< float, 4 >, 3 > inv_matrix
std::array< std::array< float, 3 >, 4 > fwd_matrix
virtual ~IKinematics()=default
virtual double getWheelRadius() const =0
Get the wheel radius used by this kinematics model.
virtual double maxYawRateForArcRadius(double, bool) const
virtual MotorCommands applyCommand(const foundation::ChassisVelocity &cmd, double dt)=0
virtual foundation::ChassisVelocity estimateState() const =0
virtual bool supportsLateralMotion() const =0
Query whether this kinematics model supports direct lateral (vy) motion.
virtual std::array< double, 3 > getVelocityCommandGains() const
virtual std::vector< hal::motor::IMotor * > getMotors()=0
Get pointers to all drive motors managed by this kinematics model.
virtual void resetEncoders()=0
Reset encoder/BEMF counters to prepare for new odometry origin.
virtual StmOdometryConfig getStmOdometryConfig()=0
virtual void applyPowerCommand(const foundation::ChassisVelocity &direction, int power_percent)=0
virtual std::size_t wheelCount() const =0
virtual void setVelocityCommandGains(double, double, double)
std::vector< double > wheel_velocities