Simulation

Simulation Methods

ConstrainedDynamics.simulate!Method
simulate!(mechanism, storage, args..., kwargs)

Simulate a mechanism for the number of time steps specified by storage (see Storage). The time step has been set in mechanism.

This method can be used to debug potentially faulty (instable) controllers: Even if the simulation fails, the results up to the point of failure are stored in storage and can be analyzed and visualized.

A controller or control function (see Controller) can be passed in with args. If no controller is needed, nothing needs to be passed in.

Available kwargs:

  • record: Specify if the state trajectory should be stored (true) or not (false).
  • ε: Solver tolerance.
source
ConstrainedDynamics.simulate!Method
simulate!(mechanism, tend, args..., kwargs)

Simulate a mechanism for tend seconds. The time step has been set in mechanism.

A controller or control function (see Controller) can be passed in with args. If no controller is needed, nothing needs to be passed in.

Available kwargs:

  • record: Specify if the state trajectory should be stored (true) or not (false).
  • ε: Solver tolerance.
source

Storage

ConstrainedDynamics.StorageType
struct Storage{T, N}

A Storage can be used to store simulation results for a Mechanism.

Indexing example: storage.x[bodyid][timestep_number][2] # returns the y-position of the specified body at the specified time step.

Important attributes

  • x: Contains the position for each body and each time step.
  • q: Contains the orientation for each body and each time step.
  • v: Contains the velocity for each body and each time step.
  • ω: Contains the angluar velocity for each body and each time step.

Constructors

Storage{T}(step_range, nbodies)
Storage(step_range, nbodies)
Storage{T}(nsteps, nbodies)
Storage(nsteps, nbodies)
source

Control Function and Controller

Users can pass a control function to simulate!. This control function must be of the form

control_function(mechanism, timestep)

If such a control function is passed to simulate!, at each time step, control_function(mechanism, timestep) will be called. This way, the user has access to all attributes of the mechanism and the time step.

It is also possible to pass in a controller object:

ConstrainedDynamics.ControllerType
abstract type Controller

Users can create subtypes of Controller to implement controllers. If such a controller object is passed to simulate!, at each time step, controller.control!(mechanism, controller, timestep) will be called. This way, the user has access to all attributes of the mechanism, the controller, and the time step. Note that the control function must be called control!.

source

Visualization

For details, see the ConstrainedDynamicsVis package.

Basic visualization can be performed with:

using ConstrainedDynamicsVis

visualize(mechanism, storage)