Skip to content

Commit

Permalink
Simulating autonomous systems without dummy input for u
Browse files Browse the repository at this point in the history
Fixes #183
  • Loading branch information
Felix-Mac committed Oct 5, 2022
1 parent a2a2447 commit 71bb7dd
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions do_mpc/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def simulate(self):

return x_new

def make_step(self, u0, v0=None, w0=None):
def make_step(self, u0=None, v0=None, w0=None):
"""Main method of the simulator class during control runtime. This method is called at each timestep
and computes the next state or the current control input :py:obj:`u0`. The method returns the resulting measurement,
as defined in :py:class:`do_mpc.model.Model.set_meas`.
Expand All @@ -455,7 +455,7 @@ def make_step(self, u0, v0=None, w0=None):
The method prepares the simulator by setting the current parameters, calls :py:func:`simulator.simulate`
and updates the :py:class:`do_mpc.data` object.
:param u0: Current input to the system.
:param u0: Current input to the system. Optional parameter for autonomous systems.
:type u0: numpy.ndarray
:param v0: Additive measurement noise
Expand All @@ -467,6 +467,11 @@ def make_step(self, u0, v0=None, w0=None):
:return: y_next
:rtype: numpy.ndarray
"""
# Generate dummy input if system is autnomous
if u0 is None:
assert self.model.n_u == 0, 'No input u0 provided. Please provide an input u0.'
u0 = self.model._u(0)

assert self.flags['setup'] == True, 'Simulator is not setup. Call simulator.setup() first.'
assert isinstance(u0, (np.ndarray, casadi.DM, structure3.DMStruct)), 'u0 is wrong input type. You have: {}'.format(type(u0))
assert u0.shape == self.model._u.shape, 'u0 has incorrect shape. You have: {}, expected: {}'.format(u0.shape, self.model._u.shape)
Expand Down

0 comments on commit 71bb7dd

Please sign in to comment.