@@ -106,52 +106,12 @@ Defining the Controller Function
106106
107107Lets start by defining a very simple controller function.
108108
109- The ``controller_function `` must take in the following arguments, in this
110- order:
111-
112- 1. ``time `` (float): The current simulation time in seconds.
113- 2. ``sampling_rate `` (float or ``None ``): The rate at which the controller
114- function is called, measured in Hertz (Hz). It is ``None `` for continuous
115- controllers, so guard any ``1 / sampling_rate `` computation against ``None ``.
116- 3. ``state `` (list): The state vector of the simulation. The state
117- is a list containing the following values, in this order:
118-
119- - ``x ``: The x position of the rocket, in meters.
120- - ``y ``: The y position of the rocket, in meters.
121- - ``z ``: The z position of the rocket, in meters.
122- - ``v_x ``: The x component of the velocity of the rocket, in meters per
123- second.
124- - ``v_y ``: The y component of the velocity of the rocket, in meters per
125- second.
126- - ``v_z ``: The z component of the velocity of the rocket, in meters per
127- second.
128- - ``e0 ``: The first component of the quaternion representing the rotation
129- of the rocket.
130- - ``e1 ``: The second component of the quaternion representing the rotation
131- of the rocket.
132- - ``e2 ``: The third component of the quaternion representing the rotation
133- of the rocket.
134- - ``e3 ``: The fourth component of the quaternion representing the rotation
135- of the rocket.
136- - ``w_x ``: The x component of the angular velocity of the rocket, in
137- radians per second.
138- - ``w_y ``: The y component of the angular velocity of the rocket, in
139- radians per second.
140- - ``w_z ``: The z component of the angular velocity of the rocket, in
141- radians per second.
142-
143- 4. ``state_history `` (list): A record of the rocket's state at each
144- step throughout the simulation. The state_history is organized as
145- a list of lists, with each sublist containing a state vector. The
146- last item in the list always corresponds to the previous state
147- vector, providing a chronological sequence of the rocket's
148- evolving states.
149- 5. ``observed_variables `` (list): A list containing the variables that
150- the controller function returns. The return of each controller
151- function call is appended to the observed_variables list. The
152- initial value in the first step of the simulation of this list is
153- provided by the ``initial_observed_variables `` argument.
154- 6. ``air_brakes `` (AirBrakes): The ``AirBrakes `` instance being controlled.
109+ The ``controller_function `` receives information about the simulation at the
110+ current time step and sets the air brakes' deployment level. See
111+ :ref: `controllers ` for the full description of its arguments and call signature.
112+ For air brakes, the controlled object (the ``air_brakes `` argument) is the
113+ :class: `rocketpy.AirBrakes ` instance, whose ``deployment_level `` the function
114+ sets.
155115
156116Our example ``controller_function `` will deploy the air brakes when the rocket
157117reaches 1500 meters above the ground. The deployment level will be function of the
@@ -227,22 +187,6 @@ Lets define the controller function:
227187
228188.. note ::
229189
230- - The ``controller_function `` accepts 6, 7, or 8 parameters for backward
231- compatibility:
232-
233- * **6 parameters ** (original): ``time ``, ``sampling_rate ``, ``state ``,
234- ``state_history ``, ``observed_variables ``, ``air_brakes ``
235- * **7 parameters ** (with sensors): adds ``sensors `` as the 7th parameter
236- * **8 parameters ** (with environment): adds ``sensors `` and ``environment ``
237- as the 7th and 8th parameters
238-
239- - The **environment parameter ** provides access to atmospheric conditions
240- (wind, temperature, pressure, elevation) without relying on global variables.
241- This enables proper serialization of rockets with air brakes and improves
242- code modularity. Available methods include ``environment.elevation ``,
243- ``environment.wind_velocity_x(altitude) ``, ``environment.wind_velocity_y(altitude) ``,
244- ``environment.speed_of_sound(altitude) ``, and others.
245-
246190 - The code inside the ``controller_function `` can be as complex as needed.
247191 Anything can be implemented inside the function, including filters,
248192 apogee prediction, and any controller logic.
@@ -252,15 +196,10 @@ Lets define the controller function:
252196 0 or higher than 1. If you want to disable this feature, set ``clamp `` to
253197 ``False `` when defining the air brakes.
254198
255- - Anything can be returned by the ``controller_function ``. The returned
256- values will be saved in the ``observed_variables `` list at every time step
257- and can then be accessed by the ``controller_function `` at the next time
258- step. The saved values can also be accessed after the simulation is
259- finished. This is useful for debugging and for plotting the results.
260-
261- - The ``controller_function `` can also be defined in a separate file and
262- imported into the simulation script. This includes importing a ``c `` or
263- ``cpp `` code into Python.
199+ - See :ref: `controllers ` for the controller-function signature (including the
200+ 6/7/8-parameter forms and the ``environment `` argument), how returned
201+ values are stored in ``observed_variables ``, and discrete vs. continuous
202+ controllers.
264203
265204
266205Defining the Drag Coefficient
@@ -375,40 +314,14 @@ controller function. If you want to disable this feature, set ``clamp`` to
375314 For more information on the :class: `rocketpy.AirBrakes ` class
376315 initialization, see :class: `rocketpy.AirBrakes.__init__ ` section.
377316
378- .. _discrete-vs-continuous-controllers :
379-
380- Discrete vs. Continuous Controllers
381- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
382-
383- The ``sampling_rate `` argument determines *when * the controller function is
384- called during the flight simulation:
385-
386- - **Discrete controller ** (``sampling_rate `` set to a number, e.g. ``10 ``):
387- the controller function is called at fixed intervals of ``1 / sampling_rate ``
388- seconds. This mirrors a real flight computer that reads its sensors and
389- updates its actuators at a fixed frequency, and is the recommended choice
390- when you want the simulation to reflect the actual control-loop rate of your
391- hardware.
392- - **Continuous controller ** (``sampling_rate=None ``): the controller function
393- is called at *every * solver step of the numerical integrator. Use this when
394- you want the control law to act as a continuous function of the state rather
395- than a sampled one (for example, when validating a control model
396- analytically).
397-
398- .. warning ::
399-
400- For continuous controllers, ``sampling_rate `` is passed to your controller
401- function as ``None ``. Any computation such as ``1 / sampling_rate `` (a
402- common pattern for rate-limiting deployment, as shown above) must guard
403- against ``None `` to avoid a ``TypeError ``.
404-
405317.. note ::
406318
407- Discrete controllers add their sampling instants as time nodes to the
408- simulation, so remember to set ``time_overshoot=False `` in the ``Flight ``
409- (see below) to make the integrator stop exactly at those instants.
410- Continuous controllers do not add time nodes; they are evaluated on the
411- integrator's own steps.
319+ Because our controller uses ``sampling_rate=10 ``, it is a **discrete **
320+ controller and adds its sampling instants as time nodes to the simulation.
321+ Remember to set ``time_overshoot=False `` in the ``Flight `` (see below) so the
322+ integrator stops exactly at those instants. See
323+ :ref: `discrete-vs-continuous-controllers ` for the difference between discrete
324+ and continuous controllers.
412325
413326Simulating a Flight
414327-------------------
0 commit comments