WPILibC++ 2024.3.2
|
#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... | |
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.
plant | The LinearSystem representing the robot's drivetrain. This system can be created with LinearSystemId::DrivetrainVelocitySystem() or LinearSystemId::IdentifyDrivetrainSystem(). |
trackWidth | The robot's track width. |
driveMotor | A DCMotor representing the left side of the drivetrain. |
gearingRatio | The 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. |
wheelRadius | The radius of the wheels on the drivetrain, in meters. |
measurementStdDevs | Standard 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. |
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.
driveMotor | A DCMotor representing the left side of the drivetrain. |
gearing | The 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. |
J | The moment of inertia of the drivetrain about its center. |
mass | The mass of the drivebase. |
wheelRadius | The radius of the wheels on the drivetrain. |
trackWidth | The robot's track width, or distance between left and right wheels. |
measurementStdDevs | Standard 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. |
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.
u | The input vector. |
|
inlinestatic |
Create a sim for the standard FRC kitbot.
motor | The motors installed in the bot. |
gearing | The gearing reduction used. |
wheelSize | The wheel size. |
measurementStdDevs | Standard 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. |
|
inlinestatic |
Create a sim for the standard FRC kitbot.
motor | The motors installed in the bot. |
gearing | The gearing reduction used. |
wheelSize | The wheel size. |
J | The moment of inertia of the drivebase. This can be calculated using SysId. |
measurementStdDevs | Standard 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. |
Vectord< 7 > frc::sim::DifferentialDrivetrainSim::Dynamics | ( | const Vectord< 7 > & | x, |
const Eigen::Vector2d & | u | ||
) |
The differential drive dynamics function.
x | The state. |
u | The input. |
units::ampere_t frc::sim::DifferentialDrivetrainSim::GetCurrentDraw | ( | ) | const |
Returns the currently drawn current.
double frc::sim::DifferentialDrivetrainSim::GetGearing | ( | ) | const |
Returns the current gearing reduction of the drivetrain, as output over input.
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.
units::ampere_t frc::sim::DifferentialDrivetrainSim::GetLeftCurrentDraw | ( | ) | const |
Returns the currently drawn current for the left side.
|
inline |
Get the left encoder position in meters.
|
inline |
Get the left encoder velocity in meters per second.
Pose2d frc::sim::DifferentialDrivetrainSim::GetPose | ( | ) | const |
Returns the current pose.
units::ampere_t frc::sim::DifferentialDrivetrainSim::GetRightCurrentDraw | ( | ) | const |
Returns the currently drawn current for the right side.
|
inline |
Get the right encoder position in meters.
|
inline |
Get the right encoder velocity in meters per second.
void frc::sim::DifferentialDrivetrainSim::SetGearing | ( | double | newGearing | ) |
Sets the gearing reduction on the drivetrain.
This is commonly used for shifting drivetrains.
newGearing | The new gear ratio, as output over input. |
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).
leftVoltage | The left voltage. |
rightVoltage | The right voltage. |
void frc::sim::DifferentialDrivetrainSim::SetPose | ( | const frc::Pose2d & | pose | ) |
Sets the system pose.
pose | The pose. |
void frc::sim::DifferentialDrivetrainSim::SetState | ( | const Vectord< 7 > & | state | ) |
Sets the system state.
state | The state. |
void frc::sim::DifferentialDrivetrainSim::Update | ( | units::second_t | dt | ) |
Updates the simulation.
dt | The time that's passed since the last Update(units::second_t) call. |