Event Callbacks¶
Event callbacks allow you to respond to detected events during propagation. Callbacks can log information, inspect state, modify the spacecraft state (for impulsive maneuvers), or control propagation flow.
Callback Function Signature¶
To define a callback, create a function matching the following signature:
EventAction Options¶
The callback return value includes an EventAction that controls propagation behavior:
| Action | Behavior |
|---|---|
CONTINUE | Continue propagation after processing the event |
STOP | Halt propagation immediately after the event |
When to Use STOP¶
Use EventAction.STOP when:
- A terminal condition has been reached (e.g., re-entry)
- The propagation goal has been achieved
- An error condition is detected
- You want to examine state at a specific event before deciding to continue
When to Use CONTINUE¶
Use EventAction.CONTINUE for:
- Logging and monitoring events
- Impulsive maneuvers (state changes but propagation continues)
- Intermediate waypoints
- Data collection triggers
Defining Callbacks¶
Callbacks receive the event epoch and state, and return a tuple containing the (possibly modified) state and an action directive.
Logging Callback¶
A simple callback that logs event information without modifying state:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
Attaching Callbacks to Events¶
Use the with_callback() method to attach a callback to any event detector:
The with_callback() method returns a new event detector with the callback attached, allowing method chaining.
State Modification¶
Callbacks can modify the spacecraft state by returning a new state vector. This is the mechanism for implementing impulsive maneuvers.
Modifying State¶
Physical Consistency¶
When modifying state, ensure physical consistency:
- Position changes are unusual except for specific scenarios
- Velocity changes should respect momentum conservation for realistic maneuvers
- Large changes may cause numerical issues in subsequent integration steps
For complete impulsive maneuver examples, see Maneuvers.
Multiple Callbacks¶
Each event detector can have one callback. For multiple actions at the same event, either:
- Perform all actions within a single callback
- Create multiple event detectors at the same time/condition
Callback Execution Order¶
When multiple events occur at the same epoch:
- Events are processed in the order their detectors were added
- State modifications from earlier callbacks are passed to later callbacks
- If any callback returns
STOP, propagation halts after all callbacks execute
See Also¶
- Event Detection - Event detection fundamentals
- Premade Events - Built-in event types
- Maneuvers - Using callbacks for orbit maneuvers