mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
[wpilib] FlywheelSim cleanup (#6629)
This is a cleanup of the FlywheelSim class with a few added features. - One FlywheelSim constructor that takes a plant, DCMotor, and a optional number of measurementStdDevs. The documentation now states how to construct the plant either through LinearSystemId.createFlywheelSystem or identifyVelocitySystem. - The gearbox, gearing and moment of Inertia (J) are now private final fields. The gearing is determined from the plant in the constructor as well as the moment of inertia. There are getter methods that allow the flywheelSim to return the gearbox, gearing, and moment of inertia. - The getCurrentDrawAmps function now uses m_x instead of getAngularVelocityRadPerSec in accordance with more accuracy and matches the patter in other sims. - Added getter methods for the InputVoltage, angularAcceleration and torque - (Java only) A third getter method for returning the AngularVelocity of the flywheel using a MutableMeasure as a backing field that is set when getAngularVelocity is called. This summarily returns the angularVelocity as just a Measure object. This allows the user of this class to handle unit conversions with less numerical manipulation. Alterations in C++ for this feature were not needed.
This commit is contained in:
committed by
GitHub
parent
8c107e4b75
commit
f42bc45ee8
@@ -4,8 +4,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#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"
|
||||
@@ -22,54 +24,59 @@ class FlywheelSim : public LinearSystemSim<1, 1, 1> {
|
||||
*
|
||||
* @param plant The linear system representing the flywheel. This
|
||||
* system can be created with
|
||||
* LinearSystemId::FlywheelSystem().
|
||||
* LinearSystemId::FlywheelSystem() or
|
||||
* LinearSystemId::IdentifyVelocitySystem().
|
||||
* @param gearbox The type of and number of motors in the flywheel
|
||||
* gearbox.
|
||||
* @param gearing The gearing of the flywheel (numbers greater than
|
||||
* 1 represent reductions).
|
||||
* @param measurementStdDevs The standard deviation of the measurement noise.
|
||||
*/
|
||||
FlywheelSim(const LinearSystem<1, 1, 1>& plant, const DCMotor& gearbox,
|
||||
double gearing,
|
||||
const std::array<double, 1>& measurementStdDevs = {0.0});
|
||||
|
||||
/**
|
||||
* Creates a simulated flywheel mechanism.
|
||||
*
|
||||
* @param gearbox The type of and number of motors in the flywheel
|
||||
* gearbox.
|
||||
* @param gearing The gearing of the flywheel (numbers greater than
|
||||
* 1 represent reductions).
|
||||
* @param moi The moment of inertia of the flywheel.
|
||||
* @param measurementStdDevs The standard deviation of the measurement noise.
|
||||
*/
|
||||
FlywheelSim(const DCMotor& gearbox, double gearing,
|
||||
units::kilogram_square_meter_t moi,
|
||||
const std::array<double, 1>& measurementStdDevs = {0.0});
|
||||
|
||||
using LinearSystemSim::SetState;
|
||||
|
||||
/**
|
||||
* Sets the flywheel's state.
|
||||
* Sets the flywheel's angular velocity.
|
||||
*
|
||||
* @param velocity The new velocity
|
||||
*/
|
||||
void SetState(units::radians_per_second_t velocity);
|
||||
void SetVelocity(units::radians_per_second_t velocity);
|
||||
|
||||
/**
|
||||
* Returns the flywheel velocity.
|
||||
* Returns the flywheel's velocity.
|
||||
*
|
||||
* @return The flywheel velocity.
|
||||
* @return The flywheel's velocity.
|
||||
*/
|
||||
units::radians_per_second_t GetAngularVelocity() const;
|
||||
|
||||
/**
|
||||
* Returns the flywheel current draw.
|
||||
* Returns the flywheel's acceleration.
|
||||
*
|
||||
* @return The flywheel current draw.
|
||||
* @return The flywheel's acceleration
|
||||
*/
|
||||
units::radians_per_second_squared_t GetAngularAcceleration() const;
|
||||
|
||||
/**
|
||||
* Returns the flywheel's torque.
|
||||
*
|
||||
* @return The flywheel's torque
|
||||
*/
|
||||
units::newton_meter_t GetTorque() const;
|
||||
|
||||
/**
|
||||
* Returns the flywheel's current draw.
|
||||
*
|
||||
* @return The flywheel's current draw.
|
||||
*/
|
||||
units::ampere_t GetCurrentDraw() const;
|
||||
|
||||
/**
|
||||
* Gets the input voltage for the flywheel.
|
||||
*
|
||||
* @return The flywheel input voltage.
|
||||
*/
|
||||
units::volt_t GetInputVoltage() const;
|
||||
|
||||
/**
|
||||
* Sets the input voltage for the flywheel.
|
||||
*
|
||||
@@ -77,8 +84,24 @@ class FlywheelSim : public LinearSystemSim<1, 1, 1> {
|
||||
*/
|
||||
void SetInputVoltage(units::volt_t voltage);
|
||||
|
||||
/**
|
||||
* Returns the gearbox.
|
||||
*/
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user