Skip to content

Commit

Permalink
docs: Docstring for AngleController
Browse files Browse the repository at this point in the history
  • Loading branch information
iwishiwasaneagle committed Mar 16, 2023
1 parent 0c7c2c6 commit 8daafa2
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/jdrones/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,45 @@ def reset(self):


class AngleController(Controller):
"""
Special controller type when the inputs are angles that wrap around
:math:`2\\pi`.
"""

angle: bool
"""Flag to determine which method to use for calculating the error"""

def __init__(self, angle=False):
self.angle = angle

@staticmethod
def angle_error(measured, setpoint):
def angle_error(measured: float, setpoint: float) -> float:
"""
Calculate the angle error through
.. math::
\\begin{align}
\\hat x_{\\mathit{wrapped}} &=
\\begin{cases}
\\hat x - 2\\pi&, \\hat x > 0 \\\\
\\hat x + 2\\pi&, \\mathit{else}
\\end{cases}\\\\
e &= \\begin{cases}
u - \\hat x&, |u - \\hat x|<|u-\\hat x_{\\mathit{wrapped}}|\\\\
u-\\hat x_{\\mathit{wrapped}}&,\\mathit{else}
\\end{cases}
\\end{align}
Parameters
----------
measured : float
setpoint : float
Returns
-------
float
Error
"""
measured_wrapped = measured
if measured > 0:
measured_wrapped -= 2 * np.pi
Expand Down

0 comments on commit 8daafa2

Please sign in to comment.