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
A function that takes the current state of the simulation as input and returns a boolean value. The event will be triggered when this function returns True.
10
+
A function that must return a boolean value. The event will be
11
+
triggered when this function returns True. The function should be
12
+
defined with the following signature: trigger(**kwargs), where
13
+
kwargs is a dictionary containing the keys:
14
+
15
+
- `"time"` (float): The current simulation time in seconds.
16
+
- `"state"` (list): The state vector of the simulation, structured
17
+
as `[x, y, z, vx, vy, vz, e0, e1, e2, e3, wx, wy, wz]`.
18
+
- `"state_dot"` (list): The time derivative of the state vector,
19
+
structured as `[vx, vy, vz, ax, ay, az, e0_dot, e1_dot, e2_dot, e3_dot, wx_dot, wy_dot, wz_dot]`.
20
+
- `"sampling_rate"` (float or None): The sampling rate of the
21
+
event, in seconds. If None, the event will be checked for
22
+
triggering at every time step of the simulation. If a float
23
+
value is provided, the event will only be checked for
24
+
triggering at that specific time interval.
25
+
- `"sensors"` (list): A list of sensors that are attached to the
26
+
rocket. The most recent measurements of the sensors are provided
27
+
with the ``sensor.measurement`` attribute. The sensors are
28
+
listed in the same order as they are added to the rocket.
29
+
- `"environment"` (Environment): The current environment object
30
+
assigned to the simulation.
31
+
- `"rocket"` (Rocket): The current rocket object assigned to the
32
+
simulation.
33
+
- `"phase"` (FlightPhase): The current flight phase object.
34
+
- `"phase_index"` (int): The index of the current flight phase.
35
+
- `"node_index"` (int): The index of the current node in the
36
+
current flight phase.
37
+
- Any additional custom key-value pairs provided via the
38
+
`event_context` parameter (see below).
39
+
9
40
action : function
10
-
A function that takes the current state of the simulation as input and performs some action when the event is triggered.
41
+
A function that will be executed when the event is triggered. The
42
+
function should be defined with the following signature:
43
+
action(**kwargs), where kwargs is a dictionary containing the same
44
+
keys as the trigger function. The action function can also modify
45
+
the state of the simulation by returning a dictionary with the keys:
46
+
- `"state"` (list): A new state vector to replace the current state
47
+
vector. The structure of the state vector is the same as the
48
+
one provided in the trigger function.
49
+
- `"disable_event"` (bool): If True, the event will not be
50
+
checked for triggering again after being triggered, making
51
+
it a one-time event. Defaults to True.
52
+
- `"new_events"` (list): A list of new Event objects to be added
53
+
to the simulation when the event is triggered. This can be
54
+
used to create events that spawn new events when they are
55
+
triggered, such as a parachute deployment event that spawns
56
+
a new event to check for the parachute deployment after a
57
+
certain time delay.
58
+
- `"remove_events"` (list): A list of Event objects to be
59
+
removed from the simulation when the event is triggered. This
60
+
can be used to create events that remove other events when
61
+
they are triggered, such as a parachute deployment event that
62
+
removes the apogee event when it is triggered.
63
+
- Any other key-value pairs defined in `event_context` will
64
+
also be included. These allow you to maintain custom state or
65
+
counters across multiple trigger and action calls. Use cases
66
+
include: tracking the number of times an event has been triggered
67
+
(e.g., `{"trigger_count": 0}`), recording the time of the last
68
+
trigger (e.g., `{"last_trigger_time": None}`), or any other
69
+
custom data your trigger/action functions need to share state.
70
+
71
+
Example: If you initialize the event with
72
+
`event_context={"trigger_count": 0}`, your trigger and action
73
+
functions will receive `trigger_count=0` in their kwargs dict.
74
+
You can then update this value in the action function by
75
+
including it in the returned dictionary (e.g.,
76
+
`{"trigger_count": 1}`), and it will be passed to subsequent
77
+
trigger/action calls.
78
+
11
79
name : str
12
80
A name for the event, used for identification purposes.
13
-
81
+
event_context : dict, optional
82
+
A dictionary of custom key-value pairs that will be passed to the
83
+
trigger and action functions. This allows you to initialize and
84
+
maintain custom state that persists across multiple trigger/action
85
+
calls. For example, `event_context={"trigger_count": 0,
86
+
"last_trigger_time": None}` can be used to track event state.
87
+
When the action function returns a dictionary with updated values
88
+
(e.g., `{"trigger_count": 1}`), those values persist and are
89
+
passed to subsequent calls. Defaults to an empty dictionary if not
# A function that takes the current state of the simulation as input and returns a boolean value. The event will be triggered when this function returns True.
75
-
# action : function
76
-
# A function that takes the current state of the simulation as input and performs some action when the event is triggered.
77
-
# name : str
78
-
# A name for the event, used for identification purposes.
79
-
# parachute : Parachute
80
-
# The parachute associated with this event.
81
-
82
-
# """
83
-
# super().__init__(trigger, action, name)
84
-
# self.parachute = parachute
85
-
86
-
# def apogee_trigger(state):
87
-
# """A trigger function that returns True when the rocket reaches apogee.
88
-
89
-
# Parameters
90
-
# ----------
91
-
# state : dict
92
-
# The current state of the simulation, containing information such as altitude, velocity, and time.
93
-
94
-
# Returns
95
-
# -------
96
-
# bool
97
-
# True if the rocket has reached apogee, False otherwise.
98
194
99
-
# """
100
-
# return state['velocity'] <= 0
195
+
# TODO: add a parameter to the Event class that specify whether the event should
196
+
# be triggered only once, or if it can be triggered multiple times. Also, add a
197
+
# way to stop the event from continuously triggering on command inside the action
198
+
# function, such as a "disable" method that can be called inside the action
199
+
# function to prevent the event from being triggered again.
200
+
201
+
# TODO: add a parameter to the Event class that specify whether the event should
202
+
# be a discrete event, meaning that it should only be checked for triggering at
203
+
# specific time intervals (e.g. every 0.1 seconds) instead of at every time step
204
+
# of the simulation. This would be useful for parachute events. This should be
205
+
# done by adding a "sampling_rate" parameter to the Event class, that is none by
206
+
# default (meaning that the event is checked at every time step), but if it is
207
+
# set to a float value, the event will only be checked for triggering at that
208
+
# specific time interval. The flight class should be able to differentiate
209
+
# between the discrete and continuous events (we will handle this later)
210
+
211
+
212
+
# FOR STANO:
213
+
# TODO: Implement Event orchestration at the Flight/Simulation level:
214
+
# - Flight or an event manager class should maintain a list of active events
215
+
# - At each simulation step, iterate through enabled events and call them with
216
+
# the current simulation state (time, state, state_dot, sensors, etc.)
217
+
# - Collect return values from events and apply state changes, add/remove events,
218
+
# and update event_context values for subsequent calls
219
+
# - Respect the disable_event flag and sampling_rate to control when events
220
+
# are checked for triggering
221
+
# - Handle the sampling_rate logic: only check events at the specified intervals,
0 commit comments