WPILibC++ 2025.2.1
Loading...
Searching...
No Matches
DCMotorSim.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
7#include <units/angle.h>
11#include <units/torque.h>
12
16
17namespace frc::sim {
18/**
19 * Represents a simulated DC motor mechanism.
20 */
21class DCMotorSim : public LinearSystemSim<2, 1, 2> {
22 public:
23 /**
24 * Creates a simulated DC motor mechanism.
25 *
26 * @param plant The linear system representing the DC motor. This
27 * system can be created with LinearSystemId::DCMotorSystem(). If
28 * LinearSystemId::DCMotorSystem(kV, kA) is used, the distance unit must be
29 * radians.
30 * @param gearbox The type of and number of motors in the DC motor
31 * gearbox.
32 * @param measurementStdDevs The standard deviation of the measurement noise.
33 */
34 DCMotorSim(const LinearSystem<2, 1, 2>& plant, const DCMotor& gearbox,
35 const std::array<double, 2>& measurementStdDevs = {0.0, 0.0});
36
38
39 /**
40 * Sets the state of the DC motor.
41 *
42 * @param angularPosition The new position
43 * @param angularVelocity The new velocity
44 */
45 void SetState(units::radian_t angularPosition,
46 units::radians_per_second_t angularVelocity);
47
48 /**
49 * Sets the DC motor's angular position.
50 *
51 * @param angularPosition The new position in radians.
52 */
53 void SetAngle(units::radian_t angularPosition);
54
55 /**
56 * Sets the DC motor's angular velocity.
57 *
58 * @param angularVelocity The new velocity in radians per second.
59 */
60 void SetAngularVelocity(units::radians_per_second_t angularVelocity);
61
62 /**
63 * Returns the DC motor position.
64 *
65 * @return The DC motor position.
66 */
67 units::radian_t GetAngularPosition() const;
68
69 /**
70 * Returns the DC motor velocity.
71 *
72 * @return The DC motor velocity.
73 */
74 units::radians_per_second_t GetAngularVelocity() const;
75
76 /**
77 * Returns the DC motor acceleration.
78 *
79 * @return The DC motor acceleration
80 */
81 units::radians_per_second_squared_t GetAngularAcceleration() const;
82
83 /**
84 * Returns the DC motor torque.
85 *
86 * @return The DC motor torque
87 */
88 units::newton_meter_t GetTorque() const;
89
90 /**
91 * Returns the DC motor current draw.
92 *
93 * @return The DC motor current draw.
94 */
95 units::ampere_t GetCurrentDraw() const;
96
97 /**
98 * Gets the input voltage for the DC motor.
99 *
100 * @return The DC motor input voltage.
101 */
102 units::volt_t GetInputVoltage() const;
103
104 /**
105 * Sets the input voltage for the DC motor.
106 *
107 * @param voltage The input voltage.
108 */
109 void SetInputVoltage(units::volt_t voltage);
110
111 /**
112 * Returns the gearbox.
113 */
114 const DCMotor& GetGearbox() const;
115
116 /**
117 * Returns the gearing;
118 */
119 double GetGearing() const;
120
121 /**
122 * Returns the moment of inertia
123 */
124 units::kilogram_square_meter_t GetJ() const;
125
126 private:
127 DCMotor m_gearbox;
128 double m_gearing;
129 units::kilogram_square_meter_t m_j;
130};
131} // 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 DC motor mechanism.
Definition DCMotorSim.h:21
units::newton_meter_t GetTorque() const
Returns the DC motor torque.
void SetAngularVelocity(units::radians_per_second_t angularVelocity)
Sets the DC motor's angular velocity.
void SetInputVoltage(units::volt_t voltage)
Sets the input voltage for the DC motor.
void SetState(units::radian_t angularPosition, units::radians_per_second_t angularVelocity)
Sets the state of the DC motor.
void SetAngle(units::radian_t angularPosition)
Sets the DC motor's angular position.
const DCMotor & GetGearbox() const
Returns the gearbox.
units::kilogram_square_meter_t GetJ() const
Returns the moment of inertia.
units::radians_per_second_squared_t GetAngularAcceleration() const
Returns the DC motor acceleration.
units::ampere_t GetCurrentDraw() const
Returns the DC motor current draw.
double GetGearing() const
Returns the gearing;.
DCMotorSim(const LinearSystem< 2, 1, 2 > &plant, const DCMotor &gearbox, const std::array< double, 2 > &measurementStdDevs={0.0, 0.0})
Creates a simulated DC motor mechanism.
units::radians_per_second_t GetAngularVelocity() const
Returns the DC motor velocity.
units::radian_t GetAngularPosition() const
Returns the DC motor position.
units::volt_t GetInputVoltage() const
Gets the input voltage for the DC motor.
This class helps simulate linear systems.
Definition LinearSystemSim.h:30
void SetState(const Vectord< States > &state)
Sets the system state.
Definition LinearSystemSim.h:118
Definition SimHooks.h:12