[wpilib] DCMotorSim cleanup/enhancement (#7021)

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
This commit is contained in:
Nicholas Armstrong
2024-10-11 01:09:22 -04:00
committed by GitHub
parent 5acb4109ff
commit 5d9a553104
6 changed files with 245 additions and 69 deletions

View File

@@ -5,8 +5,10 @@
#pragma once
#include <units/angle.h>
#include <units/angular_acceleration.h>
#include <units/angular_velocity.h>
#include <units/moment_of_inertia.h>
#include <units/torque.h>
#include "frc/simulation/LinearSystemSim.h"
#include "frc/system/LinearSystem.h"
@@ -27,26 +29,9 @@ class DCMotorSim : public LinearSystemSim<2, 1, 2> {
* radians.
* @param gearbox The type of and number of motors in the DC motor
* gearbox.
* @param gearing The gearing of the DC motor (numbers greater than
* 1 represent reductions).
* @param measurementStdDevs The standard deviation of the measurement noise.
*/
DCMotorSim(const LinearSystem<2, 1, 2>& plant, const DCMotor& gearbox,
double gearing,
const std::array<double, 2>& measurementStdDevs = {0.0, 0.0});
/**
* Creates a simulated DC motor mechanism.
*
* @param gearbox The type of and number of motors in the DC motor
* gearbox.
* @param gearing The gearing of the DC motor (numbers greater than
* 1 represent reductions).
* @param moi The moment of inertia of the DC motor.
* @param measurementStdDevs The standard deviation of the measurement noise.
*/
DCMotorSim(const DCMotor& gearbox, double gearing,
units::kilogram_square_meter_t moi,
const std::array<double, 2>& measurementStdDevs = {0.0, 0.0});
using LinearSystemSim::SetState;
@@ -74,6 +59,20 @@ class DCMotorSim : public LinearSystemSim<2, 1, 2> {
*/
units::radians_per_second_t GetAngularVelocity() const;
/**
* Returns the DC motor acceleration.
*
* @return The DC motor acceleration
*/
units::radians_per_second_squared_t GetAngularAcceleration() const;
/**
* Returns the DC motor torque.
*
* @return The DC motor torque
*/
units::newton_meter_t GetTorque() const;
/**
* Returns the DC motor current draw.
*
@@ -81,6 +80,13 @@ class DCMotorSim : public LinearSystemSim<2, 1, 2> {
*/
units::ampere_t GetCurrentDraw() const;
/**
* Gets the input voltage for the DC motor.
*
* @return The DC motor input voltage.
*/
units::volt_t GetInputVoltage() const;
/**
* Sets the input voltage for the DC motor.
*
@@ -88,8 +94,24 @@ class DCMotorSim : public LinearSystemSim<2, 1, 2> {
*/
void SetInputVoltage(units::volt_t voltage);
/**
* Returns the gearbox.
*/
const DCMotor& Gearbox() const { return m_gearbox; }
/**
* Returns the gearing;
*/
double Gearing() const { return m_gearing; }
/**
* Returns the moment of inertia
*/
units::kilogram_square_meter_t J() const { return m_j; }
private:
DCMotor m_gearbox;
double m_gearing;
units::kilogram_square_meter_t m_j;
};
} // namespace frc::sim