SCRIPT namespace replacements

This commit is contained in:
PJ Reiniger
2025-11-07 20:00:05 -05:00
committed by Peter Johnson
parent ae6c043632
commit 9aca8e0fd6
2622 changed files with 22275 additions and 22275 deletions

View File

@@ -11,7 +11,7 @@
* ADXL346, 362 Accelerometer snippets for frc-docs.
* https://docs.wpilib.org/en/stable/docs/software/hardware-apis/sensors/accelerometers-software.html
*/
class Robot : public frc::TimedRobot {
class Robot : public wpi::TimedRobot {
public:
Robot() {}
@@ -27,12 +27,12 @@ class Robot : public frc::TimedRobot {
private:
// Creates an ADXL345 accelerometer object on the MXP I2C port
// with a measurement range from -8 to 8 G's
frc::ADXL345_I2C m_accelerometer{frc::I2C::Port::kPort0,
frc::ADXL345_I2C::Range::kRange_8G};
wpi::ADXL345_I2C m_accelerometer{wpi::I2C::Port::kPort0,
wpi::ADXL345_I2C::Range::kRange_8G};
};
#ifndef RUNNING_FRC_TESTS
int main() {
return frc::StartRobot<Robot>();
return wpi::StartRobot<Robot>();
}
#endif

View File

@@ -11,7 +11,7 @@
* Collision detection snippets for frc-docs.
* https://docs.wpilib.org/en/stable/docs/software/hardware-apis/sensors/accelerometers-software.html
*/
class Robot : public frc::TimedRobot {
class Robot : public wpi::TimedRobot {
public:
void RobotPeriodic() override {
// Gets the current accelerations in the X and Y directions
@@ -23,18 +23,18 @@ class Robot : public frc::TimedRobot {
m_prevXAccel = xAccel;
m_prevYAccel = yAccel;
frc::SmartDashboard::PutNumber("X Jerk", xJerk.value());
frc::SmartDashboard::PutNumber("Y Jerk", yJerk.value());
wpi::SmartDashboard::PutNumber("X Jerk", xJerk.value());
wpi::SmartDashboard::PutNumber("Y Jerk", yJerk.value());
}
private:
units::meters_per_second_squared_t m_prevXAccel = 0.0_mps_sq;
units::meters_per_second_squared_t m_prevYAccel = 0.0_mps_sq;
frc::OnboardIMU m_accelerometer{frc::OnboardIMU::MountOrientation::kFlat};
wpi::units::meters_per_second_squared_t m_prevXAccel = 0.0_mps_sq;
wpi::units::meters_per_second_squared_t m_prevYAccel = 0.0_mps_sq;
wpi::OnboardIMU m_accelerometer{wpi::OnboardIMU::MountOrientation::kFlat};
};
#ifndef RUNNING_FRC_TESTS
int main() {
return frc::StartRobot<Robot>();
return wpi::StartRobot<Robot>();
}
#endif

View File

@@ -12,27 +12,27 @@
* Accelerometer filtering snippets for frc-docs.
* https://docs.wpilib.org/en/stable/docs/software/hardware-apis/sensors/accelerometers-software.html
*/
class Robot : public frc::TimedRobot {
class Robot : public wpi::TimedRobot {
public:
void RobotPeriodic() override {
units::meters_per_second_squared_t XAccel = m_accelerometer.GetAccelX();
wpi::units::meters_per_second_squared_t XAccel = m_accelerometer.GetAccelX();
// Get the filtered X acceleration
units::meters_per_second_squared_t filteredXAccel =
wpi::units::meters_per_second_squared_t filteredXAccel =
m_xAccelFilter.Calculate(XAccel);
frc::SmartDashboard::PutNumber("X Acceleration", XAccel.value());
frc::SmartDashboard::PutNumber("Filtered X Acceleration",
wpi::SmartDashboard::PutNumber("X Acceleration", XAccel.value());
wpi::SmartDashboard::PutNumber("Filtered X Acceleration",
filteredXAccel.value());
}
private:
frc::OnboardIMU m_accelerometer{frc::OnboardIMU::MountOrientation::kFlat};
frc::LinearFilter<units::meters_per_second_squared_t> m_xAccelFilter =
frc::LinearFilter<units::meters_per_second_squared_t>::MovingAverage(10);
wpi::OnboardIMU m_accelerometer{wpi::OnboardIMU::MountOrientation::kFlat};
wpi::math::LinearFilter<wpi::units::meters_per_second_squared_t> m_xAccelFilter =
wpi::math::LinearFilter<wpi::units::meters_per_second_squared_t>::MovingAverage(10);
};
#ifndef RUNNING_FRC_TESTS
int main() {
return frc::StartRobot<Robot>();
return wpi::StartRobot<Robot>();
}
#endif

View File

@@ -10,7 +10,7 @@
* AnalogAccelerometer snippets for frc-docs.
* https://docs.wpilib.org/en/stable/docs/software/hardware-apis/sensors/accelerometers-software.html
*/
class Robot : public frc::TimedRobot {
class Robot : public wpi::TimedRobot {
public:
Robot() {
// Sets the sensitivity of the accelerometer to 1 volt per G
@@ -26,11 +26,11 @@ class Robot : public frc::TimedRobot {
private:
// Creates an analog accelerometer on analog input 0
frc::AnalogAccelerometer m_accelerometer{0};
wpi::AnalogAccelerometer m_accelerometer{0};
};
#ifndef RUNNING_FRC_TESTS
int main() {
return frc::StartRobot<Robot>();
return wpi::StartRobot<Robot>();
}
#endif

View File

@@ -9,7 +9,7 @@
* AnalogEncoder snippets for frc-docs.
* https://docs.wpilib.org/en/stable/docs/software/hardware-apis/sensors/encoders-software.html
*/
class Robot : public frc::TimedRobot {
class Robot : public wpi::TimedRobot {
public:
Robot() {}
@@ -20,16 +20,16 @@ class Robot : public frc::TimedRobot {
private:
// Initializes an analog encoder on Analog Input pin 0
frc::AnalogEncoder m_encoder{0};
wpi::AnalogEncoder m_encoder{0};
// Initializes an analog encoder on DIO pins 0 to return a value of 4 for
// a full rotation, with the encoder reporting 0 half way through rotation (2
// out of 4)
frc::AnalogEncoder m_encoderFR{0, 4.0, 2.0};
wpi::AnalogEncoder m_encoderFR{0, 4.0, 2.0};
};
#ifndef RUNNING_FRC_TESTS
int main() {
return frc::StartRobot<Robot>();
return wpi::StartRobot<Robot>();
}
#endif

View File

@@ -9,7 +9,7 @@
* AnalogInput snippets for frc-docs.
* https://docs.wpilib.org/en/stable/docs/software/hardware-apis/sensors/analog-input-software.html
*/
class Robot : public frc::TimedRobot {
class Robot : public wpi::TimedRobot {
public:
Robot() {
// Sets the AnalogInput to 4-bit oversampling. 16 samples will be added
@@ -44,11 +44,11 @@ class Robot : public frc::TimedRobot {
private:
// Initializes an AnalogInput on port 0
frc::AnalogInput m_analog{0};
wpi::AnalogInput m_analog{0};
};
#ifndef RUNNING_FRC_TESTS
int main() {
return frc::StartRobot<Robot>();
return wpi::StartRobot<Robot>();
}
#endif

View File

@@ -10,7 +10,7 @@
* AnalogPotentiometer snippets for frc-docs.
* https://docs.wpilib.org/en/stable/docs/software/hardware-apis/sensors/analog-potentiometers-software.html
*/
class Robot : public frc::TimedRobot {
class Robot : public wpi::TimedRobot {
public:
Robot() {
// Set averaging bits to 2
@@ -27,19 +27,19 @@ class Robot : public frc::TimedRobot {
// The full range of motion (in meaningful external units) is 0-180 (this
// could be degrees, for instance) The "starting point" of the motion, i.e.
// where the mechanism is located when the potentiometer reads 0v, is 30.
frc::AnalogPotentiometer m_pot{0, 180, 30};
wpi::AnalogPotentiometer m_pot{0, 180, 30};
// Initializes an AnalogInput on port 1
frc::AnalogInput m_input{1};
wpi::AnalogInput m_input{1};
// Initializes an AnalogPotentiometer with the given AnalogInput
// The full range of motion (in meaningful external units) is 0-180 (this
// could be degrees, for instance) The "starting point" of the motion, i.e.
// where the mechanism is located when the potentiometer reads 0v, is 30.
frc::AnalogPotentiometer m_pot1{&m_input, 180, 30};
wpi::AnalogPotentiometer m_pot1{&m_input, 180, 30};
};
#ifndef RUNNING_FRC_TESTS
int main() {
return frc::StartRobot<Robot>();
return wpi::StartRobot<Robot>();
}
#endif

View File

@@ -9,7 +9,7 @@
* Digital Input snippets for frc-docs.
* https://docs.wpilib.org/en/stable/docs/software/hardware-apis/sensors/digital-input-software.html
*/
class Robot : public frc::TimedRobot {
class Robot : public wpi::TimedRobot {
public:
void TeleopPeriodic() override {
// Gets the value of the digital input. Returns true if the circuit is
@@ -19,11 +19,11 @@ class Robot : public frc::TimedRobot {
private:
// Initializes a DigitalInput on DIO 0
frc::DigitalInput m_input{0};
wpi::DigitalInput m_input{0};
};
#ifndef RUNNING_FRC_TESTS
int main() {
return frc::StartRobot<Robot>();
return wpi::StartRobot<Robot>();
}
#endif

View File

@@ -9,7 +9,7 @@
* DutyCycleEncoder snippets for frc-docs.
* https://docs.wpilib.org/en/stable/docs/software/hardware-apis/sensors/encoders-software.html
*/
class Robot : public frc::TimedRobot {
class Robot : public wpi::TimedRobot {
public:
Robot() {}
@@ -23,16 +23,16 @@ class Robot : public frc::TimedRobot {
private:
// Initializes a duty cycle encoder on DIO pins 0
frc::DutyCycleEncoder m_encoder{0};
wpi::DutyCycleEncoder m_encoder{0};
// Initializes a duty cycle encoder on DIO pins 0 to return a value of 4 for
// a full rotation, with the encoder reporting 0 half way through rotation (2
// out of 4)
frc::DutyCycleEncoder m_encoderFR{0, 4.0, 2.0};
wpi::DutyCycleEncoder m_encoderFR{0, 4.0, 2.0};
};
#ifndef RUNNING_FRC_TESTS
int main() {
return frc::StartRobot<Robot>();
return wpi::StartRobot<Robot>();
}
#endif

View File

@@ -11,7 +11,7 @@
* https://docs.wpilib.org/en/stable/docs/software/hardware-apis/sensors/encoders-software.html
*/
WPI_IGNORE_DEPRECATED
class Robot : public frc::TimedRobot {
class Robot : public wpi::TimedRobot {
public:
Robot() {
// Configures the encoder to return a distance of 4 for every 256 pulses
@@ -52,15 +52,15 @@ class Robot : public frc::TimedRobot {
private:
// Initializes an encoder on DIO pins 0 and 1
// Defaults to 4X decoding and non-inverted
frc::Encoder m_encoder{0, 1};
wpi::Encoder m_encoder{0, 1};
// Initializes an encoder on DIO pins 0 and 1
// 2X encoding and non-inverted
frc::Encoder m_encoder2x{0, 1, false, frc::Encoder::EncodingType::k2X};
wpi::Encoder m_encoder2x{0, 1, false, wpi::Encoder::EncodingType::k2X};
};
#ifndef RUNNING_FRC_TESTS
int main() {
return frc::StartRobot<Robot>();
return wpi::StartRobot<Robot>();
}
#endif

View File

@@ -11,7 +11,7 @@
* Encoder drive to distance snippets for frc-docs.
* https://docs.wpilib.org/en/stable/docs/software/hardware-apis/sensors/encoders-software.html
*/
class Robot : public frc::TimedRobot {
class Robot : public wpi::TimedRobot {
public:
Robot() {
// Configures the encoder's distance-per-pulse
@@ -37,18 +37,18 @@ class Robot : public frc::TimedRobot {
private:
// Creates an encoder on DIO ports 0 and 1.
frc::Encoder m_encoder{0, 1};
wpi::Encoder m_encoder{0, 1};
// Initialize motor controllers and drive
frc::Spark leftLeader{0};
frc::Spark leftFollower{1};
frc::Spark rightLeader{2};
frc::Spark rightFollower{3};
frc::DifferentialDrive drive{[&](double output) { leftLeader.Set(output); },
wpi::Spark leftLeader{0};
wpi::Spark leftFollower{1};
wpi::Spark rightLeader{2};
wpi::Spark rightFollower{3};
wpi::DifferentialDrive drive{[&](double output) { leftLeader.Set(output); },
[&](double output) { rightLeader.Set(output); }};
};
#ifndef RUNNING_FRC_TESTS
int main() {
return frc::StartRobot<Robot>();
return wpi::StartRobot<Robot>();
}
#endif

View File

@@ -11,7 +11,7 @@
* Encoder mechanism homing snippets for frc-docs.
* https://docs.wpilib.org/en/stable/docs/software/hardware-apis/sensors/encoders-software.html
*/
class Robot : public frc::TimedRobot {
class Robot : public wpi::TimedRobot {
public:
void AutonomousPeriodic() override {
// Runs the motor backwards at half speed until the limit switch is pressed
@@ -25,14 +25,14 @@ class Robot : public frc::TimedRobot {
}
private:
frc::Encoder m_encoder{0, 1};
frc::Spark m_spark{0};
wpi::Encoder m_encoder{0, 1};
wpi::Spark m_spark{0};
// Limit switch on DIO 2
frc::DigitalInput m_limit{2};
wpi::DigitalInput m_limit{2};
};
#ifndef RUNNING_FRC_TESTS
int main() {
return frc::StartRobot<Robot>();
return wpi::StartRobot<Robot>();
}
#endif

View File

@@ -12,7 +12,7 @@
* Limit Switch snippets for frc-docs.
* https://docs.wpilib.org/en/stable/docs/software/hardware-apis/sensors/limit-switch.html
*/
class Robot : public frc::TimedRobot {
class Robot : public wpi::TimedRobot {
public:
void TeleopPeriodic() override { SetMotorSpeed(m_joystick.GetRawAxis(2)); }
void SetMotorSpeed(double speed) {
@@ -37,14 +37,14 @@ class Robot : public frc::TimedRobot {
}
private:
frc::DigitalInput m_toplimitSwitch{0};
frc::DigitalInput m_bottomlimitSwitch{1};
frc::PWMVictorSPX m_motor{0};
frc::Joystick m_joystick{0};
wpi::DigitalInput m_toplimitSwitch{0};
wpi::DigitalInput m_bottomlimitSwitch{1};
wpi::PWMVictorSPX m_motor{0};
wpi::Joystick m_joystick{0};
};
#ifndef RUNNING_FRC_TESTS
int main() {
return frc::StartRobot<Robot>();
return wpi::StartRobot<Robot>();
}
#endif

View File

@@ -12,7 +12,7 @@
* Onboard IMU snippets for frc-docs.
* https://docs.wpilib.org/en/stable/docs/software/hardware-apis/sensors/accelerometers-software.html
*/
class Robot : public frc::TimedRobot {
class Robot : public wpi::TimedRobot {
public:
void TeleopPeriodic() override {
// Gets the current acceleration in the X axis
@@ -35,11 +35,11 @@ class Robot : public frc::TimedRobot {
private:
// Creates an object for the Systemcore IMU
frc::OnboardIMU m_IMU{frc::OnboardIMU::MountOrientation::kFlat};
wpi::OnboardIMU m_IMU{wpi::OnboardIMU::MountOrientation::kFlat};
};
#ifndef RUNNING_FRC_TESTS
int main() {
return frc::StartRobot<Robot>();
return wpi::StartRobot<Robot>();
}
#endif

View File

@@ -13,19 +13,19 @@
#include <wpi/units/voltage.hpp>
/**
* ProfiledPIDController with feedforward snippets for frc-docs.
* wpi::math::ProfiledPIDController with feedforward snippets for frc-docs.
* https://docs.wpilib.org/en/stable/docs/software/advanced-controls/controllers/profiled-pidcontroller.html
*/
class Robot : public frc::TimedRobot {
class Robot : public wpi::TimedRobot {
public:
Robot() { m_encoder.SetDistancePerPulse(1.0 / 256.0); }
// Controls a simple motor's position using a SimpleMotorFeedforward
// and a ProfiledPIDController
void GoToPosition(units::meter_t goalPosition) {
// Controls a simple motor's position using a wpi::math::SimpleMotorFeedforward
// and a wpi::math::ProfiledPIDController
void GoToPosition(wpi::units::meter_t goalPosition) {
auto pidVal = m_controller.Calculate(
units::meter_t{m_encoder.GetDistance()}, goalPosition);
m_motor.SetVoltage(units::volt_t{pidVal} +
wpi::units::meter_t{m_encoder.GetDistance()}, goalPosition);
m_motor.SetVoltage(wpi::units::volt_t{pidVal} +
m_feedforward.Calculate(
m_lastSpeed, m_controller.GetSetpoint().velocity));
m_lastSpeed = m_controller.GetSetpoint().velocity;
@@ -37,18 +37,18 @@ class Robot : public frc::TimedRobot {
}
private:
frc::ProfiledPIDController<units::meters> m_controller{
wpi::math::ProfiledPIDController<wpi::units::meters> m_controller{
1.0, 0.0, 0.0, {5_mps, 10_mps_sq}};
frc::SimpleMotorFeedforward<units::meters> m_feedforward{0.5_V, 1.5_V / 1_mps,
wpi::math::SimpleMotorFeedforward<wpi::units::meters> m_feedforward{0.5_V, 1.5_V / 1_mps,
0.3_V / 1_mps_sq};
frc::Encoder m_encoder{0, 1};
frc::PWMSparkMax m_motor{0};
wpi::Encoder m_encoder{0, 1};
wpi::PWMSparkMax m_motor{0};
units::meters_per_second_t m_lastSpeed = 0_mps;
wpi::units::meters_per_second_t m_lastSpeed = 0_mps;
};
#ifndef RUNNING_FRC_TESTS
int main() {
return frc::StartRobot<Robot>();
return wpi::StartRobot<Robot>();
}
#endif