Skip to content

Commit ca82e12

Browse files
Angle wrap example with LQR (#1798)
* angle wrap example with LQR * Update source/docs/software/advanced-controls/state-space/state-space-flywheel-walkthrough.rst Co-authored-by: Tyler Veness <[email protected]> Co-authored-by: Tyler Veness <[email protected]>
1 parent 783c4d3 commit ca82e12

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

source/docs/software/advanced-controls/state-space/state-space-flywheel-walkthrough.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,26 @@ Once we have our ``LinearSystemLoop``, the only thing left to do is actually run
251251
:lines: 91-113
252252
:linenos:
253253
:lineno-start: 91
254+
255+
Angle Wrap with LQR
256+
-------------------
257+
258+
Mechanisms with a continuous angle can have that angle wrapped by calling the code below instead of ``lqr.Calculate(x, r)``.
259+
260+
.. tabs::
261+
262+
.. group-tab:: Java
263+
264+
.. code-block:: Java
265+
266+
var error = lqr.getR().minus(x);
267+
error.set(0, 0, MathUtil.angleModulus(error.get(0, 0)));
268+
var u = lqr.getK().times(error);
269+
270+
.. group-tab:: C++
271+
272+
.. code-block:: C++
273+
274+
Eigen::Vector<double, 2> error = lqr.R() - x;
275+
error(0) = frc::AngleModulus(units::radian_t{error(0)}).value();
276+
Eigen::Vector<double, 2> u = lqr.K() * error;

0 commit comments

Comments
 (0)