You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source/docs/software/advanced-controls/controllers/trapezoidal-profiles.rst
+16-18Lines changed: 16 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -65,7 +65,7 @@ Putting It All Together
65
65
66
66
.. note:: C++ is often able to infer the type of the inner classes, and thus a simple initializer list (without the class name) can be sent as a parameter. The full class names are included in the example below for clarity.
67
67
68
-
Now that we know how to create a set of constraints and the desired start/end states, we are ready to create our motion profile. The ``TrapezoidProfile`` constructor takes 3 parameters, in order: the constraints, the goal state, and the initial state.
68
+
Now that we know how to create a set of constraints and the desired start/end states, we are ready to create our motion profile. The ``TrapezoidProfile`` constructor takes 1 parameter: the constraints.
69
69
70
70
.. tabs::
71
71
@@ -74,65 +74,63 @@ Now that we know how to create a set of constraints and the desired start/end st
74
74
// Creates a new TrapezoidProfile
75
75
// Profile will have a max vel of 5 meters per second
76
76
// Profile will have a max acceleration of 10 meters per second squared
77
-
// Profile will end stationary at 5 meters
78
-
// Profile will start stationary at zero position
79
-
TrapezoidProfile profile = new TrapezoidProfile(new TrapezoidProfile.Constraints(5, 10),
80
-
new TrapezoidProfile.State(5, 0),
81
-
new TrapezoidProfile.State(0, 0));
77
+
TrapezoidProfile profile = new TrapezoidProfile(new TrapezoidProfile.Constraints(5, 10));
82
78
83
79
.. code-tab:: c++
84
80
85
81
// Creates a new TrapezoidProfile
86
82
// Profile will have a max vel of 5 meters per second
87
83
// Profile will have a max acceleration of 10 meters per second squared
Once we've created a ``TrapezoidProfile``, using it is very simple: to get the profile state at the given time after the profile has started, call the ``calculate()`` method:
93
+
Once we've created a ``TrapezoidProfile``, using it is very simple: to get the profile state at the given time after the profile has started, call the ``calculate()`` method with the goal state and initial state:
102
94
103
95
.. tabs::
104
96
105
97
.. code-tab:: java
106
98
99
+
// Profile will end stationary at 5 meters
100
+
// Profile will start stationary at zero position
107
101
// Returns the motion profile state after 5 seconds of motion
108
-
profile.calculate(5);
102
+
profile.calculate(5, new TrapezoidProfile.State(5, 0), new TrapezoidProfile.State(0, 0));
109
103
110
104
.. code-tab:: c++
111
105
106
+
// Profile will end stationary at 5 meters
107
+
// Profile will start stationary at zero position
112
108
// Returns the motion profile state after 5 seconds of motion
The ``calculate`` method returns a ``TrapezoidProfile.State`` class (the same one that was used to specify the initial/end states when constructing the profile). To use this for actual control, simply pass the contained position and velocity values to whatever controller you wish (for example, a PIDController):
116
+
The ``calculate`` method returns a ``TrapezoidProfile.State`` class (the same one that was used to specify the initial/end states when calculating the profile state). To use this for actual control, simply pass the contained position and velocity values to whatever controller you wish (for example, a PIDController):
119
117
120
118
.. tabs::
121
119
122
120
.. code-tab:: java
123
121
124
-
var setpoint = profile.calculate(elapsedTime);
122
+
var setpoint = profile.calculate(elapsedTime, goalState, initialState);
.. note:: In this example, the profile is re-computed every timestep. This is a somewhat different usage technique than is detailed above, but works according to the same principles - the profile is sampled at a time corresponding to the loop period to get the setpoint for the next loop iteration.
133
+
.. note:: In this example, the initial state is re-computed every timestep. This is a somewhat different usage technique than is detailed above, but works according to the same principles - the profile is sampled at a time corresponding to the loop period to get the setpoint for the next loop iteration.
136
134
137
135
A more complete example of ``TrapezoidProfile`` usage is provided in the ElevatorTrapezoidProfile example project (`Java <https://github.com/wpilibsuite/allwpilib/tree/main/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatortrapezoidprofile>`__, `C++ <https://github.com/wpilibsuite/allwpilib/tree/main/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/cpp>`__):
Copy file name to clipboardExpand all lines: source/docs/software/commandbased/profile-subsystems-commands.rst
+24-14Lines changed: 24 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -144,7 +144,7 @@ The ``TrapezoidProfileCommand`` class (`Java <https://github.wpilib.org/allwpili
144
144
Creating a TrapezoidProfileCommand
145
145
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
146
146
147
-
A ``TrapezoidProfileCommand`` can be created two ways - by subclassing the ``TrapezoidProfileCommand`` class, or by defining the command :ref:`inline <docs/software/commandbased/organizing-command-based:Inline Commands>`. Both methods ultimately extremely similar, and ultimately the choice of which to use comes down to where the user desires that the relevant code be located.
147
+
A ``TrapezoidProfileCommand`` can be created two ways - by subclassing the ``TrapezoidProfileCommand`` class, or by defining the command :ref:`inline <docs/software/commandbased/organizing-command-based:Inline Commands>`. Both methods are ultimately extremely similar, and ultimately the choice of which to use comes down to where the user desires that the relevant code be located.
148
148
149
149
.. note:: If subclassing ``TrapezoidProfileCommand`` and overriding any methods, make sure to call the ``super`` version of those methods! Otherwise, motion profiling functionality will not work properly.
150
150
@@ -154,30 +154,40 @@ In either case, a ``TrapezoidProfileCommand`` is created by passing the necessar
The ``profile`` parameter is the ``TrapezoidProfile`` object that will be executed by the command. By passing this in, users specify the start state, end state, and motion constraints of the profile that the command will use.
174
+
The ``profile`` parameter is the ``TrapezoidProfile`` object that will be executed by the command. By passing this in, users specify the motion constraints of the profile that the command will use.
175
175
176
176
output
177
177
~~~~~~
178
178
179
179
The ``output`` parameter is a function (usually passed as a :ref:`lambda <docs/software/commandbased/index:Lambda Expressions (Java)>`) that consumes the output and setpoint of the control loop. Passing in the ``useOutput`` function in ``PIDCommand`` is functionally analogous to overriding the `useState()`_ function in ``PIDSubsystem``.
180
180
181
+
goal
182
+
~~~~
183
+
184
+
The ``goal`` parameter is a function that supplies the desired state of the motion profile. This can be used to change the goal at runtime if desired.
185
+
186
+
currentState
187
+
~~~~~~~~~~~~
188
+
189
+
The ``currentState`` parameter is a function that supplies the starting state of the motion profile. Combined with ``goal``, this can be used to dynamically generate and follow any motion profile at runtime.
190
+
181
191
requirements
182
192
~~~~~~~~~~~~
183
193
@@ -192,23 +202,23 @@ What does a ``TrapezoidProfileSubsystem`` look like when used in practice? The
0 commit comments