Enki simulations

Genaration of simulations

class generate_simulation_data.GenerateSimulationData
classmethod check_dataset_conformity(runs_dir, runs_img, title, dataset, net_input, communication)

Generate a scatter plot to check the conformity of the dataset. The plot will show the distribution of the input sensing, in particular, as the difference between the front sensor and the mean of the rear sensors, with respect to the output control of the datasets.

Parameters
  • runs_dir – directory containing the simulation

  • runs_img – directory containing the simulation images

  • title – title of the plot

  • dataset – name of the dataset

  • net_input – input of the net between prox_values, prox_comm or all_sensors

  • communication – states if the communication is used by the network

classmethod generate_dict(myt, n_sim, s, comm=None)

Save all the information of the agent in a dictionary.

Parameters
  • myt – agent

  • n_sim – index of the simulation

  • s – index of the timestep

  • comm – boolean, True if the dataset is generated using the learned model with communication

Return dictionary
  • ‘run’: n_sim,

  • ‘timestep’: s,

  • ‘name’: myt.name,

  • ‘index’: myt.index,

  • ‘myt_quantity’: myt.controller.N,

  • ‘net_input’: myt.controller.net_input,

  • ‘prox_values’: prox_values,

  • ‘prox_comm’: utils.parse_prox_comm(prox_comm),

  • ‘all_sensors’: all_sensors,

  • ‘initial_position’: myt.initial_position,

  • ‘position’: myt.position,

  • ‘angle’: myt.angle,

  • ‘goal_position’: myt.goal_position,

  • ‘goal_angle’: myt.goal_angle,

  • ‘motor_left_target’: myt.motor_left_target,

  • ‘motor_right_target’: myt.motor_right_target,

  • ‘goal_position_distance’: myt.goal_position[0] - myt.position[0],

  • ‘goal_position_distance_absolute’: abs(myt.goal_position[0] - myt.position[0])

  • ‘transmitted_comm’: communication transmitted two the neighbours

  • ‘colour’: colour of the top led

classmethod generate_simulation(run_dir, n_simulations, controller, myt_quantity, args, model_dir=None, model=None, communication=False)
Parameters
  • run_dir – directory containing the simulation runs

  • n_simulations – number of simulations to generate

  • controller – controller to be used in the simulations

  • model_dir – directory containing the model

  • myt_quantity – number of agents

  • args – arguments from command line

  • model – model to be used

  • communication – states if the communication is used by the network

classmethod get_controller(controller, controllers, goal, myt_quantity, net_input, communication=None, model=None, model_dir=None)

Important

This method has not yet been implemented for task 2.

Parameters
  • controller – name of the controller (between omniscient, manual and learned)

  • controllers – reference to the controller class

  • goal – task to perform (between colour ot distribute)

  • myt_quantity – number of agents

  • net_input – input of the net between prox_values, prox_comm or all_sensors

  • communication – states if the communication is used by the network

  • model – network to be used by the controller

  • model_dir – directory containing the model

Return controller_factory

lambda function containing the controller to be used

classmethod init_positions(myts, net_input, avg_gap, variate_pose=False, min_distance=10.9, extension=False, x=None, epsilon=None)

Given the agents, position them such as all x-axes are aligned. Arrange the robots in a “single file” (all x-axes aligned) and within the proximity sensor range (when running the extension of task 1 it is not mandatory that the robot are within the proximity sensor range, since a random average gap is used).

The distance between the first and the last robot is usually computed as follow:

\[(min\_distance + avg\_gap) * (myt\_quantity - 1)\]

In case of the extended task this quantity it is not initialised.

Usually, the distances among the robots are computed by drawing (myt_quantity - 1) real random gaps in using a normal distribution with mean equal to the average gap and stdev fixed to 8. This values are clipped between 1 and the maximum_gap. Then, the minimum_distance is added to all the distances, in order to move from the ICR to the front of the thymio. The distances obtained are rescaled in such a way their sum corresponds to the total gap that is known. In case of the extended task the distances are obtained using the random average gap fixed and generating random positions in the maximum range allowed.

Parameters
  • myts – list containing all the agents and associated attributes

  • net_input – input of the net between prox_values, prox_comm or all_sensors

  • avg_gap – for the prox_values the default value is 8cm; for the prox_comm the default value is 25cm. Can be also a random value, between 5 and 35, in case of the extended task.

  • variate_pose – False by default, True only during the evaluation of the models when only one agent is used.

  • min_distance – the minimum distance between two Thymio [wheel - wheel] is 10.9 cm, that corresponds to the length of the agents.

  • extension – True if is running task1_extension

  • x – quantity of which variate the position along the x axis of the robot (only during the model evaluation with variate_pose True)

classmethod run(n_sim, myts, runs, complete_runs, world: pyenki.pyenki.World, comm=None, gui: bool = False, T: float = 4, dt: float = 0.1, tol: float = 0.1) → None

Run the simulation as fast as possible or using the real time GUI. Generate two different type of simulation data, one with all the thymios and the other without including the 2 thymios at the ends, but only the ones that have to move. If all the robots have reached their target, stop the simulation.

Parameters
  • n_sim – index of the simulation

  • myts – list containing the agents

  • runs – list containing all the data of the robots (except about the two robots at the beginning and at the end of the row) in the simulations

  • complete_runs – list containing all the data of the robots in the simulations

  • world – enki world

  • comm – variable that states if the communication is used

  • gui – variable that states if use the gui

  • T – duration of the simulation in seconds

  • dt – control step duration – update timestep in seconds, should be below 1 (typically .02-.1)

  • tol – tolerance used to verify if the robot reaches the target

classmethod save_simulation(complete_data, data, runs_dir)
Parameters
  • complete_data – list containing all the data of the robots in the simulations

  • data – list containing all the data of the robots (except about the two robots at the beginning and at the end of the row) in the simulations

  • runs_dir – directory where to save the simulation runs

classmethod setup(controller_factory, myt_quantity, aseba: bool = False)

Set up the world as an unbounded world.

Parameters
  • controller_factory – if the controller is passed, load the learned network

  • myt_quantity – number of robot in the simulation

  • aseba – True

Return world, myts

world and the agents in the world

classmethod update_dict(myt, s, comm=None)

Updated data in the dictionary instead of rewrite every field to optimise performances.

Parameters
  • myt – agent

  • s – timestep

  • comm – boolean, True if the dataset is generated using the learned model with communication

Return updated dictionary

updated dictionary

classmethod verify_target(myt, counter, dictionary, tol)

Verify if the robot has reached the target goal.

It is always ensured that enough timesteps are performed, especially for the omniscient controller.

Parameters
  • myt – agent

  • counter – counter incremented when the robot has reached the goal

  • dictionary – dictionary containing the agent information

  • tol – tolerance