10#include "units/angular_acceleration.h"
11#include "units/force.h"
12#include "units/moment_of_inertia.h"
13#include "units/torque.h"
34 std::vector<units::newton_t>
x;
36 std::vector<units::newton_t>
y;
50 std::vector<Translation2d> moduleLocations;
51 units::kilogram_t mass;
52 units::kilogram_square_meter_t moi;
64 std::vector<Translation2d> moduleLocations,
65 units::kilogram_t mass,
66 units::kilogram_square_meter_t moi
68 moduleLocations{std::move(moduleLocations)},
85 units::meters_per_second_squared_t ax,
86 units::meters_per_second_squared_t ay,
87 units::radians_per_second_squared_t alpha,
88 Translation2d
const ¢erOfRotation = {}
90 units::newton_t
const fx = ax * mass;
91 units::newton_t
const fy = ay * mass;
92 units::newton_meter_t
const tau = alpha * moi / 1_rad;
94 Feedforwards feedforwards{moduleLocations.size()};
95 for (
size_t i = 0; i < moduleLocations.size(); ++i) {
96 Translation2d
const r = moduleLocations[i] - centerOfRotation;
98 Translation2d
const f_tau{tau / r.Norm() * 1_m/1_N, r.Angle() + Rotation2d{90_deg}};
99 feedforwards.x[i] = (fx + f_tau.X() * 1_N/1_m) / moduleLocations.size();
100 feedforwards.y[i] = (fy + f_tau.Y() * 1_N/1_m) / moduleLocations.size();
119 ChassisSpeeds
const &prev,
120 ChassisSpeeds
const ¤t,
121 Translation2d
const ¢erOfRotation = {}
123 auto const ax = (current.vx - prev.vx) / dt;
124 auto const ay = (current.vy - prev.vy) / dt;
125 auto const alpha = (current.omega - prev.omega) / dt;
126 return Calculate(ax, ay, alpha, centerOfRotation);
Calculates wheel force feedforwards for a SwerveDrivetrain.
Definition WheelForceCalculator.hpp:29
Feedforwards Calculate(units::second_t dt, ChassisSpeeds const &prev, ChassisSpeeds const ¤t, Translation2d const ¢erOfRotation={}) const
Calculates wheel force feedforwards for the desired change in speeds.
Definition WheelForceCalculator.hpp:117
WheelForceCalculator(std::vector< Translation2d > moduleLocations, units::kilogram_t mass, units::kilogram_square_meter_t moi)
Constructs a new wheel force feedforward calculator for the given drivetrain characteristics.
Definition WheelForceCalculator.hpp:63
Feedforwards Calculate(units::meters_per_second_squared_t ax, units::meters_per_second_squared_t ay, units::radians_per_second_squared_t alpha, Translation2d const ¢erOfRotation={}) const
Calculates wheel force feedforwards for the desired robot acceleration.
Definition WheelForceCalculator.hpp:84
Definition motor_constants.h:14
Wheel force feedforwards to apply to a swerve drivetrain.
Definition WheelForceCalculator.hpp:32
std::vector< units::newton_t > x
The X component of the forces in Newtons.
Definition WheelForceCalculator.hpp:34
std::vector< units::newton_t > y
The Y component of the forces in Newtons.
Definition WheelForceCalculator.hpp:36
Feedforwards(size_t numModules)
Constructs a new set of wheel force feedforwards.
Definition WheelForceCalculator.hpp:43