Skip to content

Commit

Permalink
Add Swerve Setpoint Generator to PPLib C++
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis-Leyva committed Dec 11, 2024
1 parent 574bc49 commit bfdec18
Show file tree
Hide file tree
Showing 5 changed files with 586 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,30 @@ frc::ChassisSpeeds RobotConfig::toChassisSpeeds(
}
}

frc::ChassisSpeeds RobotConfig::toChassisSpeeds(
std::vector<frc::SwerveModuleState> states) const {
if (isHolonomic) {
wpi::array < frc::SwerveModuleState, 4 > wpiStates { states.at(0),
states.at(1), states.at(2), states.at(3) };
return swerveKinematics.ToChassisSpeeds(wpiStates);
} else {
frc::DifferentialDriveWheelSpeeds wheelSpeeds { states.at(0).speed,
states.at(1).speed };
return diffKinematics.ToChassisSpeeds(wheelSpeeds);
}
}

std::vector<frc::SwerveModuleState> RobotConfig::desaturateWheelSpeeds(
std::vector<frc::SwerveModuleState> moduleStates,
units::meters_per_second_t maxSpeed) const {
wpi::array < frc::SwerveModuleState, 4 > wpiStates { moduleStates.at(0),
moduleStates.at(1), moduleStates.at(2), moduleStates.at(3) };
swerveKinematics.DesaturateWheelSpeeds(&wpiStates, maxSpeed);

return std::vector < frc::SwerveModuleState
> (wpiStates.begin(), wpiStates.end());
}

std::vector<frc::Translation2d> RobotConfig::chassisForcesToWheelForceVectors(
frc::ChassisSpeeds chassisForces) const {
Eigen::Vector3d chassisForceVector { chassisForces.vx.value(),
Expand Down
Loading

0 comments on commit bfdec18

Please sign in to comment.