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