WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
FlywheelSim.hpp
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 "wpi/units/angular_acceleration.hpp"
11#include "wpi/units/angular_velocity.hpp"
12#include "wpi/units/moment_of_inertia.hpp"
13#include "wpi/units/torque.hpp"
14
15namespace wpi::sim {
16/**
17 * Represents a simulated flywheel mechanism.
18 */
19class FlywheelSim : public LinearSystemSim<1, 1, 1> {
20 public:
21 /**
22 * Creates a simulated flywheel mechanism.
23 *
24 * @param plant The linear system representing the flywheel. This system can
25 * be created with wpi::math::Models::FlywheelFromPhysicalConstants() or
26 * wpi::math::Models::FlywheelFromSysId().
27 * @param gearbox The type of and number of motors in the flywheel gearbox.
28 * @param measurementStdDevs The standard deviation of the measurement noise.
29 */
31 const wpi::math::DCMotor& gearbox,
32 const std::array<double, 1>& measurementStdDevs = {0.0});
33
35
36 /**
37 * Sets the flywheel's angular velocity.
38 *
39 * @param velocity The new velocity
40 */
41 void SetVelocity(wpi::units::radians_per_second_t velocity);
42
43 /**
44 * Returns the flywheel's velocity.
45 *
46 * @return The flywheel's velocity.
47 */
48 wpi::units::radians_per_second_t GetAngularVelocity() const;
49
50 /**
51 * Returns the flywheel's acceleration.
52 *
53 * @return The flywheel's acceleration
54 */
55 wpi::units::radians_per_second_squared_t GetAngularAcceleration() const;
56
57 /**
58 * Returns the flywheel's torque.
59 *
60 * @return The flywheel's torque
61 */
62 wpi::units::newton_meter_t GetTorque() const;
63
64 /**
65 * Returns the flywheel's current draw.
66 *
67 * @return The flywheel's current draw.
68 */
69 wpi::units::ampere_t GetCurrentDraw() const;
70
71 /**
72 * Gets the input voltage for the flywheel.
73 *
74 * @return The flywheel input voltage.
75 */
76 wpi::units::volt_t GetInputVoltage() const;
77
78 /**
79 * Sets the input voltage for the flywheel.
80 *
81 * @param voltage The input voltage.
82 */
83 void SetInputVoltage(wpi::units::volt_t voltage);
84
85 /**
86 * Returns the gearbox.
87 */
88 wpi::math::DCMotor Gearbox() const { return m_gearbox; }
89
90 /**
91 * Returns the gearing;
92 */
93 double Gearing() const { return m_gearing; }
94
95 /**
96 * Returns the moment of inertia
97 */
98 wpi::units::kilogram_square_meter_t J() const { return m_j; }
99
100 private:
101 wpi::math::DCMotor m_gearbox;
102 double m_gearing;
103 wpi::units::kilogram_square_meter_t m_j;
104};
105} // namespace wpi::sim
Holds the constants for a DC motor.
Definition DCMotor.hpp:19
A plant defined using state-space notation.
Definition LinearSystem.hpp:35
wpi::units::radians_per_second_squared_t GetAngularAcceleration() const
Returns the flywheel's acceleration.
void SetVelocity(wpi::units::radians_per_second_t velocity)
Sets the flywheel's angular velocity.
double Gearing() const
Returns the gearing;.
Definition FlywheelSim.hpp:93
wpi::units::volt_t GetInputVoltage() const
Gets the input voltage for the flywheel.
wpi::units::newton_meter_t GetTorque() const
Returns the flywheel's torque.
wpi::math::DCMotor Gearbox() const
Returns the gearbox.
Definition FlywheelSim.hpp:88
FlywheelSim(const wpi::math::LinearSystem< 1, 1, 1 > &plant, const wpi::math::DCMotor &gearbox, const std::array< double, 1 > &measurementStdDevs={0.0})
Creates a simulated flywheel mechanism.
wpi::units::kilogram_square_meter_t J() const
Returns the moment of inertia.
Definition FlywheelSim.hpp:98
void SetInputVoltage(wpi::units::volt_t voltage)
Sets the input voltage for the flywheel.
wpi::units::radians_per_second_t GetAngularVelocity() const
Returns the flywheel's velocity.
wpi::units::ampere_t GetCurrentDraw() const
Returns the flywheel's current draw.
LinearSystemSim(const wpi::math::LinearSystem< States, Inputs, Outputs > &system, const std::array< double, Outputs > &measurementStdDevs={})
Definition LinearSystemSim.hpp:37
void SetState(const wpi::math::Vectord< States > &state)
Sets the system state.
Definition LinearSystemSim.hpp:117
Definition CTREPCMSim.hpp:13