justinT21 | 446e4f6 | 2024-06-16 22:36:10 -0700 | [diff] [blame] | 1 | #ifndef FRC971_CONTROL_LOOPS_SWERVE_MOTORS_ |
| 2 | #define FRC971_CONTROL_LOOPS_SWERVE_MOTORS_ |
| 3 | |
| 4 | #include <numbers> |
| 5 | |
| 6 | namespace frc971::control_loops::swerve { |
| 7 | |
| 8 | // Class holding the physical parameters for a motor. |
| 9 | struct Motor { |
| 10 | constexpr Motor(double stall_torque, double stall_current, double free_speed, |
| 11 | double free_current, double motor_inertia) |
| 12 | : stall_torque(stall_torque), |
| 13 | stall_current(stall_current), |
| 14 | free_speed(free_speed), |
| 15 | free_current(free_current), |
| 16 | resistance(12 / stall_current), |
| 17 | Kv(free_speed / (12 - resistance * free_current)), |
| 18 | Kt(stall_torque / stall_current), |
| 19 | motor_inertia(motor_inertia) {} |
| 20 | // Stall Torque in Nm |
| 21 | double stall_torque; |
| 22 | // Stall Current in Amps |
| 23 | double stall_current; |
| 24 | // Free Speed in rad / sec |
| 25 | double free_speed; |
| 26 | // Free Current in Amps |
| 27 | double free_current; |
| 28 | // Resistance of the motor, divided by 2 to account for the 2 motors |
| 29 | double resistance; |
| 30 | // Motor velocity constant |
| 31 | double Kv; |
| 32 | // Torque constant |
| 33 | double Kt; |
| 34 | // Motor inertia in kg m^2 |
| 35 | // Diameter of 1.9", weight of: 100 grams |
| 36 | // TODO(Filip/Justin): Update motor inertia for Kraken, currently using Falcon |
| 37 | // motor inertia |
| 38 | double motor_inertia; |
| 39 | }; |
| 40 | |
| 41 | // Struct representing the WCP Kraken X60 motor using |
| 42 | // Field Oriented Controls (FOC) communication. |
| 43 | // |
| 44 | // All numbers based on data from |
| 45 | // https://wcproducts.com/products/kraken. |
| 46 | constexpr Motor KrakenFOC() { |
| 47 | return Motor{9.37, 483.0, 5800.0 / 60.0 * 2.0 * std::numbers::pi, 2.0, |
| 48 | 0.1 * (0.95 * 0.0254) * (0.95 * 0.0254)}; |
| 49 | }; |
| 50 | } // namespace frc971::control_loops::swerve |
| 51 | |
| 52 | #endif // FRC971_CONTROL_LOOPS_SWERVE_MOTORS_ |