mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
SCRIPT namespace replacements
This commit is contained in:
committed by
Peter Johnson
parent
ae6c043632
commit
9aca8e0fd6
@@ -6,21 +6,21 @@
|
||||
|
||||
#include <wpi/math/kinematics/ChassisSpeeds.hpp>
|
||||
|
||||
frc::MecanumDriveWheelSpeeds Drivetrain::GetCurrentState() const {
|
||||
return {units::meters_per_second_t{m_frontLeftEncoder.GetRate()},
|
||||
units::meters_per_second_t{m_frontRightEncoder.GetRate()},
|
||||
units::meters_per_second_t{m_backLeftEncoder.GetRate()},
|
||||
units::meters_per_second_t{m_backRightEncoder.GetRate()}};
|
||||
wpi::math::MecanumDriveWheelSpeeds Drivetrain::GetCurrentState() const {
|
||||
return {wpi::units::meters_per_second_t{m_frontLeftEncoder.GetRate()},
|
||||
wpi::units::meters_per_second_t{m_frontRightEncoder.GetRate()},
|
||||
wpi::units::meters_per_second_t{m_backLeftEncoder.GetRate()},
|
||||
wpi::units::meters_per_second_t{m_backRightEncoder.GetRate()}};
|
||||
}
|
||||
|
||||
frc::MecanumDriveWheelPositions Drivetrain::GetCurrentWheelDistances() const {
|
||||
return {units::meter_t{m_frontLeftEncoder.GetDistance()},
|
||||
units::meter_t{m_frontRightEncoder.GetDistance()},
|
||||
units::meter_t{m_backLeftEncoder.GetDistance()},
|
||||
units::meter_t{m_backRightEncoder.GetDistance()}};
|
||||
wpi::math::MecanumDriveWheelPositions Drivetrain::GetCurrentWheelDistances() const {
|
||||
return {wpi::units::meter_t{m_frontLeftEncoder.GetDistance()},
|
||||
wpi::units::meter_t{m_frontRightEncoder.GetDistance()},
|
||||
wpi::units::meter_t{m_backLeftEncoder.GetDistance()},
|
||||
wpi::units::meter_t{m_backRightEncoder.GetDistance()}};
|
||||
}
|
||||
|
||||
void Drivetrain::SetSpeeds(const frc::MecanumDriveWheelSpeeds& wheelSpeeds) {
|
||||
void Drivetrain::SetSpeeds(const wpi::math::MecanumDriveWheelSpeeds& wheelSpeeds) {
|
||||
const auto frontLeftFeedforward =
|
||||
m_feedforward.Calculate(wheelSpeeds.frontLeft);
|
||||
const auto frontRightFeedforward =
|
||||
@@ -39,21 +39,21 @@ void Drivetrain::SetSpeeds(const frc::MecanumDriveWheelSpeeds& wheelSpeeds) {
|
||||
const double backRightOutput = m_backRightPIDController.Calculate(
|
||||
m_backRightEncoder.GetRate(), wheelSpeeds.rearRight.value());
|
||||
|
||||
m_frontLeftMotor.SetVoltage(units::volt_t{frontLeftOutput} +
|
||||
m_frontLeftMotor.SetVoltage(wpi::units::volt_t{frontLeftOutput} +
|
||||
frontLeftFeedforward);
|
||||
m_frontRightMotor.SetVoltage(units::volt_t{frontRightOutput} +
|
||||
m_frontRightMotor.SetVoltage(wpi::units::volt_t{frontRightOutput} +
|
||||
frontRightFeedforward);
|
||||
m_backLeftMotor.SetVoltage(units::volt_t{backLeftOutput} +
|
||||
m_backLeftMotor.SetVoltage(wpi::units::volt_t{backLeftOutput} +
|
||||
backLeftFeedforward);
|
||||
m_backRightMotor.SetVoltage(units::volt_t{backRightOutput} +
|
||||
m_backRightMotor.SetVoltage(wpi::units::volt_t{backRightOutput} +
|
||||
backRightFeedforward);
|
||||
}
|
||||
|
||||
void Drivetrain::Drive(units::meters_per_second_t xSpeed,
|
||||
units::meters_per_second_t ySpeed,
|
||||
units::radians_per_second_t rot, bool fieldRelative,
|
||||
units::second_t period) {
|
||||
frc::ChassisSpeeds chassisSpeeds{xSpeed, ySpeed, rot};
|
||||
void Drivetrain::Drive(wpi::units::meters_per_second_t xSpeed,
|
||||
wpi::units::meters_per_second_t ySpeed,
|
||||
wpi::units::radians_per_second_t rot, bool fieldRelative,
|
||||
wpi::units::second_t period) {
|
||||
wpi::math::ChassisSpeeds chassisSpeeds{xSpeed, ySpeed, rot};
|
||||
if (fieldRelative) {
|
||||
chassisSpeeds = chassisSpeeds.ToRobotRelative(m_imu.GetRotation2d());
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include "Drivetrain.hpp"
|
||||
|
||||
class Robot : public frc::TimedRobot {
|
||||
class Robot : public wpi::TimedRobot {
|
||||
public:
|
||||
void AutonomousPeriodic() override {
|
||||
DriveWithJoystick(false);
|
||||
@@ -18,14 +18,14 @@ class Robot : public frc::TimedRobot {
|
||||
void TeleopPeriodic() override { DriveWithJoystick(true); }
|
||||
|
||||
private:
|
||||
frc::XboxController m_controller{0};
|
||||
wpi::XboxController m_controller{0};
|
||||
Drivetrain m_mecanum;
|
||||
|
||||
// Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0
|
||||
// to 1.
|
||||
frc::SlewRateLimiter<units::scalar> m_xspeedLimiter{3 / 1_s};
|
||||
frc::SlewRateLimiter<units::scalar> m_yspeedLimiter{3 / 1_s};
|
||||
frc::SlewRateLimiter<units::scalar> m_rotLimiter{3 / 1_s};
|
||||
wpi::math::SlewRateLimiter<wpi::units::scalar> m_xspeedLimiter{3 / 1_s};
|
||||
wpi::math::SlewRateLimiter<wpi::units::scalar> m_yspeedLimiter{3 / 1_s};
|
||||
wpi::math::SlewRateLimiter<wpi::units::scalar> m_rotLimiter{3 / 1_s};
|
||||
|
||||
void DriveWithJoystick(bool fieldRelative) {
|
||||
// Get the x speed. We are inverting this because Xbox controllers return
|
||||
@@ -52,6 +52,6 @@ class Robot : public frc::TimedRobot {
|
||||
|
||||
#ifndef RUNNING_FRC_TESTS
|
||||
int main() {
|
||||
return frc::StartRobot<Robot>();
|
||||
return wpi::StartRobot<Robot>();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -30,50 +30,50 @@ class Drivetrain {
|
||||
m_backRightMotor.SetInverted(true);
|
||||
}
|
||||
|
||||
frc::MecanumDriveWheelSpeeds GetCurrentState() const;
|
||||
frc::MecanumDriveWheelPositions GetCurrentWheelDistances() const;
|
||||
void SetSpeeds(const frc::MecanumDriveWheelSpeeds& wheelSpeeds);
|
||||
void Drive(units::meters_per_second_t xSpeed,
|
||||
units::meters_per_second_t ySpeed, units::radians_per_second_t rot,
|
||||
bool fieldRelative, units::second_t period);
|
||||
wpi::math::MecanumDriveWheelSpeeds GetCurrentState() const;
|
||||
wpi::math::MecanumDriveWheelPositions GetCurrentWheelDistances() const;
|
||||
void SetSpeeds(const wpi::math::MecanumDriveWheelSpeeds& wheelSpeeds);
|
||||
void Drive(wpi::units::meters_per_second_t xSpeed,
|
||||
wpi::units::meters_per_second_t ySpeed, wpi::units::radians_per_second_t rot,
|
||||
bool fieldRelative, wpi::units::second_t period);
|
||||
void UpdateOdometry();
|
||||
|
||||
static constexpr units::meters_per_second_t kMaxSpeed =
|
||||
static constexpr wpi::units::meters_per_second_t kMaxSpeed =
|
||||
3.0_mps; // 3 meters per second
|
||||
static constexpr units::radians_per_second_t kMaxAngularSpeed{
|
||||
static constexpr wpi::units::radians_per_second_t kMaxAngularSpeed{
|
||||
std::numbers::pi}; // 1/2 rotation per second
|
||||
|
||||
private:
|
||||
frc::PWMSparkMax m_frontLeftMotor{1};
|
||||
frc::PWMSparkMax m_frontRightMotor{2};
|
||||
frc::PWMSparkMax m_backLeftMotor{3};
|
||||
frc::PWMSparkMax m_backRightMotor{4};
|
||||
wpi::PWMSparkMax m_frontLeftMotor{1};
|
||||
wpi::PWMSparkMax m_frontRightMotor{2};
|
||||
wpi::PWMSparkMax m_backLeftMotor{3};
|
||||
wpi::PWMSparkMax m_backRightMotor{4};
|
||||
|
||||
frc::Encoder m_frontLeftEncoder{0, 1};
|
||||
frc::Encoder m_frontRightEncoder{2, 3};
|
||||
frc::Encoder m_backLeftEncoder{4, 5};
|
||||
frc::Encoder m_backRightEncoder{6, 7};
|
||||
wpi::Encoder m_frontLeftEncoder{0, 1};
|
||||
wpi::Encoder m_frontRightEncoder{2, 3};
|
||||
wpi::Encoder m_backLeftEncoder{4, 5};
|
||||
wpi::Encoder m_backRightEncoder{6, 7};
|
||||
|
||||
frc::Translation2d m_frontLeftLocation{0.381_m, 0.381_m};
|
||||
frc::Translation2d m_frontRightLocation{0.381_m, -0.381_m};
|
||||
frc::Translation2d m_backLeftLocation{-0.381_m, 0.381_m};
|
||||
frc::Translation2d m_backRightLocation{-0.381_m, -0.381_m};
|
||||
wpi::math::Translation2d m_frontLeftLocation{0.381_m, 0.381_m};
|
||||
wpi::math::Translation2d m_frontRightLocation{0.381_m, -0.381_m};
|
||||
wpi::math::Translation2d m_backLeftLocation{-0.381_m, 0.381_m};
|
||||
wpi::math::Translation2d m_backRightLocation{-0.381_m, -0.381_m};
|
||||
|
||||
frc::PIDController m_frontLeftPIDController{1.0, 0.0, 0.0};
|
||||
frc::PIDController m_frontRightPIDController{1.0, 0.0, 0.0};
|
||||
frc::PIDController m_backLeftPIDController{1.0, 0.0, 0.0};
|
||||
frc::PIDController m_backRightPIDController{1.0, 0.0, 0.0};
|
||||
wpi::math::PIDController m_frontLeftPIDController{1.0, 0.0, 0.0};
|
||||
wpi::math::PIDController m_frontRightPIDController{1.0, 0.0, 0.0};
|
||||
wpi::math::PIDController m_backLeftPIDController{1.0, 0.0, 0.0};
|
||||
wpi::math::PIDController m_backRightPIDController{1.0, 0.0, 0.0};
|
||||
|
||||
frc::OnboardIMU m_imu{frc::OnboardIMU::kFlat};
|
||||
wpi::OnboardIMU m_imu{wpi::OnboardIMU::kFlat};
|
||||
|
||||
frc::MecanumDriveKinematics m_kinematics{
|
||||
wpi::math::MecanumDriveKinematics m_kinematics{
|
||||
m_frontLeftLocation, m_frontRightLocation, m_backLeftLocation,
|
||||
m_backRightLocation};
|
||||
|
||||
frc::MecanumDriveOdometry m_odometry{m_kinematics, m_imu.GetRotation2d(),
|
||||
wpi::math::MecanumDriveOdometry m_odometry{m_kinematics, m_imu.GetRotation2d(),
|
||||
GetCurrentWheelDistances()};
|
||||
|
||||
// Gains are for example purposes only - must be determined for your own
|
||||
// robot!
|
||||
frc::SimpleMotorFeedforward<units::meters> m_feedforward{1_V, 3_V / 1_mps};
|
||||
wpi::math::SimpleMotorFeedforward<wpi::units::meters> m_feedforward{1_V, 3_V / 1_mps};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user