Skip to content

Commit

Permalink
Add state constraints for Transition
Browse files Browse the repository at this point in the history
  • Loading branch information
taldcroft committed Oct 27, 2024
1 parent f2f6268 commit aad970a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion kadi/commands/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ class Transition(dict):
or a TransitionCallback object.
"""

state_constraints = None

def __init__(self, *args, **kwargs):
if args and isinstance(args[0], str):
date = args[0]
Expand All @@ -120,7 +122,7 @@ def __init__(self, *args, **kwargs):
self.date = date

def __repr__(self):
return f"{self.date}: {super().__repr__()}"
return f"{self.date} {self.state_constraints}: {super().__repr__()}"

def __eq__(self, other):
return self.date == other.date and super().__eq__(other)
Expand Down Expand Up @@ -1361,6 +1363,7 @@ def callback(cls, date, transitions, state, idx):
# normally the case) then back to NPNT at end of maneuver
if state["auto_npnt"] == "ENAB":
transition = Transition(end_manvr_date, pcad_mode="NPNT")
transition.state_constraints = {"pcad_mode": ["NMAN"]}
add_transition(transitions, idx, transition)

@classmethod
Expand Down Expand Up @@ -2195,6 +2198,15 @@ def get_states(
continuity_transitions = []

for idx, transition in enumerate(transitions):
# If there are state constraints then check that the state satisfies the
# constraints. If not then skip this transition. Canonical example is
# ManeuverTransition which requires that the state be in NMAN.
if (tsc := transition.state_constraints) and any(
state_key in state and state[state_key] not in allowed_values
for state_key, allowed_values in tsc.items()
):
continue

date = transition.date

# Some transition classes (e.g. Maneuver) might put in transitions that
Expand All @@ -2221,6 +2233,7 @@ def get_states(
value.callback(date, transitions, state, idx, **value.kwargs)
else:
# Normal case of just updating current state

state[key] = value

# Make into an astropy Table and set up datestart/stop columns
Expand Down

0 comments on commit aad970a

Please sign in to comment.