12#include "wpi/units/length.hpp"
13#include "wpi/units/moment_of_inertia.hpp"
14#include "wpi/units/time.hpp"
15#include "wpi/units/velocity.hpp"
16#include "wpi/units/voltage.hpp"
46 wpi::units::meter_t wheelRadius,
47 const std::array<double, 7>& measurementStdDevs = {});
71 wpi::units::kilogram_square_meter_t J, wpi::units::kilogram_t mass,
72 wpi::units::meter_t wheelRadius, wpi::units::meter_t trackwidth,
73 const std::array<double, 7>& measurementStdDevs = {});
92 wpi::units::volt_t rightVoltage);
198 const Eigen::Vector2d& u);
202 static constexpr int kX = 0;
203 static constexpr int kY = 1;
226 static constexpr double k8p45 = 8.45;
228 static constexpr double k7p31 = 7.31;
230 static constexpr double k5p95 = 5.95;
270 static constexpr wpi::units::meter_t
kSixInch = 6_in;
274 static constexpr wpi::units::meter_t
kTenInch = 10_in;
292 const std::array<double, 7>& measurementStdDevs = {}) {
294 wpi::units::kilogram_square_meter_t batteryMoi = 12.5_lb * 10_in * 10_in;
295 wpi::units::kilogram_square_meter_t gearboxMoi =
296 (2.8_lb + 2.0_lb) * 2
297 * (26_in / 2) * (26_in / 2);
300 motor, gearing, batteryMoi + gearboxMoi, 60_lb,
301 wheelSize / 2.0, 26_in, measurementStdDevs};
321 wpi::units::kilogram_square_meter_t J,
322 const std::array<double, 7>& measurementStdDevs = {}) {
324 motor, gearing, J, 60_lb, wheelSize / 2.0, 26_in, measurementStdDevs};
333 double GetOutput(
int output)
const;
346 double GetState(
int state)
const;
354 wpi::units::meter_t m_rb;
355 wpi::units::meter_t m_wheelRadius;
359 double m_originalGearing;
360 double m_currentGearing;
365 std::array<double, 7> m_measurementStdDevs;
Holds the constants for a DC motor.
Definition DCMotor.hpp:19
static constexpr DCMotor MiniCIM(int numMotors=1)
Returns a gearbox of MiniCIM motors.
Definition DCMotor.hpp:155
static constexpr DCMotor Falcon500(int numMotors=1)
Returns a gearbox of Falcon 500 brushless motors.
Definition DCMotor.hpp:218
static constexpr DCMotor NEO(int numMotors=1)
Returns a gearbox of NEO brushless motors.
Definition DCMotor.hpp:204
static constexpr DCMotor CIM(int numMotors=1)
Returns a gearbox of CIM motors.
Definition DCMotor.hpp:148
A plant defined using state-space notation.
Definition LinearSystem.hpp:35
Represents a 2D pose containing translational and rotational elements.
Definition Pose2d.hpp:27
A rotation in a 2D coordinate frame represented by a point on the unit circle (cosine and sine).
Definition Rotation2d.hpp:26
Represents a gearing option of the Toughbox mini.
Definition DifferentialDrivetrainSim.hpp:219
static constexpr double k10p71
Gear ratio of 10.71:1.
Definition DifferentialDrivetrainSim.hpp:224
static constexpr double k5p95
Gear ratio of 5.95:1.
Definition DifferentialDrivetrainSim.hpp:230
static constexpr double k12p75
Gear ratio of 12.75:1.
Definition DifferentialDrivetrainSim.hpp:222
static constexpr double k7p31
Gear ratio of 7.31:1.
Definition DifferentialDrivetrainSim.hpp:228
static constexpr double k8p45
Gear ratio of 8.45:1.
Definition DifferentialDrivetrainSim.hpp:226
Represents common motor layouts of the kit drivetrain.
Definition DifferentialDrivetrainSim.hpp:236
static constexpr wpi::math::DCMotor SingleCIMPerSide
One CIM motor per drive side.
Definition DifferentialDrivetrainSim.hpp:239
static constexpr wpi::math::DCMotor DualMiniCIMPerSide
Two Mini CIM motors per drive side.
Definition DifferentialDrivetrainSim.hpp:248
static constexpr wpi::math::DCMotor DualFalcon500PerSide
Two Falcon 500 motors per drive side.
Definition DifferentialDrivetrainSim.hpp:254
static constexpr wpi::math::DCMotor DualNEOPerSide
Two NEO motors per drive side.
Definition DifferentialDrivetrainSim.hpp:260
static constexpr wpi::math::DCMotor DualCIMPerSide
Two CIM motors per drive side.
Definition DifferentialDrivetrainSim.hpp:242
static constexpr wpi::math::DCMotor SingleNEOPerSide
One NEO motor per drive side.
Definition DifferentialDrivetrainSim.hpp:257
static constexpr wpi::math::DCMotor SingleMiniCIMPerSide
One Mini CIM motor per drive side.
Definition DifferentialDrivetrainSim.hpp:245
static constexpr wpi::math::DCMotor SingleFalcon500PerSide
One Falcon 500 motor per drive side.
Definition DifferentialDrivetrainSim.hpp:251
Represents common wheel sizes of the kit drivetrain.
Definition DifferentialDrivetrainSim.hpp:267
static constexpr wpi::units::meter_t kSixInch
Six inch diameter wheels.
Definition DifferentialDrivetrainSim.hpp:270
static constexpr wpi::units::meter_t kEightInch
Eight inch diameter wheels.
Definition DifferentialDrivetrainSim.hpp:272
static constexpr wpi::units::meter_t kTenInch
Ten inch diameter wheels.
Definition DifferentialDrivetrainSim.hpp:274
Definition DifferentialDrivetrainSim.hpp:200
static constexpr int kX
Definition DifferentialDrivetrainSim.hpp:202
static constexpr int kHeading
Definition DifferentialDrivetrainSim.hpp:204
static constexpr int kLeftVelocity
Definition DifferentialDrivetrainSim.hpp:205
static constexpr int kRightPosition
Definition DifferentialDrivetrainSim.hpp:208
static constexpr int kY
Definition DifferentialDrivetrainSim.hpp:203
static constexpr int kLeftPosition
Definition DifferentialDrivetrainSim.hpp:207
static constexpr int kRightVelocity
Definition DifferentialDrivetrainSim.hpp:206
Definition DifferentialDrivetrainSim.hpp:20
static DifferentialDrivetrainSim CreateKitbotSim(wpi::math::DCMotor motor, double gearing, wpi::units::meter_t wheelSize, const std::array< double, 7 > &measurementStdDevs={})
Create a sim for the standard FRC kitbot.
Definition DifferentialDrivetrainSim.hpp:290
wpi::units::ampere_t GetLeftCurrentDraw() const
Returns the currently drawn current for the left side.
double GetGearing() const
Returns the current gearing reduction of the drivetrain, as output over input.
Eigen::Vector2d ClampInput(const Eigen::Vector2d &u)
Clamp the input vector such that no element exceeds the battery voltage.
wpi::math::Pose2d GetPose() const
Returns the current pose.
wpi::units::ampere_t GetRightCurrentDraw() const
Returns the currently drawn current for the right side.
wpi::math::Rotation2d GetHeading() const
Returns the direction the robot is pointing.
void SetGearing(double newGearing)
Sets the gearing reduction on the drivetrain.
void SetInputs(wpi::units::volt_t leftVoltage, wpi::units::volt_t rightVoltage)
Sets the applied voltage to the drivetrain.
wpi::units::ampere_t GetCurrentDraw() const
Returns the currently drawn current.
static DifferentialDrivetrainSim CreateKitbotSim(wpi::math::DCMotor motor, double gearing, wpi::units::meter_t wheelSize, wpi::units::kilogram_square_meter_t J, const std::array< double, 7 > &measurementStdDevs={})
Create a sim for the standard FRC kitbot.
Definition DifferentialDrivetrainSim.hpp:319
wpi::units::meters_per_second_t GetRightVelocity() const
Get the right encoder velocity in meters per second.
Definition DifferentialDrivetrainSim.hpp:141
wpi::units::meters_per_second_t GetLeftVelocity() const
Get the left encoder velocity in meters per second.
Definition DifferentialDrivetrainSim.hpp:157
void SetPose(const wpi::math::Pose2d &pose)
Sets the system pose.
void SetState(const wpi::math::Vectord< 7 > &state)
Sets the system state.
void Update(wpi::units::second_t dt)
Updates the simulation.
wpi::math::Vectord< 7 > Dynamics(const wpi::math::Vectord< 7 > &x, const Eigen::Vector2d &u)
The differential drive dynamics function.
wpi::units::meter_t GetLeftPosition() const
Get the left encoder position in meters.
Definition DifferentialDrivetrainSim.hpp:149
DifferentialDrivetrainSim(wpi::math::LinearSystem< 2, 2, 2 > plant, wpi::units::meter_t trackwidth, wpi::math::DCMotor driveMotor, double gearingRatio, wpi::units::meter_t wheelRadius, const std::array< double, 7 > &measurementStdDevs={})
Creates a simulated differential drivetrain.
DifferentialDrivetrainSim(wpi::math::DCMotor driveMotor, double gearing, wpi::units::kilogram_square_meter_t J, wpi::units::kilogram_t mass, wpi::units::meter_t wheelRadius, wpi::units::meter_t trackwidth, const std::array< double, 7 > &measurementStdDevs={})
Creates a simulated differential drivetrain.
wpi::units::meter_t GetRightPosition() const
Get the right encoder position in meters.
Definition DifferentialDrivetrainSim.hpp:133
Eigen::Vector< double, Size > Vectord
Definition EigenCore.hpp:12
Definition CTREPCMSim.hpp:13