diff --git a/CHANGELOG.md b/CHANGELOG.md index 311189757..9bcb06322 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,7 +40,7 @@ straightforward as possible. ### Fixed -- +- ENH: Parachute trigger doesn't work if "Apogee" is used instead of "apogee" [#489](https://github.com/RocketPy-Team/RocketPy/pull/489) ## [v1.1.2] - 2023-11-25 diff --git a/rocketpy/rocket/parachute.py b/rocketpy/rocket/parachute.py index 07c44e158..3abd66ac2 100644 --- a/rocketpy/rocket/parachute.py +++ b/rocketpy/rocket/parachute.py @@ -38,7 +38,7 @@ class Parachute: case, the parachute will be ejected when the rocket reaches this height above ground level. - - The string "apogee," which triggers the parachute at apogee, i.e., + - The string "apogee" which triggers the parachute at apogee, i.e., when the rocket reaches its highest point and starts descending. Note: The function will be called according to the sampling rate @@ -126,7 +126,7 @@ def __init__( case, the parachute will be ejected when the rocket reaches this height above ground level. - - The string "apogee," which triggers the parachute at apogee, i.e., + - The string "apogee" which triggers the parachute at apogee, i.e., when the rocket reaches its highest point and starts descending. Note: The function will be called according to the sampling rate @@ -171,11 +171,17 @@ def __init__( self.prints = _ParachutePrints(self) - # evaluate the trigger + self.__evaluate_trigger_function(trigger) + + def __evaluate_trigger_function(self, trigger): + """This is used to set the triggerfunc attribute that will be used to + interact with the Flight class. + """ if callable(trigger): self.triggerfunc = trigger + elif isinstance(trigger, (int, float)): - # trigger is interpreted as the absolute height at which the parachute will be ejected + # The parachute is deployed at a given height def triggerfunc(p, h, y): # p = pressure considering parachute noise signal # h = height above ground level considering parachute noise signal @@ -184,8 +190,8 @@ def triggerfunc(p, h, y): self.triggerfunc = triggerfunc - elif trigger == "apogee": - # trigger for apogee + elif trigger.lower() == "apogee": + # The parachute is deployed at apogee def triggerfunc(p, h, y): # p = pressure considering parachute noise signal # h = height above ground level considering parachute noise signal @@ -194,7 +200,12 @@ def triggerfunc(p, h, y): self.triggerfunc = triggerfunc - return None + else: + raise ValueError( + f"Unable to set the trigger function for parachute '{self.name}'. " + + "Trigger must be a callable, a float value or the string 'apogee'. " + + "See the Parachute class documentation for more information." + ) def __str__(self): """Returns a string representation of the Parachute class. diff --git a/rocketpy/rocket/rocket.py b/rocketpy/rocket/rocket.py index 947c82acd..62f61d99b 100644 --- a/rocketpy/rocket/rocket.py +++ b/rocketpy/rocket/rocket.py @@ -1092,7 +1092,7 @@ def add_parachute( case, the parachute will be ejected when the rocket reaches this height above ground level. - - The string "apogee," which triggers the parachute at apogee, i.e., + - The string "apogee" which triggers the parachute at apogee, i.e., when the rocket reaches its highest point and starts descending. Note: The function will be called according to the sampling rate