WPILibC++ 2023.4.3
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.
25 * @param gearbox The type of and number of motors in the DC motor
26 * gearbox.
27 * @param gearing The gearing of the DC motor (numbers greater than
28 * 1 represent reductions).
29 * @param measurementStdDevs The standard deviation of the measurement noise.
30 */
31 DCMotorSim(const LinearSystem<2, 1, 2>& plant, const DCMotor& gearbox,
32 double gearing,
33 const std::array<double, 2>& measurementStdDevs = {0.0, 0.0});
34
35 /**
36 * Creates a simulated DC motor mechanism.
37 *
38 * @param gearbox The type of and number of motors in the DC motor
39 * gearbox.
40 * @param gearing The gearing of the DC motor (numbers greater than
41 * 1 represent reductions).
42 * @param moi The moment of inertia of the DC motor.
43 * @param measurementStdDevs The standard deviation of the measurement noise.
44 */
45 DCMotorSim(const DCMotor& gearbox, double gearing,
46 units::kilogram_square_meter_t moi,
47 const std::array<double, 2>& measurementStdDevs = {0.0, 0.0});
48
49 /**
50 * Returns the DC motor position.
51 *
52 * @return The DC motor position.
53 */
54 units::radian_t GetAngularPosition() const;
55
56 /**
57 * Returns the DC motor velocity.
58 *
59 * @return The DC motor velocity.
60 */
61 units::radians_per_second_t GetAngularVelocity() const;
62
63 /**
64 * Returns the DC motor current draw.
65 *
66 * @return The DC motor current draw.
67 */
68 units::ampere_t GetCurrentDraw() const override;
69
70 /**
71 * Sets the input voltage for the DC motor.
72 *
73 * @param voltage The input voltage.
74 */
75 void SetInputVoltage(units::volt_t voltage);
76
77 private:
78 DCMotor m_gearbox;
79 double m_gearing;
80};
81} // 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.
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
Definition: AnalogOutputSim.h:15