WPILibC++ 2025.0.0-alpha-1-9-ga2beb75
FlywheelSim.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
10#include <units/torque.h>
11
15
16namespace frc::sim {
17/**
18 * Represents a simulated flywheel mechanism.
19 */
20class FlywheelSim : public LinearSystemSim<1, 1, 1> {
21 public:
22 /**
23 * Creates a simulated flywheel mechanism.
24 *
25 * @param plant The linear system representing the flywheel. This
26 * system can be created with
27 * LinearSystemId::FlywheelSystem() or
28 * LinearSystemId::IdentifyVelocitySystem().
29 * @param gearbox The type of and number of motors in the flywheel
30 * gearbox.
31 * @param measurementStdDevs The standard deviation of the measurement noise.
32 */
33 FlywheelSim(const LinearSystem<1, 1, 1>& plant, const DCMotor& gearbox,
34 const std::array<double, 1>& measurementStdDevs = {0.0});
35
37
38 /**
39 * Sets the flywheel's angular velocity.
40 *
41 * @param velocity The new velocity
42 */
43 void SetVelocity(units::radians_per_second_t velocity);
44
45 /**
46 * Returns the flywheel's velocity.
47 *
48 * @return The flywheel's velocity.
49 */
50 units::radians_per_second_t GetAngularVelocity() const;
51
52 /**
53 * Returns the flywheel's acceleration.
54 *
55 * @return The flywheel's acceleration
56 */
57 units::radians_per_second_squared_t GetAngularAcceleration() const;
58
59 /**
60 * Returns the flywheel's torque.
61 *
62 * @return The flywheel's torque
63 */
64 units::newton_meter_t GetTorque() const;
65
66 /**
67 * Returns the flywheel's current draw.
68 *
69 * @return The flywheel's current draw.
70 */
71 units::ampere_t GetCurrentDraw() const;
72
73 /**
74 * Gets the input voltage for the flywheel.
75 *
76 * @return The flywheel input voltage.
77 */
78 units::volt_t GetInputVoltage() const;
79
80 /**
81 * Sets the input voltage for the flywheel.
82 *
83 * @param voltage The input voltage.
84 */
85 void SetInputVoltage(units::volt_t voltage);
86
87 /**
88 * Returns the gearbox.
89 */
90 DCMotor Gearbox() const { return m_gearbox; }
91
92 /**
93 * Returns the gearing;
94 */
95 double Gearing() const { return m_gearing; }
96
97 /**
98 * Returns the moment of inertia
99 */
100 units::kilogram_square_meter_t J() const { return m_j; }
101
102 private:
103 DCMotor m_gearbox;
104 double m_gearing;
105 units::kilogram_square_meter_t m_j;
106};
107} // namespace frc::sim
Holds the constants for a DC motor.
Definition: DCMotor.h:20
A plant defined using state-space notation.
Definition: LinearSystem.h:35
Represents a simulated flywheel mechanism.
Definition: FlywheelSim.h:20
void SetVelocity(units::radians_per_second_t velocity)
Sets the flywheel's angular velocity.
units::radians_per_second_t GetAngularVelocity() const
Returns the flywheel's velocity.
units::kilogram_square_meter_t J() const
Returns the moment of inertia.
Definition: FlywheelSim.h:100
DCMotor Gearbox() const
Returns the gearbox.
Definition: FlywheelSim.h:90
void SetInputVoltage(units::volt_t voltage)
Sets the input voltage for the flywheel.
double Gearing() const
Returns the gearing;.
Definition: FlywheelSim.h:95
units::ampere_t GetCurrentDraw() const
Returns the flywheel's current draw.
units::radians_per_second_squared_t GetAngularAcceleration() const
Returns the flywheel's acceleration.
units::volt_t GetInputVoltage() const
Gets the input voltage for the flywheel.
FlywheelSim(const LinearSystem< 1, 1, 1 > &plant, const DCMotor &gearbox, const std::array< double, 1 > &measurementStdDevs={0.0})
Creates a simulated flywheel mechanism.
units::newton_meter_t GetTorque() const
Returns the flywheel's torque.
This class helps simulate linear systems.
Definition: LinearSystemSim.h:31
void SetState(const Vectord< States > &state)
Sets the system state.
Definition: LinearSystemSim.h:119
Definition: ADXL345Sim.h:14