Skip to content

Commit

Permalink
Fix problem with disturbance module if no sensor is present
Browse files Browse the repository at this point in the history
  • Loading branch information
cklb committed Oct 21, 2024
1 parent 4b43643 commit fa430f1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pymoskito/examples/car/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def state_function(self, t, x, args):
"""

x1, x2, x3, x4, x5 = x
v, w = 1, 1
v, w = args[0]

return np.array([v * np.cos(x3),
v * np.sin(x3),
Expand Down
2 changes: 1 addition & 1 deletion pymoskito/examples/tanksystem/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def event_level_2_high(self, t, x):
return x[1] - self.settings["hT"]

def calc_output(self, input_vector):
return [input_vector[0], input_vector[1] + np.random.random(1)[0] / 100]
return input_vector


pm.register_simulation_module(pm.Model, TwoTankSystem)
6 changes: 3 additions & 3 deletions pymoskito/generic_simulation_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,10 +627,10 @@ class GaussianNoise(Disturbance):
("mean", 0)])

def __init__(self, settings):
settings.update([("input signal", "Sensor")])
settings.update([("input signal", "Model_Output")])
Disturbance.__init__(self, settings)

def _disturb(self, value):
def _disturb(self, t, signal):
return np.random.normal(self._settings['mean'],
self._settings['sigma'],
value.output_dim)
signal.shape)
9 changes: 6 additions & 3 deletions pymoskito/simulation_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,18 +593,21 @@ def __init__(self, settings):
SimulationModule.__init__(self, settings)

def calc_output(self, input_dict):
return self._disturb(input_dict[self._settings["input signal"]])
return self._disturb(
input_dict["time"],
input_dict.get(self._settings["input signal"], None))

@abstractmethod
def _disturb(self, value):
def _disturb(self, t, signal):
"""
Placeholder for disturbance calculations.
If the noise is to be dependent on the measured signal use its `value`
to create the noise.
Args:
value (array-like float): Values from the source selected by the
t (float): Current simulation time.
signal (array-like float): Values from the source selected by the
``input_signal`` property.
Returns:
array-like float: Noise that will be mixed with a signal later on.
Expand Down

0 comments on commit fa430f1

Please sign in to comment.