WPILibC++ 2024.3.2
frc::sim::DifferentialDrivetrainSim Class Reference

#include <frc/simulation/DifferentialDrivetrainSim.h>

Classes

class  KitbotGearing
 Represents a gearing option of the Toughbox mini. More...
 
class  KitbotMotor
 Represents common motor layouts of the kit drivetrain. More...
 
class  KitbotWheelSize
 Represents common wheel sizes of the kit drivetrain. More...
 
class  State
 

Public Member Functions

 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. More...
 
 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. More...
 
Eigen::Vector2d ClampInput (const Eigen::Vector2d &u)
 Clamp the input vector such that no element exceeds the battery voltage. More...
 
void SetInputs (units::volt_t leftVoltage, units::volt_t rightVoltage)
 Sets the applied voltage to the drivetrain. More...
 
void SetGearing (double newGearing)
 Sets the gearing reduction on the drivetrain. More...
 
void Update (units::second_t dt)
 Updates the simulation. More...
 
double GetGearing () const
 Returns the current gearing reduction of the drivetrain, as output over input. More...
 
Rotation2d GetHeading () const
 Returns the direction the robot is pointing. More...
 
Pose2d GetPose () const
 Returns the current pose. More...
 
units::meter_t GetRightPosition () const
 Get the right encoder position in meters. More...
 
units::meters_per_second_t GetRightVelocity () const
 Get the right encoder velocity in meters per second. More...
 
units::meter_t GetLeftPosition () const
 Get the left encoder position in meters. More...
 
units::meters_per_second_t GetLeftVelocity () const
 Get the left encoder velocity in meters per second. More...
 
units::ampere_t GetRightCurrentDraw () const
 Returns the currently drawn current for the right side. More...
 
units::ampere_t GetLeftCurrentDraw () const
 Returns the currently drawn current for the left side. More...
 
units::ampere_t GetCurrentDraw () const
 Returns the currently drawn current. More...
 
void SetState (const Vectord< 7 > &state)
 Sets the system state. More...
 
void SetPose (const frc::Pose2d &pose)
 Sets the system pose. More...
 
Vectord< 7 > Dynamics (const Vectord< 7 > &x, const Eigen::Vector2d &u)
 The differential drive dynamics function. More...
 

Static Public Member Functions

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. More...
 
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. More...
 

Constructor & Destructor Documentation

◆ DifferentialDrivetrainSim() [1/2]

frc::sim::DifferentialDrivetrainSim::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.

Parameters
plantThe LinearSystem representing the robot's drivetrain. This system can be created with LinearSystemId::DrivetrainVelocitySystem() or LinearSystemId::IdentifyDrivetrainSystem().
trackWidthThe robot's track width.
driveMotorA DCMotor representing the left side of the drivetrain.
gearingRatioThe gearingRatio ratio of the left side, as output over input. This must be the same ratio as the ratio used to identify or create the plant.
wheelRadiusThe radius of the wheels on the drivetrain, in meters.
measurementStdDevsStandard deviations for measurements, in the form [x, y, heading, left velocity, right velocity, left distance, right distance]ᵀ. Can be omitted if no noise is desired. Gyro standard deviations of 0.0001 radians, velocity standard deviations of 0.05 m/s, and position measurement standard deviations of 0.005 meters are a reasonable starting point.

◆ DifferentialDrivetrainSim() [2/2]

frc::sim::DifferentialDrivetrainSim::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.

Parameters
driveMotorA DCMotor representing the left side of the drivetrain.
gearingThe gearing on the drive between motor and wheel, as output over input. This must be the same ratio as the ratio used to identify or create the plant.
JThe moment of inertia of the drivetrain about its center.
massThe mass of the drivebase.
wheelRadiusThe radius of the wheels on the drivetrain.
trackWidthThe robot's track width, or distance between left and right wheels.
measurementStdDevsStandard deviations for measurements, in the form [x, y, heading, left velocity, right velocity, left distance, right distance]ᵀ. Can be omitted if no noise is desired. Gyro standard deviations of 0.0001 radians, velocity standard deviations of 0.05 m/s, and position measurement standard deviations of 0.005 meters are a reasonable starting point.

Member Function Documentation

◆ ClampInput()

Eigen::Vector2d frc::sim::DifferentialDrivetrainSim::ClampInput ( const Eigen::Vector2d &  u)

Clamp the input vector such that no element exceeds the battery voltage.

If any does, the relative magnitudes of the input will be maintained.

Parameters
uThe input vector.
Returns
The normalized input.

◆ CreateKitbotSim() [1/2]

static DifferentialDrivetrainSim frc::sim::DifferentialDrivetrainSim::CreateKitbotSim ( frc::DCMotor  motor,
double  gearing,
units::meter_t  wheelSize,
const std::array< double, 7 > &  measurementStdDevs = {} 
)
inlinestatic

Create a sim for the standard FRC kitbot.

