mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
SCRIPT: wpiformat
This commit is contained in:
committed by
Peter Johnson
parent
ae6bdc9d25
commit
2109161534
@@ -31,9 +31,9 @@ class BatterySim {
|
||||
* @param currents The currents drawn from the battery.
|
||||
* @return The battery's voltage under load.
|
||||
*/
|
||||
static wpi::units::volt_t Calculate(wpi::units::volt_t nominalVoltage,
|
||||
wpi::units::ohm_t resistance,
|
||||
std::span<const wpi::units::ampere_t> currents) {
|
||||
static wpi::units::volt_t Calculate(
|
||||
wpi::units::volt_t nominalVoltage, wpi::units::ohm_t resistance,
|
||||
std::span<const wpi::units::ampere_t> currents) {
|
||||
return std::max(0_V, nominalVoltage - std::accumulate(currents.begin(),
|
||||
currents.end(), 0_A) *
|
||||
resistance);
|
||||
@@ -69,7 +69,8 @@ class BatterySim {
|
||||
* @param currents The currents drawn from the battery.
|
||||
* @return The battery's voltage under load.
|
||||
*/
|
||||
static wpi::units::volt_t Calculate(std::span<const wpi::units::ampere_t> currents) {
|
||||
static wpi::units::volt_t Calculate(
|
||||
std::span<const wpi::units::ampere_t> currents) {
|
||||
return Calculate(12_V, 0.02_Ohm, currents);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,13 +24,14 @@ class DCMotorSim : public LinearSystemSim<2, 1, 2> {
|
||||
*
|
||||
* @param plant The linear system representing the DC motor. This
|
||||
* system can be created with wpi::math::LinearSystemId::DCMotorSystem(). If
|
||||
* wpi::math::LinearSystemId::DCMotorSystem(kV, kA) is used, the distance unit must be
|
||||
* radians.
|
||||
* wpi::math::LinearSystemId::DCMotorSystem(kV, kA) is used, the distance unit
|
||||
* must be radians.
|
||||
* @param gearbox The type of and number of motors in the DC motor
|
||||
* gearbox.
|
||||
* @param measurementStdDevs The standard deviation of the measurement noise.
|
||||
*/
|
||||
DCMotorSim(const wpi::math::LinearSystem<2, 1, 2>& plant, const wpi::math::DCMotor& gearbox,
|
||||
DCMotorSim(const wpi::math::LinearSystem<2, 1, 2>& plant,
|
||||
const wpi::math::DCMotor& gearbox,
|
||||
const std::array<double, 2>& measurementStdDevs = {0.0, 0.0});
|
||||
|
||||
using LinearSystemSim::SetState;
|
||||
|
||||
@@ -20,12 +20,13 @@ class DifferentialDrivetrainSim {
|
||||
/**
|
||||
* Creates a simulated differential drivetrain.
|
||||
*
|
||||
* @param plant The wpi::math::LinearSystem representing the robot's drivetrain. This
|
||||
* system can be created with
|
||||
* @param plant The wpi::math::LinearSystem representing the robot's
|
||||
* drivetrain. This system can be created with
|
||||
* wpi::math::LinearSystemId::DrivetrainVelocitySystem() or
|
||||
* wpi::math::LinearSystemId::IdentifyDrivetrainSystem().
|
||||
* @param trackwidth The robot's trackwidth.
|
||||
* @param driveMotor A wpi::math::DCMotor representing the left side of the drivetrain.
|
||||
* @param driveMotor A wpi::math::DCMotor representing the left side of the
|
||||
* drivetrain.
|
||||
* @param 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.
|
||||
@@ -41,13 +42,15 @@ class DifferentialDrivetrainSim {
|
||||
*/
|
||||
DifferentialDrivetrainSim(
|
||||
wpi::math::LinearSystem<2, 2, 2> plant, wpi::units::meter_t trackwidth,
|
||||
wpi::math::DCMotor driveMotor, double gearingRatio, wpi::units::meter_t wheelRadius,
|
||||
wpi::math::DCMotor driveMotor, double gearingRatio,
|
||||
wpi::units::meter_t wheelRadius,
|
||||
const std::array<double, 7>& measurementStdDevs = {});
|
||||
|
||||
/**
|
||||
* Creates a simulated differential drivetrain.
|
||||
*
|
||||
* @param driveMotor A wpi::math::DCMotor representing the left side of the drivetrain.
|
||||
* @param driveMotor A wpi::math::DCMotor representing the left side of the
|
||||
* drivetrain.
|
||||
* @param 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.
|
||||
@@ -67,9 +70,9 @@ class DifferentialDrivetrainSim {
|
||||
* starting point.
|
||||
*/
|
||||
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,
|
||||
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 = {});
|
||||
|
||||
/**
|
||||
@@ -88,7 +91,8 @@ class DifferentialDrivetrainSim {
|
||||
* @param leftVoltage The left voltage.
|
||||
* @param rightVoltage The right voltage.
|
||||
*/
|
||||
void SetInputs(wpi::units::volt_t leftVoltage, wpi::units::volt_t rightVoltage);
|
||||
void SetInputs(wpi::units::volt_t leftVoltage,
|
||||
wpi::units::volt_t rightVoltage);
|
||||
|
||||
/**
|
||||
* Sets the gearing reduction on the drivetrain. This is commonly used for
|
||||
@@ -101,8 +105,8 @@ class DifferentialDrivetrainSim {
|
||||
/**
|
||||
* Updates the simulation.
|
||||
*
|
||||
* @param dt The time that's passed since the last Update(wpi::units::second_t)
|
||||
* call.
|
||||
* @param dt The time that's passed since the last
|
||||
* Update(wpi::units::second_t) call.
|
||||
*/
|
||||
void Update(wpi::units::second_t dt);
|
||||
|
||||
@@ -193,7 +197,8 @@ class DifferentialDrivetrainSim {
|
||||
* @param u The input.
|
||||
* @return The state derivative with respect to time.
|
||||
*/
|
||||
wpi::math::Vectord<7> Dynamics(const wpi::math::Vectord<7>& x, const Eigen::Vector2d& u);
|
||||
wpi::math::Vectord<7> Dynamics(const wpi::math::Vectord<7>& x,
|
||||
const Eigen::Vector2d& u);
|
||||
|
||||
class State {
|
||||
public:
|
||||
@@ -234,14 +239,17 @@ class DifferentialDrivetrainSim {
|
||||
class KitbotMotor {
|
||||
public:
|
||||
/// One CIM motor per drive side.
|
||||
static constexpr wpi::math::DCMotor SingleCIMPerSide = wpi::math::DCMotor::CIM(1);
|
||||
static constexpr wpi::math::DCMotor SingleCIMPerSide =
|
||||
wpi::math::DCMotor::CIM(1);
|
||||
/// Two CIM motors per drive side.
|
||||
static constexpr wpi::math::DCMotor DualCIMPerSide = wpi::math::DCMotor::CIM(2);
|
||||
static constexpr wpi::math::DCMotor DualCIMPerSide =
|
||||
wpi::math::DCMotor::CIM(2);
|
||||
/// One Mini CIM motor per drive side.
|
||||
static constexpr wpi::math::DCMotor SingleMiniCIMPerSide =
|
||||
wpi::math::DCMotor::MiniCIM(1);
|
||||
/// Two Mini CIM motors per drive side.
|
||||
static constexpr wpi::math::DCMotor DualMiniCIMPerSide = wpi::math::DCMotor::MiniCIM(2);
|
||||
static constexpr wpi::math::DCMotor DualMiniCIMPerSide =
|
||||
wpi::math::DCMotor::MiniCIM(2);
|
||||
/// One Falcon 500 motor per drive side.
|
||||
static constexpr wpi::math::DCMotor SingleFalcon500PerSide =
|
||||
wpi::math::DCMotor::Falcon500(1);
|
||||
@@ -249,9 +257,11 @@ class DifferentialDrivetrainSim {
|
||||
static constexpr wpi::math::DCMotor DualFalcon500PerSide =
|
||||
wpi::math::DCMotor::Falcon500(2);
|
||||
/// One NEO motor per drive side.
|
||||
static constexpr wpi::math::DCMotor SingleNEOPerSide = wpi::math::DCMotor::NEO(1);
|
||||
static constexpr wpi::math::DCMotor SingleNEOPerSide =
|
||||
wpi::math::DCMotor::NEO(1);
|
||||
/// Two NEO motors per drive side.
|
||||
static constexpr wpi::math::DCMotor DualNEOPerSide = wpi::math::DCMotor::NEO(2);
|
||||
static constexpr wpi::math::DCMotor DualNEOPerSide =
|
||||
wpi::math::DCMotor::NEO(2);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -285,9 +295,9 @@ class DifferentialDrivetrainSim {
|
||||
const std::array<double, 7>& measurementStdDevs = {}) {
|
||||
// MOI estimation -- note that I = mr² for point masses
|
||||
wpi::units::kilogram_square_meter_t batteryMoi = 12.5_lb * 10_in * 10_in;
|
||||
wpi::units::kilogram_square_meter_t gearboxMoi = (2.8_lb + 2.0_lb) *
|
||||
2 // CIM plus toughbox per side
|
||||
* (26_in / 2) * (26_in / 2);
|
||||
wpi::units::kilogram_square_meter_t gearboxMoi =
|
||||
(2.8_lb + 2.0_lb) * 2 // CIM plus toughbox per side
|
||||
* (26_in / 2) * (26_in / 2);
|
||||
|
||||
return DifferentialDrivetrainSim{
|
||||
motor, gearing, batteryMoi + gearboxMoi, 60_lb,
|
||||
|
||||
@@ -19,12 +19,13 @@ namespace wpi::sim {
|
||||
class ElevatorSim : public LinearSystemSim<2, 1, 2> {
|
||||
public:
|
||||
template <typename Distance>
|
||||
using Velocity_t = wpi::units::unit_t<
|
||||
wpi::units::compound_unit<Distance, wpi::units::inverse<wpi::units::seconds>>>;
|
||||
using Velocity_t = wpi::units::unit_t<wpi::units::compound_unit<
|
||||
Distance, wpi::units::inverse<wpi::units::seconds>>>;
|
||||
|
||||
template <typename Distance>
|
||||
using Acceleration_t = wpi::units::unit_t<wpi::units::compound_unit<
|
||||
wpi::units::compound_unit<Distance, wpi::units::inverse<wpi::units::seconds>>,
|
||||
wpi::units::compound_unit<Distance,
|
||||
wpi::units::inverse<wpi::units::seconds>>,
|
||||
wpi::units::inverse<wpi::units::seconds>>>;
|
||||
|
||||
/**
|
||||
@@ -41,9 +42,10 @@ class ElevatorSim : public LinearSystemSim<2, 1, 2> {
|
||||
* @param startingHeight The starting height of the elevator.
|
||||
* @param measurementStdDevs The standard deviation of the measurements.
|
||||
*/
|
||||
ElevatorSim(const wpi::math::LinearSystem<2, 1, 2>& plant, const wpi::math::DCMotor& gearbox,
|
||||
wpi::units::meter_t minHeight, wpi::units::meter_t maxHeight,
|
||||
bool simulateGravity, wpi::units::meter_t startingHeight,
|
||||
ElevatorSim(const wpi::math::LinearSystem<2, 1, 2>& plant,
|
||||
const wpi::math::DCMotor& gearbox, wpi::units::meter_t minHeight,
|
||||
wpi::units::meter_t maxHeight, bool simulateGravity,
|
||||
wpi::units::meter_t startingHeight,
|
||||
const std::array<double, 2>& measurementStdDevs = {0.0, 0.0});
|
||||
|
||||
/**
|
||||
@@ -63,9 +65,10 @@ class ElevatorSim : public LinearSystemSim<2, 1, 2> {
|
||||
* @param measurementStdDevs The standard deviation of the measurements.
|
||||
*/
|
||||
ElevatorSim(const wpi::math::DCMotor& gearbox, double gearing,
|
||||
wpi::units::kilogram_t carriageMass, wpi::units::meter_t drumRadius,
|
||||
wpi::units::meter_t minHeight, wpi::units::meter_t maxHeight,
|
||||
bool simulateGravity, wpi::units::meter_t startingHeight,
|
||||
wpi::units::kilogram_t carriageMass,
|
||||
wpi::units::meter_t drumRadius, wpi::units::meter_t minHeight,
|
||||
wpi::units::meter_t maxHeight, bool simulateGravity,
|
||||
wpi::units::meter_t startingHeight,
|
||||
const std::array<double, 2>& measurementStdDevs = {0.0, 0.0});
|
||||
|
||||
/**
|
||||
@@ -98,7 +101,8 @@ class ElevatorSim : public LinearSystemSim<2, 1, 2> {
|
||||
* @param position The new position
|
||||
* @param velocity The new velocity
|
||||
*/
|
||||
void SetState(wpi::units::meter_t position, wpi::units::meters_per_second_t velocity);
|
||||
void SetState(wpi::units::meter_t position,
|
||||
wpi::units::meters_per_second_t velocity);
|
||||
|
||||
/**
|
||||
* Returns whether the elevator would hit the lower limit.
|
||||
@@ -166,8 +170,9 @@ class ElevatorSim : public LinearSystemSim<2, 1, 2> {
|
||||
* @param u The system inputs (voltage).
|
||||
* @param dt The time difference between controller updates.
|
||||
*/
|
||||
wpi::math::Vectord<2> UpdateX(const wpi::math::Vectord<2>& currentXhat, const wpi::math::Vectord<1>& u,
|
||||
wpi::units::second_t dt) override;
|
||||
wpi::math::Vectord<2> UpdateX(const wpi::math::Vectord<2>& currentXhat,
|
||||
const wpi::math::Vectord<1>& u,
|
||||
wpi::units::second_t dt) override;
|
||||
|
||||
private:
|
||||
wpi::math::DCMotor m_gearbox;
|
||||
|
||||
@@ -29,7 +29,8 @@ class FlywheelSim : public LinearSystemSim<1, 1, 1> {
|
||||
* gearbox.
|
||||
* @param measurementStdDevs The standard deviation of the measurement noise.
|
||||
*/
|
||||
FlywheelSim(const wpi::math::LinearSystem<1, 1, 1>& plant, const wpi::math::DCMotor& gearbox,
|
||||
FlywheelSim(const wpi::math::LinearSystem<1, 1, 1>& plant,
|
||||
const wpi::math::DCMotor& gearbox,
|
||||
const std::array<double, 1>& measurementStdDevs = {0.0});
|
||||
|
||||
using LinearSystemSim::SetState;
|
||||
|
||||
@@ -131,9 +131,9 @@ class LinearSystemSim {
|
||||
* @param u The system inputs (usually voltage).
|
||||
* @param dt The time difference between controller updates.
|
||||
*/
|
||||
virtual wpi::math::Vectord<States> UpdateX(const wpi::math::Vectord<States>& currentXhat,
|
||||
const wpi::math::Vectord<Inputs>& u,
|
||||
wpi::units::second_t dt) {
|
||||
virtual wpi::math::Vectord<States> UpdateX(
|
||||
const wpi::math::Vectord<States>& currentXhat,
|
||||
const wpi::math::Vectord<Inputs>& u, wpi::units::second_t dt) {
|
||||
return m_plant.CalculateX(currentXhat, u, dt);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,8 @@ class SingleJointedArmSim : public LinearSystemSim<2, 1, 2> {
|
||||
*/
|
||||
SingleJointedArmSim(const wpi::math::LinearSystem<2, 1, 2>& system,
|
||||
const wpi::math::DCMotor& gearbox, double gearing,
|
||||
wpi::units::meter_t armLength, wpi::units::radian_t minAngle,
|
||||
wpi::units::meter_t armLength,
|
||||
wpi::units::radian_t minAngle,
|
||||
wpi::units::radian_t maxAngle, bool simulateGravity,
|
||||
wpi::units::radian_t startingAngle,
|
||||
const std::array<double, 2>& measurementStdDevs = {0.0,
|
||||
@@ -57,13 +58,12 @@ class SingleJointedArmSim : public LinearSystemSim<2, 1, 2> {
|
||||
* @param startingAngle The initial position of the arm.
|
||||
* @param measurementStdDevs The standard deviation of the measurement noise.
|
||||
*/
|
||||
SingleJointedArmSim(const wpi::math::DCMotor& gearbox, double gearing,
|
||||
wpi::units::kilogram_square_meter_t moi,
|
||||
wpi::units::meter_t armLength, wpi::units::radian_t minAngle,
|
||||
wpi::units::radian_t maxAngle, bool simulateGravity,
|
||||
wpi::units::radian_t startingAngle,
|
||||
const std::array<double, 2>& measurementStdDevs = {0.0,
|
||||
0.0});
|
||||
SingleJointedArmSim(
|
||||
const wpi::math::DCMotor& gearbox, double gearing,
|
||||
wpi::units::kilogram_square_meter_t moi, wpi::units::meter_t armLength,
|
||||
wpi::units::radian_t minAngle, wpi::units::radian_t maxAngle,
|
||||
bool simulateGravity, wpi::units::radian_t startingAngle,
|
||||
const std::array<double, 2>& measurementStdDevs = {0.0, 0.0});
|
||||
|
||||
using LinearSystemSim::SetState;
|
||||
|
||||
@@ -74,7 +74,8 @@ class SingleJointedArmSim : public LinearSystemSim<2, 1, 2> {
|
||||
* @param angle The new angle.
|
||||
* @param velocity The new angular velocity.
|
||||
*/
|
||||
void SetState(wpi::units::radian_t angle, wpi::units::radians_per_second_t velocity);
|
||||
void SetState(wpi::units::radian_t angle,
|
||||
wpi::units::radians_per_second_t velocity);
|
||||
|
||||
/**
|
||||
* Returns whether the arm would hit the lower limit.
|
||||
@@ -156,8 +157,9 @@ class SingleJointedArmSim : public LinearSystemSim<2, 1, 2> {
|
||||
* @param u The system inputs (voltage).
|
||||
* @param dt The time difference between controller updates.
|
||||
*/
|
||||
wpi::math::Vectord<2> UpdateX(const wpi::math::Vectord<2>& currentXhat, const wpi::math::Vectord<1>& u,
|
||||
wpi::units::second_t dt) override;
|
||||
wpi::math::Vectord<2> UpdateX(const wpi::math::Vectord<2>& currentXhat,
|
||||
const wpi::math::Vectord<1>& u,
|
||||
wpi::units::second_t dt) override;
|
||||
|
||||
private:
|
||||
wpi::units::meter_t m_armLen;
|
||||
|
||||
Reference in New Issue
Block a user