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