45 DCMotor driveMotor,
double gearingRatio, units::meter_t wheelRadius,
46 const std::array<double, 7>& measurementStdDevs = {});
71 frc::DCMotor driveMotor,
double gearing, units::kilogram_square_meter_t J,
72 units::kilogram_t mass, units::meter_t wheelRadius,
73 units::meter_t trackWidth,
74 const std::array<double, 7>& measurementStdDevs = {});
92 void SetInputs(units::volt_t leftVoltage, units::volt_t rightVoltage);
201 static constexpr int kX = 0;
202 static constexpr int kY = 1;
225 static constexpr double k8p45 = 8.45;
227 static constexpr double k7p31 = 7.31;
229 static constexpr double k5p95 = 5.95;
285 frc::DCMotor motor,
double gearing, units::meter_t wheelSize,
286 const std::array<double, 7>& measurementStdDevs = {}) {
288 units::kilogram_square_meter_t batteryMoi = 12.5_lb * 10_in * 10_in;
289 units::kilogram_square_meter_t gearboxMoi = (2.8_lb + 2.0_lb) *
291 * (26_in / 2) * (26_in / 2);
294 motor, gearing, batteryMoi + gearboxMoi, 60_lb,
295 wheelSize / 2.0, 26_in, measurementStdDevs};
314 frc::DCMotor motor,
double gearing, units::meter_t wheelSize,
315 units::kilogram_square_meter_t J,
316 const std::array<double, 7>& measurementStdDevs = {}) {
318 motor, gearing, J, 60_lb, wheelSize / 2.0, 26_in, measurementStdDevs};
327 double GetOutput(
int output)
const;
332 Vectord<7> GetOutput()
const;
340 double GetState(
int state)
const;
345 Vectord<7> GetState()
const;
347 LinearSystem<2, 2, 2> m_plant;
349 units::meter_t m_wheelRadius;
353 double m_originalGearing;
354 double m_currentGearing;
359 std::array<double, 7> m_measurementStdDevs;
Holds the constants for a DC motor.
Definition: DCMotor.h:20
static constexpr DCMotor Falcon500(int numMotors=1)
Returns a gearbox of Falcon 500 brushless motors.
Definition: DCMotor.h:203
static constexpr DCMotor CIM(int numMotors=1)
Returns a gearbox of CIM motors.
Definition: DCMotor.h:133
static constexpr DCMotor NEO(int numMotors=1)
Returns a gearbox of NEO brushless motors.
Definition: DCMotor.h:189
static constexpr DCMotor MiniCIM(int numMotors=1)
Returns a gearbox of MiniCIM motors.
Definition: DCMotor.h:140
Represents a 2D pose containing translational and rotational elements.
Definition: Pose2d.h:23
A rotation in a 2D coordinate frame represented by a point on the unit circle (cosine and sine).
Definition: Rotation2d.h:23
Represents a gearing option of the Toughbox mini.
Definition: DifferentialDrivetrainSim.h:218
static constexpr double k10p71
Gear ratio of 10.71:1.
Definition: DifferentialDrivetrainSim.h:223
static constexpr double k5p95
Gear ratio of 5.95:1.
Definition: DifferentialDrivetrainSim.h:229
static constexpr double k8p45
Gear ratio of 8.45:1.
Definition: DifferentialDrivetrainSim.h:225
static constexpr double k7p31
Gear ratio of 7.31:1.
Definition: DifferentialDrivetrainSim.h:227
static constexpr double k12p75
Gear ratio of 12.75:1.
Definition: DifferentialDrivetrainSim.h:221
Represents common motor layouts of the kit drivetrain.
Definition: DifferentialDrivetrainSim.h:235
static constexpr frc::DCMotor DualNEOPerSide
Two NEO motors per drive side.
Definition: DifferentialDrivetrainSim.h:255
static constexpr frc::DCMotor DualFalcon500PerSide
Two Falcon 500 motors per drive side.
Definition: DifferentialDrivetrainSim.h:250
static constexpr frc::DCMotor SingleNEOPerSide
One NEO motor per drive side.
Definition: DifferentialDrivetrainSim.h:253
static constexpr frc::DCMotor SingleMiniCIMPerSide
One Mini CIM motor per drive side.
Definition: DifferentialDrivetrainSim.h:242
static constexpr frc::DCMotor SingleCIMPerSide
One CIM motor per drive side.
Definition: DifferentialDrivetrainSim.h:238
static constexpr frc::DCMotor DualCIMPerSide
Two CIM motors per drive side.
Definition: DifferentialDrivetrainSim.h:240
static constexpr frc::DCMotor DualMiniCIMPerSide
Two Mini CIM motors per drive side.
Definition: DifferentialDrivetrainSim.h:245
static constexpr frc::DCMotor SingleFalcon500PerSide
One Falcon 500 motor per drive side.
Definition: DifferentialDrivetrainSim.h:247
Represents common wheel sizes of the kit drivetrain.
Definition: DifferentialDrivetrainSim.h:261
static constexpr units::meter_t kTenInch
Ten inch diameter wheels.
Definition: DifferentialDrivetrainSim.h:268
static constexpr units::meter_t kSixInch
Six inch diameter wheels.
Definition: DifferentialDrivetrainSim.h:264
static constexpr units::meter_t kEightInch
Eight inch diameter wheels.
Definition: DifferentialDrivetrainSim.h:266
Definition: DifferentialDrivetrainSim.h:199
static constexpr int kLeftVelocity
Definition: DifferentialDrivetrainSim.h:204
static constexpr int kX
Definition: DifferentialDrivetrainSim.h:201
static constexpr int kY
Definition: DifferentialDrivetrainSim.h:202
static constexpr int kLeftPosition
Definition: DifferentialDrivetrainSim.h:206
static constexpr int kHeading
Definition: DifferentialDrivetrainSim.h:203
static constexpr int kRightPosition
Definition: DifferentialDrivetrainSim.h:207
static constexpr int kRightVelocity
Definition: DifferentialDrivetrainSim.h:205
Definition: DifferentialDrivetrainSim.h:19
units::ampere_t GetCurrentDraw() const
Returns the currently drawn current.
DifferentialDrivetrainSim(frc::DCMotor driveMotor, double gearing, units::kilogram_square_meter_t J, units::kilogram_t mass, units::meter_t wheelRadius, units::meter_t trackWidth, const std::array< double, 7 > &measurementStdDevs={})
Creates a simulated differential drivetrain.
Eigen::Vector2d ClampInput(const Eigen::Vector2d &u)
Clamp the input vector such that no element exceeds the battery voltage.
void Update(units::second_t dt)
Updates the simulation.
units::meter_t GetRightPosition() const
Get the right encoder position in meters.
Definition: DifferentialDrivetrainSim.h:133
void SetGearing(double newGearing)
Sets the gearing reduction on the drivetrain.
Pose2d GetPose() const
Returns the current pose.
units::meter_t GetLeftPosition() const
Get the left encoder position in meters.
Definition: DifferentialDrivetrainSim.h:149
static DifferentialDrivetrainSim CreateKitbotSim(frc::DCMotor motor, double gearing, units::meter_t wheelSize, const std::array< double, 7 > &measurementStdDevs={})
Create a sim for the standard FRC kitbot.
Definition: DifferentialDrivetrainSim.h:284
units::meters_per_second_t GetLeftVelocity() const
Get the left encoder velocity in meters per second.
Definition: DifferentialDrivetrainSim.h:157
units::ampere_t GetLeftCurrentDraw() const
Returns the currently drawn current for the left side.
void SetState(const Vectord< 7 > &state)
Sets the system state.
units::meters_per_second_t GetRightVelocity() const
Get the right encoder velocity in meters per second.
Definition: DifferentialDrivetrainSim.h:141
void SetPose(const frc::Pose2d &pose)
Sets the system pose.
units::ampere_t GetRightCurrentDraw() const
Returns the currently drawn current for the right side.
Vectord< 7 > Dynamics(const Vectord< 7 > &x, const Eigen::Vector2d &u)
The differential drive dynamics function.
double GetGearing() const
Returns the current gearing reduction of the drivetrain, as output over input.
void SetInputs(units::volt_t leftVoltage, units::volt_t rightVoltage)
Sets the applied voltage to the drivetrain.
static DifferentialDrivetrainSim CreateKitbotSim(frc::DCMotor motor, double gearing, units::meter_t wheelSize, units::kilogram_square_meter_t J, const std::array< double, 7 > &measurementStdDevs={})
Create a sim for the standard FRC kitbot.
Definition: DifferentialDrivetrainSim.h:313
DifferentialDrivetrainSim(LinearSystem< 2, 2, 2 > plant, units::meter_t trackWidth, DCMotor driveMotor, double gearingRatio, units::meter_t wheelRadius, const std::array< double, 7 > &measurementStdDevs={})
Creates a simulated differential drivetrain.
Rotation2d GetHeading() const
Returns the direction the robot is pointing.
state
Definition: core.h:2271
Definition: XboxControllerSim.h:13
Eigen::Vector< double, Size > Vectord
Definition: EigenCore.h:12