Parameters
motorThe motors installed in the bot.
gearingThe gearing reduction used.
wheelSizeThe wheel size.
measurementStdDevsStandard deviations for measurements, in the form [x, y, heading, left velocity, right velocity, left distance, right distance]ᵀ. Can be omitted if no noise is desired. Gyro standard deviations of 0.0001 radians, velocity standard deviations of 0.05 m/s, and position measurement standard deviations of 0.005 meters are a reasonable starting point.

◆ CreateKitbotSim() [2/2]

static DifferentialDrivetrainSim frc::sim::DifferentialDrivetrainSim::CreateKitbotSim ( frc::DCMotor  motor,
double  gearing,
units::meter_t  wheelSize,
units::kilogram_square_meter_t  J,
const std::array< double, 7 > &  measurementStdDevs = {} 
)
inlinestatic

Create a sim for the standard FRC kitbot.

Parameters
motorThe motors installed in the bot.
gearingThe gearing reduction used.
wheelSizeThe wheel size.
JThe moment of inertia of the drivebase. This can be calculated using SysId.
measurementStdDevsStandard deviations for measurements, in the form [x, y, heading, left velocity, right velocity, left distance, right distance]ᵀ. Can be omitted if no noise is desired. Gyro standard deviations of 0.0001 radians, velocity standard deviations of 0.05 m/s, and position measurement standard deviations of 0.005 meters are a reasonable starting point.

◆ Dynamics()

Vectord< 7 > frc::sim::DifferentialDrivetrainSim::Dynamics ( const Vectord< 7 > &  x,
const Eigen::Vector2d &  u 
)

The differential drive dynamics function.

Parameters
xThe state.
uThe input.
Returns
The state derivative with respect to time.

◆ GetCurrentDraw()

units::ampere_t frc::sim::DifferentialDrivetrainSim::GetCurrentDraw ( ) const

Returns the currently drawn current.

◆ GetGearing()

double frc::sim::DifferentialDrivetrainSim::GetGearing ( ) const

Returns the current gearing reduction of the drivetrain, as output over input.

◆ GetHeading()

Rotation2d frc::sim::DifferentialDrivetrainSim::GetHeading ( ) const

Returns the direction the robot is pointing.

Note that this angle is counterclockwise-positive, while most gyros are clockwise positive.

◆ GetLeftCurrentDraw()

units::ampere_t frc::sim::DifferentialDrivetrainSim::GetLeftCurrentDraw ( ) const

Returns the currently drawn current for the left side.

◆ GetLeftPosition()

units::meter_t frc::sim::DifferentialDrivetrainSim::GetLeftPosition ( ) const
inline

Get the left encoder position in meters.

Returns
The encoder position.

◆ GetLeftVelocity()

units::meters_per_second_t frc::sim::DifferentialDrivetrainSim::GetLeftVelocity ( ) const
inline

Get the left encoder velocity in meters per second.

Returns
The encoder velocity.

◆ GetPose()

Pose2d frc::sim::DifferentialDrivetrainSim::GetPose ( ) const

Returns the current pose.

◆ GetRightCurrentDraw()

units::ampere_t frc::sim::DifferentialDrivetrainSim::GetRightCurrentDraw ( ) const

Returns the currently drawn current for the right side.

◆ GetRightPosition()

units::meter_t frc::sim::DifferentialDrivetrainSim::GetRightPosition ( ) const
inline

Get the right encoder position in meters.

Returns
The encoder position.

◆ GetRightVelocity()

units::meters_per_second_t frc::sim::DifferentialDrivetrainSim::GetRightVelocity ( ) const
inline

Get the right encoder velocity in meters per second.

Returns
The encoder velocity.

◆ SetGearing()

void frc::sim::DifferentialDrivetrainSim::SetGearing ( double  newGearing)

Sets the gearing reduction on the drivetrain.

This is commonly used for shifting drivetrains.

Parameters
newGearingThe new gear ratio, as output over input.

◆ SetInputs()

void frc::sim::DifferentialDrivetrainSim::SetInputs ( units::volt_t  leftVoltage,
units::volt_t  rightVoltage 
)

Sets the applied voltage to the drivetrain.

Note that positive voltage must make that side of the drivetrain travel forward (+X).

Parameters
leftVoltageThe left voltage.
rightVoltageThe right voltage.

◆ SetPose()

void frc::sim::DifferentialDrivetrainSim::SetPose ( const frc::Pose2d pose)

Sets the system pose.

Parameters
poseThe pose.

◆ SetState()

void frc::sim::DifferentialDrivetrainSim::SetState ( const Vectord< 7 > &  state)

Sets the system state.

Parameters
stateThe state.

◆ Update()

void frc::sim::DifferentialDrivetrainSim::Update ( units::second_t  dt)

Updates the simulation.

Parameters
dtThe time that's passed since the last Update(units::second_t) call.

The documentation for this class was generated from the following file: