36 const int count = std::max(1, motor_count);
51 const int count = std::max(1, motor_count);
66 const int count = std::max(1, motor_count);
113 : motor_(motor), wheel_(wheel) {}
137 return omega_radps_ * std::max(0.0, wheel_.radius_m);
157 const double effective_nominal_v = std::max(1e-9, motor_.nominal_voltage_v);
158 const double effective_free_speed = std::max(1e-9, motor_.free_speed_radps);
159 const double kt = motor_.stall_torque_nm / effective_nominal_v;
166 voltage = std::clamp(voltage, -effective_nominal_v, effective_nominal_v);
168 if (std::abs(omega_radps_) < 1e-3) {
170 if (std::abs(voltage) <= v_deadband) {
173 voltage = std::copysign(std::max(0.0, std::abs(voltage) - v_deadband),
180 const double voltage_scale = voltage / effective_nominal_v;
181 const double no_load_speed = effective_free_speed * voltage_scale;
182 const double speed_error = no_load_speed - omega_radps_;
183 double available_torque =
184 motor_.stall_torque_nm * speed_error / effective_free_speed;
187 const double torque_per_amp =
188 motor_.stall_torque_nm / motor_.stall_current_a;
189 const double max_torque_from_limit =
191 available_torque = std::clamp(available_torque, -max_torque_from_limit,
192 max_torque_from_limit);
195 const double friction_torque =
196 wheel_.viscous_friction_nm_per_radps * omega_radps_;
197 const double net_torque = available_torque - friction_torque;
199 const double inertia = std::max(1e-9, wheel_.inertia_kgm2);
200 const double alpha_radps2 = net_torque / inertia;
201 omega_radps_ += alpha_radps2 * dt_s;
205 MotorConfig motor_{};
206 WheelConfig wheel_{};
207 double omega_radps_{0.0};
FlywheelWheelSim()=default
void setMotorConfig(const MotorConfig &motor)
Sets motor constants.
Definition shooter_wheel.hpp:116
void setWheelConfig(const WheelConfig &wheel)
Sets wheel constants.
Definition shooter_wheel.hpp:118
double angularSpeedRadps() const
Returns current wheel angular speed.
Definition shooter_wheel.hpp:132
const MotorConfig & motorConfig() const
Returns motor configuration.
Definition shooter_wheel.hpp:122
double surfaceSpeedMps() const
Computes tangential speed at wheel perimeter.
Definition shooter_wheel.hpp:136
const WheelConfig & wheelConfig() const
Returns wheel configuration.
Definition shooter_wheel.hpp:125
void setAngularSpeedRadps(double omega_radps)
Forces internal angular speed state.
Definition shooter_wheel.hpp:129
void step(double dt_s, const ControlInput &control)
Advances the flywheel wheel state by one step.
Definition shooter_wheel.hpp:152
double estimatedExitVelocityMps() const
Estimates ball exit speed from current surface speed and coupling factor.
Definition shooter_wheel.hpp:142
FlywheelWheelSim(const MotorConfig &motor, const WheelConfig &wheel)
Constructs a wheel simulator with explicit motor and wheel configuration.
Definition shooter_wheel.hpp:112
DC motor approximation constants for flywheel drive.
Definition shooter_wheel.hpp:17
double stall_current_a
Definition shooter_wheel.hpp:25
double nominal_voltage_v
Definition shooter_wheel.hpp:28
static MotorConfig falcon500(int motor_count=1)
Returns Falcon 500 aggregate motor constants.
Definition shooter_wheel.hpp:35
double free_speed_radps
Definition shooter_wheel.hpp:19
static MotorConfig neoV1_1(int motor_count=1)
Returns NEO V1.1 aggregate motor constants.
Definition shooter_wheel.hpp:50
double stall_torque_nm
Definition shooter_wheel.hpp:22
static MotorConfig krakenX60(int motor_count=1)
Returns Kraken X60 aggregate motor constants.
Definition shooter_wheel.hpp:65
Flywheel wheel inertial/friction and ball-coupling parameters.
Definition shooter_wheel.hpp:77
double radius_m
Definition shooter_wheel.hpp:78
double viscous_friction_nm_per_radps
Definition shooter_wheel.hpp:80
double ball_coupling
Definition shooter_wheel.hpp:83
double inertia_kgm2
Definition shooter_wheel.hpp:79