libstp
Robotics library for Botball
Loading...
Searching...
No Matches
mecanum.hpp
Go to the documentation of this file.
1#pragma once
5#include "hal/IMotor.hpp"
6#include <array>
7#include <vector>
8
10{
18 {
19 private:
20 double m_wheelbase;
21 double m_trackWidth;
22 double m_wheelRadius;
23 double m_maxWheelSpeed{0.0}; // 0 = no limiting
24
25 // Per-axis velocity-command gain [vx, vy, wz]; folded into fwd_matrix in
26 // getStmOdometryConfig() to compensate drivetrain efficiency (e.g.
27 // mecanum roller slip). Calibrated by the autotune velocity phase.
28 std::array<double, 3> m_velCmdGain{1.0, 1.0, 1.0};
29
30 drive::MotorAdapter front_left_motor_;
31 drive::MotorAdapter front_right_motor_;
32 drive::MotorAdapter back_left_motor_;
33 drive::MotorAdapter back_right_motor_;
34
35 public:
50 hal::motor::IMotor* front_right_motor,
51 hal::motor::IMotor* back_left_motor,
52 hal::motor::IMotor* back_right_motor,
53 double wheelbase,
54 double trackWidth,
55 double wheelRadius,
56 foundation::VelocityCommandGain velocityCommandGain = {});
57 ~MecanumKinematics() override = default;
58
60 [[nodiscard]] std::size_t wheelCount() const override;
61
64
66 [[nodiscard]] foundation::ChassisVelocity estimateState() const override;
67
69 void hardStop() override;
70
72 [[nodiscard]] bool supportsLateralMotion() const override;
73
75 void resetEncoders() override;
76
77 [[nodiscard]] double getWheelRadius() const override { return m_wheelRadius; }
78
80 void setMaxWheelSpeed(double max_wheel_speed) { m_maxWheelSpeed = max_wheel_speed; }
81 [[nodiscard]] double getMaxWheelSpeed() const { return m_maxWheelSpeed; }
82
89 [[nodiscard]] double maxYawRateForArcRadius(double radius_m,
90 bool /*lateral*/) const override
91 {
92 if (m_maxWheelSpeed <= 0.0)
93 return std::numeric_limits<double>::infinity();
94 const double lever = 0.5 * (m_wheelbase + m_trackWidth);
95 const double max_wheel_mps = m_maxWheelSpeed * m_wheelRadius;
96 return max_wheel_mps / (radius_m + lever);
97 }
98
100 [[nodiscard]] std::vector<hal::motor::IMotor*> getMotors() override;
101
102 [[nodiscard]] StmOdometryConfig getStmOdometryConfig() override;
103
105 void setVelocityCommandGains(double gx, double gy, double gw) override;
106 [[nodiscard]] std::array<double, 3> getVelocityCommandGains() const override;
107
110 int power_percent) override;
111 };
112}
std::size_t wheelCount() const override
void applyPowerCommand(const foundation::ChassisVelocity &direction, int power_percent) override
MecanumKinematics(hal::motor::IMotor *front_left_motor, hal::motor::IMotor *front_right_motor, hal::motor::IMotor *back_left_motor, hal::motor::IMotor *back_right_motor, double wheelbase, double trackWidth, double wheelRadius, foundation::VelocityCommandGain velocityCommandGain={})
std::vector< hal::motor::IMotor * > getMotors() override
foundation::ChassisVelocity estimateState() const override
MotorCommands applyCommand(const foundation::ChassisVelocity &cmd, double dt) override
void setMaxWheelSpeed(double max_wheel_speed)
Definition mecanum.hpp:80
void setVelocityCommandGains(double gx, double gy, double gw) override
std::array< double, 3 > getVelocityCommandGains() const override
StmOdometryConfig getStmOdometryConfig() override
double maxYawRateForArcRadius(double radius_m, bool) const override
Definition mecanum.hpp:89
double getWheelRadius() const override
Get the wheel radius used by this kinematics model.
Definition mecanum.hpp:77
Interface for motor abstraction.
Definition IMotor.hpp:17