libstp
Robotics library for Botball
Loading...
Searching...
No Matches
drive.hpp
Go to the documentation of this file.
1#pragma once
2#include <memory>
3#include <vector>
4
9#include "hal/IMotor.hpp"
10
11namespace libstp::hal::imu { struct IIMU; }
12
14{
17 foundation::PidGains pid{0.0, 0.0, 0.0};
18 foundation::Feedforward ff{0.0, 1.0, 0.0}; // kV=1.0 = passthrough
19 };
20
27
35 class Drive final
36 {
37 public:
43 Drive(std::unique_ptr<kinematics::IKinematics> kinematics,
44 const ChassisVelocityControlConfig& vel_config,
45 hal::imu::IIMU& imu);
46
49
52
55
57 [[nodiscard]] std::size_t wheelCount() const;
58
60 void softStop();
61
63 void hardStop();
64
67 [[nodiscard]] const ChassisVelocityControlConfig& getVelocityControlConfig() const { return vel_ctrl_config_; }
68
71
73 [[nodiscard]] kinematics::IKinematics& getKinematics() { return *kinematics_; }
74 [[nodiscard]] const kinematics::IKinematics& getKinematics() const { return *kinematics_; }
75
77 [[nodiscard]] double getWheelRadius() const { return kinematics_->getWheelRadius(); }
78
80 [[nodiscard]] std::vector<hal::motor::IMotor*> getMotors() { return kinematics_->getMotors(); }
81
84 [[nodiscard]] hal::imu::IIMU& getImu() { return imu_; }
85 [[nodiscard]] const hal::imu::IIMU& getImu() const { return imu_; }
86
88 void applyPowerCommand(const foundation::ChassisVelocity& direction, int power_percent)
89 { kinematics_->applyPowerCommand(direction, power_percent); }
90
91 private:
92 void initControllers();
93
94 std::unique_ptr<kinematics::IKinematics> kinematics_;
95
97
98 // Velocity control
99 ChassisVelocityControlConfig vel_ctrl_config_{};
100 hal::imu::IIMU& imu_;
101
102 VelocityController ctrl_vx_;
103 VelocityController ctrl_vy_;
104 VelocityController ctrl_wz_;
105
106 // Last gyro wz reading for estimateState()
107 float last_gyro_wz_{0.0f};
108 };
109}
kinematics::MotorCommands update(double dt)
kinematics::IKinematics & getKinematics()
Definition drive.hpp:73
std::size_t wheelCount() const
hal::imu::IIMU & getImu()
Definition drive.hpp:84
void resetVelocityControllers()
const kinematics::IKinematics & getKinematics() const
Definition drive.hpp:74
std::vector< hal::motor::IMotor * > getMotors()
Definition drive.hpp:80
double getWheelRadius() const
Definition drive.hpp:77
Drive(std::unique_ptr< kinematics::IKinematics > kinematics, const ChassisVelocityControlConfig &vel_config, hal::imu::IIMU &imu)
const ChassisVelocityControlConfig & getVelocityControlConfig() const
Definition drive.hpp:67
void applyPowerCommand(const foundation::ChassisVelocity &direction, int power_percent)
Definition drive.hpp:88
void setVelocityControlConfig(const ChassisVelocityControlConfig &config)
void setVelocity(const foundation::ChassisVelocity &v_body)
foundation::ChassisVelocity estimateState() const
const hal::imu::IIMU & getImu() const
Definition drive.hpp:85
Feedforward terms for velocity and acceleration control.
Definition motor.hpp:24
Basic PID gains without integrator and output shaping parameters.
Definition motor.hpp:18
Interface for IMU abstraction.
Definition IIMU.hpp:97