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
@@ -39,6 +39,6 @@ void Robot::DisabledInit() {
|
||||
|
||||
#ifndef RUNNING_FRC_TESTS
|
||||
int main() {
|
||||
return frc::StartRobot<Robot>();
|
||||
return wpi::StartRobot<Robot>();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -14,14 +14,14 @@ Elevator::Elevator() {
|
||||
// Put Mechanism 2d to SmartDashboard
|
||||
// To view the Elevator visualization, select Network Tables -> SmartDashboard
|
||||
// -> Elevator Sim
|
||||
frc::SmartDashboard::PutData("Elevator Sim", &m_mech2d);
|
||||
wpi::SmartDashboard::PutData("Elevator Sim", &m_mech2d);
|
||||
}
|
||||
|
||||
void Elevator::SimulationPeriodic() {
|
||||
// In this method, we update our simulation of what our elevator is doing
|
||||
// First, we set our "inputs" (voltages)
|
||||
m_elevatorSim.SetInput(frc::Vectord<1>{
|
||||
m_motorSim.GetSpeed() * frc::RobotController::GetInputVoltage()});
|
||||
m_elevatorSim.SetInput(wpi::math::Vectord<1>{
|
||||
m_motorSim.GetSpeed() * wpi::RobotController::GetInputVoltage()});
|
||||
|
||||
// Next, we update it. The standard loop time is 20ms.
|
||||
m_elevatorSim.Update(20_ms);
|
||||
@@ -30,8 +30,8 @@ void Elevator::SimulationPeriodic() {
|
||||
// voltage
|
||||
m_encoderSim.SetDistance(m_elevatorSim.GetPosition().value());
|
||||
// SimBattery estimates loaded battery voltages
|
||||
frc::sim::RoboRioSim::SetVInVoltage(
|
||||
frc::sim::BatterySim::Calculate({m_elevatorSim.GetCurrentDraw()}));
|
||||
wpi::sim::RoboRioSim::SetVInVoltage(
|
||||
wpi::sim::BatterySim::Calculate({m_elevatorSim.GetCurrentDraw()}));
|
||||
}
|
||||
|
||||
void Elevator::UpdateTelemetry() {
|
||||
@@ -39,8 +39,8 @@ void Elevator::UpdateTelemetry() {
|
||||
m_elevatorMech2d->SetLength(m_encoder.GetDistance());
|
||||
}
|
||||
|
||||
void Elevator::ReachGoal(units::meter_t goal) {
|
||||
frc::ExponentialProfile<units::meters, units::volts>::State goalState{goal,
|
||||
void Elevator::ReachGoal(wpi::units::meter_t goal) {
|
||||
wpi::math::ExponentialProfile<wpi::units::meters, wpi::units::volts>::State goalState{goal,
|
||||
0_mps};
|
||||
|
||||
auto next = m_profile.Calculate(20_ms, m_setpoint, goalState);
|
||||
@@ -50,7 +50,7 @@ void Elevator::ReachGoal(units::meter_t goal) {
|
||||
auto feedforwardOutput =
|
||||
m_feedforward.Calculate(m_setpoint.velocity, next.velocity);
|
||||
|
||||
m_motor.SetVoltage(units::volt_t{pidOutput} + feedforwardOutput);
|
||||
m_motor.SetVoltage(wpi::units::volt_t{pidOutput} + feedforwardOutput);
|
||||
|
||||
m_setpoint = next;
|
||||
}
|
||||
|
||||
@@ -34,20 +34,20 @@ inline constexpr double kElevatorKp = 0.75;
|
||||
inline constexpr double kElevatorKi = 0.0;
|
||||
inline constexpr double kElevatorKd = 0.0;
|
||||
|
||||
inline constexpr units::volt_t kElevatorMaxV = 10_V;
|
||||
inline constexpr units::volt_t kElevatorkS = 0.0_V;
|
||||
inline constexpr units::volt_t kElevatorkG = 0.62_V;
|
||||
inline constexpr wpi::units::volt_t kElevatorMaxV = 10_V;
|
||||
inline constexpr wpi::units::volt_t kElevatorkS = 0.0_V;
|
||||
inline constexpr wpi::units::volt_t kElevatorkG = 0.62_V;
|
||||
inline constexpr auto kElevatorkV = 3.9_V / 1_mps;
|
||||
inline constexpr auto kElevatorkA = 0.06_V / 1_mps_sq;
|
||||
|
||||
inline constexpr double kElevatorGearing = 5.0;
|
||||
inline constexpr units::meter_t kElevatorDrumRadius = 1_in;
|
||||
inline constexpr units::kilogram_t kCarriageMass = 12_lb;
|
||||
inline constexpr wpi::units::meter_t kElevatorDrumRadius = 1_in;
|
||||
inline constexpr wpi::units::kilogram_t kCarriageMass = 12_lb;
|
||||
|
||||
inline constexpr units::meter_t kSetpoint = 42.875_in;
|
||||
inline constexpr units::meter_t kLowerSetpoint = 15_in;
|
||||
inline constexpr units::meter_t kMinElevatorHeight = 0_cm;
|
||||
inline constexpr units::meter_t kMaxElevatorHeight = 50_in;
|
||||
inline constexpr wpi::units::meter_t kSetpoint = 42.875_in;
|
||||
inline constexpr wpi::units::meter_t kLowerSetpoint = 15_in;
|
||||
inline constexpr wpi::units::meter_t kMinElevatorHeight = 0_cm;
|
||||
inline constexpr wpi::units::meter_t kMaxElevatorHeight = 50_in;
|
||||
|
||||
// distance per pulse = (distance per revolution) / (pulses per revolution)
|
||||
// = (Pi * D) / ppr
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
/**
|
||||
* This is a sample program to demonstrate the use of elevator simulation.
|
||||
*/
|
||||
class Robot : public frc::TimedRobot {
|
||||
class Robot : public wpi::TimedRobot {
|
||||
public:
|
||||
Robot() {}
|
||||
void RobotPeriodic() override;
|
||||
@@ -22,6 +22,6 @@ class Robot : public frc::TimedRobot {
|
||||
void DisabledInit() override;
|
||||
|
||||
private:
|
||||
frc::Joystick m_joystick{Constants::kJoystickPort};
|
||||
wpi::Joystick m_joystick{Constants::kJoystickPort};
|
||||
Elevator m_elevator;
|
||||
};
|
||||
|
||||
@@ -26,34 +26,34 @@ class Elevator {
|
||||
Elevator();
|
||||
void SimulationPeriodic();
|
||||
void UpdateTelemetry();
|
||||
void ReachGoal(units::meter_t goal);
|
||||
void ReachGoal(wpi::units::meter_t goal);
|
||||
void Reset();
|
||||
void Stop();
|
||||
|
||||
private:
|
||||
// This gearbox represents a gearbox containing 4 Vex 775pro motors.
|
||||
frc::DCMotor m_elevatorGearbox = frc::DCMotor::NEO(2);
|
||||
wpi::math::DCMotor m_elevatorGearbox = wpi::math::DCMotor::NEO(2);
|
||||
|
||||
// Standard classes for controlling our elevator
|
||||
frc::ExponentialProfile<units::meters, units::volts>::Constraints
|
||||
wpi::math::ExponentialProfile<wpi::units::meters, wpi::units::volts>::Constraints
|
||||
m_constraints{Constants::kElevatorMaxV, Constants::kElevatorkV,
|
||||
Constants::kElevatorkA};
|
||||
frc::ExponentialProfile<units::meters, units::volts> m_profile{m_constraints};
|
||||
frc::ExponentialProfile<units::meters, units::volts>::State m_setpoint;
|
||||
wpi::math::ExponentialProfile<wpi::units::meters, wpi::units::volts> m_profile{m_constraints};
|
||||
wpi::math::ExponentialProfile<wpi::units::meters, wpi::units::volts>::State m_setpoint;
|
||||
|
||||
frc::PIDController m_controller{
|
||||
wpi::math::PIDController m_controller{
|
||||
Constants::kElevatorKp, Constants::kElevatorKi, Constants::kElevatorKd};
|
||||
|
||||
frc::ElevatorFeedforward m_feedforward{
|
||||
wpi::math::ElevatorFeedforward m_feedforward{
|
||||
Constants::kElevatorkS, Constants::kElevatorkG, Constants::kElevatorkV,
|
||||
Constants::kElevatorkA};
|
||||
frc::Encoder m_encoder{Constants::kEncoderAChannel,
|
||||
wpi::Encoder m_encoder{Constants::kEncoderAChannel,
|
||||
Constants::kEncoderBChannel};
|
||||
frc::PWMSparkMax m_motor{Constants::kMotorPort};
|
||||
frc::sim::PWMMotorControllerSim m_motorSim{m_motor};
|
||||
wpi::PWMSparkMax m_motor{Constants::kMotorPort};
|
||||
wpi::sim::PWMMotorControllerSim m_motorSim{m_motor};
|
||||
|
||||
// Simulation classes help us simulate what's going on, including gravity.
|
||||
frc::sim::ElevatorSim m_elevatorSim{m_elevatorGearbox,
|
||||
wpi::sim::ElevatorSim m_elevatorSim{m_elevatorGearbox,
|
||||
Constants::kElevatorGearing,
|
||||
Constants::kCarriageMass,
|
||||
Constants::kElevatorDrumRadius,
|
||||
@@ -62,13 +62,13 @@ class Elevator {
|
||||
true,
|
||||
0_m,
|
||||
{0.005}};
|
||||
frc::sim::EncoderSim m_encoderSim{m_encoder};
|
||||
wpi::sim::EncoderSim m_encoderSim{m_encoder};
|
||||
|
||||
// Create a Mechanism2d display of an elevator
|
||||
frc::Mechanism2d m_mech2d{10_in / 1_m, 51_in / 1_m};
|
||||
frc::MechanismRoot2d* m_elevatorRoot =
|
||||
wpi::Mechanism2d m_mech2d{10_in / 1_m, 51_in / 1_m};
|
||||
wpi::MechanismRoot2d* m_elevatorRoot =
|
||||
m_mech2d.GetRoot("Elevator Root", 5_in / 1_m, 0.5_in / 1_m);
|
||||
frc::MechanismLigament2d* m_elevatorMech2d =
|
||||
m_elevatorRoot->Append<frc::MechanismLigament2d>(
|
||||
wpi::MechanismLigament2d* m_elevatorMech2d =
|
||||
m_elevatorRoot->Append<wpi::MechanismLigament2d>(
|
||||
"Elevator", m_elevatorSim.GetPosition().value(), 90_deg);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user