hbp_nrp_cle.cle.DeterministicClosedLoopEngine module¶
Implementation of the closed loop engine.
-
class
DeterministicClosedLoopEngine
(robot_control_adapter, robot_comm_adapter, brain_control_adapter, brain_comm_adapter, transfer_function_manager, external_module_manager, dt)[source]¶ Bases:
hbp_nrp_cle.cle.CLEInterface.IClosedLoopControl
Implementation of the closed loop engine that runs Transfer functions (TF) sequentially to brain simulation (B) and world simulation (W). Therefore, we are to some degree sure that the TFs work on a reproducible state.
W is run in parallel with B. TF sequentially to those. i.e. seq(par(W,B), TF)
Notes about synchronization: W, B start at cle.clock == 0 and they are asked to simulate one timestep. After their completion, TF is run with t == cle.clock + timestep so to be in sync with B and W, which have already simulated one timestep.
Thus, from the TF point of view, TF_t == B_t == W_t.
e.g. rospy.get_time() (which is in sync with W_t) should be equal to TF_t.
-
DEFAULT_TIMESTEP
= 0.02¶
-
property
initial_robots_poses
¶ Get the robots poses at the beginning of the simulation.
-
initialize
(brain_file=None, configuration=None)[source]¶ Initializes the closed loop engine.
- Parameters
brain_file – A python PyNN script containing the neural network definition
configuration – A set of populations
-
property
is_initialized
¶ Returns True if the simulation is initialized, False otherwise.
-
load_brain
(brain_file, brain_populations=None)[source]¶ Creates a new brain in the running simulation
- Parameters
brain_file – A python PyNN script or an h5 file containing the neural network definition
brain_populations – A (optional) dictionary indexed by population names and containing neuron indices. Neuron indices can be defined by lists of integers or slices. Slices are either python slices or dictionaries containing ‘from’, ‘to’ and ‘step’ values.
-
load_populations
(populations)[source]¶ load new populations into the brain
- Parameters
populations – A dictionary indexed by population names and containing neuron indices. Neuron indices can be defined by lists of integers or slices. Slices are either python slices or dictionaries containing ‘from’, ‘to’ and ‘step’ values.
-
loop
()[source]¶ Starts the orchestrated simulations. This function does not return (starts an infinite loop).
-
property
real_time
¶ Get the total execution time.
-
reset_brain
(brain_file=None, populations=None)[source]¶ Reloads the brain and resets the transfer function. If no parameter is specified, it reloads the initial brain.
- Parameters
brain_file – A python PyNN script containing the neural network definition
populations – A set of populations
-
reset_world
(sdf_world_string='')[source]¶ Reset the world to a given configuration, or to the initial one if none is passed.
- Parameters
sdf_world_string – the new environment to be set in the world simulator (default value is the empty string for compatibility with the ROS message).
-
run_step
(timestep_s)[source]¶ Runs both simulations for the given time step in seconds.
- Parameters
timestep_s – simulation time, in seconds
- Returns
Updated simulation time, otherwise -1
-
property
running
¶ Gets a future indicating whether the simulation is running
-
property
simulation_time
¶ Get the current simulation time.
-
stop
(forced=False, in_loop=False)[source]¶ Stops the orchestrated simulations. Also waits for the current simulation step to end. Must be called on a separate thread from the start one, as an example by a threading.Timer (except when in_loop is set).
- Parameters
forced – If set, the CLE instance cancels pending tasks
in_loop – If set, do not wait for multi-threading signals of pending tasks. It must be set if and only if the function is called by the CLE main loop’s thread.
- Raises
Exception – throws an exception if the CLE was forced to stop but could not be stopped
-