WPILibC++ 2024.3.2
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
9
13
14namespace frc::sim {
15/**
16 * Represents a simulated flywheel mechanism.
17 */
18class FlywheelSim : public LinearSystemSim<1, 1, 1> {
19 public:
20 /**
21 * Creates a simulated flywheel mechanism.
22 *
23 * @param plant The linear system representing the flywheel. This
24 * system can be created with
25 * LinearSystemId::FlywheelSystem().
26 * @param gearbox The type of and number of motors in the flywheel
27 * gearbox.
28 * @param gearing The gearing of the flywheel (numbers greater than
29 * 1 represent reductions).
30 * @param measurementStdDevs The standard deviation of the measurement noise.
31 */
32 FlywheelSim(const LinearSystem<1, 1, 1>& plant, const DCMotor& gearbox,
33 double gearing,
34 const std::array<double, 1>& measurementStdDevs = {0.0});
35
36 /**
37 * Creates a simulated flywheel mechanism.
38 *
39 * @param gearbox The type of and number of motors in the flywheel
40 * gearbox.
41 * @param gearing The gearing of the flywheel (numbers greater than
42 * 1 represent reductions).
43 * @param moi The moment of inertia of the flywheel.
44 * @param measurementStdDevs The standard deviation of the measurement noise.
45 */
46 FlywheelSim(const DCMotor& gearbox, double gearing,
47 units::kilogram_square_meter_t moi,
48 const std::array<double, 1>& measurementStdDevs = {0.0});
49
51
52 /**
53 * Sets the flywheel's state.
54 *
55 * @param velocity The new velocity
56 */
57 void SetState(units::radians_per_second_t velocity);
58
59 /**
60 * Returns the flywheel velocity.
61 *
62 * @return The flywheel velocity.
63 */
64 units::radians_per_second_t GetAngularVelocity() const;
65
66 /**
67 * Returns the flywheel current draw.
68 *
69 * @return The flywheel current draw.
70 */
71 units::ampere_t GetCurrentDraw() const override;
72
73 /**
74 * Sets the input voltage for the flywheel.
75 *
76 * @param voltage The input voltage.
77 */
78 void SetInputVoltage(units::volt_t voltage);
79
80 private:
81 DCMotor m_gearbox;
82 double m_gearing;
83};
84} // namespace frc::sim
Holds the constants for a DC motor.
Definition: DCMotor.h:20
A plant defined using state-space notation.
Definition: LinearSystem.h:31
Represents a simulated flywheel mechanism.
Definition: FlywheelSim.h:18
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.
units::radians_per_second_t GetAngularVelocity() const
Returns the flywheel velocity.
units::ampere_t GetCurrentDraw() const override
Returns the flywheel current draw.
void SetInputVoltage(units::volt_t voltage)
Sets the input voltage for the flywheel.
void SetState(units::radians_per_second_t velocity)
Sets the flywheel's state.
FlywheelSim(const DCMotor &gearbox, double gearing, units::kilogram_square_meter_t moi, const std::array< double, 1 > &measurementStdDevs={0.0})
Creates a simulated flywheel mechanism.
This class helps simulate linear systems.
Definition: LinearSystemSim.h:31
void SetState(const Vectord< States > &state)
Sets the system state.
Definition: LinearSystemSim.h:107
Definition: XboxControllerSim.h:13