WPILibC++ 2024.3.2
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>
10
14
15namespace frc::sim {
16/**
17 * Represents a simulated DC motor mechanism.
18 */
19class DCMotorSim : public LinearSystemSim<2, 1, 2> {
20 public:
21 /**
22 * Creates a simulated DC motor mechanism.
23 *
24 * @param plant The linear system representing the DC motor. This
25 * system can be created with
26 * LinearSystemId::DCMotorSystem().
27 * @param gearbox The type of and number of motors in the DC motor
28 * gearbox.
29 * @param gearing The gearing of the DC motor (numbers greater than
30 * 1 represent reductions).
31 * @param measurementStdDevs The standard deviation of the measurement noise.
32 */
33 DCMotorSim(const LinearSystem<2, 1, 2>& plant, const DCMotor& gearbox,
34 double gearing,
35 const std::array<double, 2>& measurementStdDevs = {0.0, 0.0});
36
37 /**
38 * Creates a simulated DC motor mechanism.
39 *
40 * @param gearbox The type of and number of motors in the DC motor
41 * gearbox.
42 * @param gearing The gearing of the DC motor (numbers greater than
43 * 1 represent reductions).
44 * @param moi The moment of inertia of the DC motor.
45 * @param measurementStdDevs The standard deviation of the measurement noise.
46 */
47 DCMotorSim(const DCMotor& gearbox, double gearing,
48 units::kilogram_square_meter_t moi,
49 const std::array<double, 2>& measurementStdDevs = {0.0, 0.0});
50
52
53 /**
54 * Sets the state of the DC motor.
55 *
56 * @param angularPosition The new position
57 * @param angularVelocity The new velocity
58 */
59 void SetState(units::radian_t angularPosition,
60 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 current draw.
78 *
79 * @return The DC motor current draw.
80 */
81 units::ampere_t GetCurrentDraw() const override;
82
83 /**
84 * Sets the input voltage for the DC motor.
85 *
86 * @param voltage The input voltage.
87 */
88 void SetInputVoltage(units::volt_t voltage);
89
90 private:
91 DCMotor m_gearbox;
92 double m_gearing;
93};
94} // 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 DC motor mechanism.
Definition: DCMotorSim.h:19
units::ampere_t GetCurrentDraw() const override
Returns the DC motor current draw.
void SetInputVoltage(units::volt_t voltage)
Sets the input voltage for the DC motor.
DCMotorSim(const DCMotor &gearbox, double gearing, units::kilogram_square_meter_t moi, const std::array< double, 2 > &measurementStdDevs={0.0, 0.0})
Creates a simulated DC motor mechanism.
void SetState(units::radian_t angularPosition, units::radians_per_second_t angularVelocity)
Sets the state of the DC motor.
units::radians_per_second_t GetAngularVelocity() const
Returns the DC motor velocity.
units::radian_t GetAngularPosition() const
Returns the DC motor position.
DCMotorSim(const LinearSystem< 2, 1, 2 > &plant, const DCMotor &gearbox, double gearing, const std::array< double, 2 > &measurementStdDevs={0.0, 0.0})
Creates a simulated DC motor 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