# hbp_nrp_backend.cle_interface.ROSCLEClient module¶

Takes care of making the appropriate ROS call(s) to control a simulation. On the other side of ROS, the calls are handled by ROSCLEServer.py

class ROSCLEClient(sim_id)[source]

Bases: object

Client around the ROS controlled Closed Loop Engine.

ReplaceBehaviorEnum

alias of hbp_nrp_commons.Enum

activate_simulation_transfer_function(transfer_function_name, activate_transfer_function)[source]

Set the activation status of a transfer function

Parameters
• transfer_function_name – the name of the tf to be set

• activate_transfer_function – the desired new activation status

Returns

add_simulation_robot(**kwargs)[source]

The function actually executed instead of the decorated one.

add_simulation_transfer_function(transfer_function_source)[source]

Add a new simulation transfer function source code.

Parameters

transfer_function_source – Source code of the transfer function

Returns

“” if the call to ROS is successful, a string containing an error message otherwise

command_simulation_recorder(command)[source]

Issue a request/command to the simulation recorder

Parameters

command – the command to issue, see SimulationRecorder.srv definition for types

Returns

boolean value/success and message if provided

convert_transfer_function_raw_to_structured(transfer_function)[source]

Convert raw tf to structured tf

Parameters

transfer_function – the transfer function in raw format

Returns

a strucuted TF

delete_simulation_robot(**kwargs)[source]

The function actually executed instead of the decorated one.

delete_simulation_transfer_function(**kwargs)[source]

The function actually executed instead of the decorated one.

download_file_in_simdir(**kwargs)[source]

The function actually executed instead of the decorated one.

edit_simulation_transfer_function(transfer_function_name, transfer_function_source)[source]

Edit the simulation transfer function’s source code.

Parameters
• transfer_function_name – Name of the transfer function to modify

• transfer_function_source – Source code of the transfer function

Returns

“” if the call to ROS is successful, a string containing an error message otherwise

extend_simulation_timeout(timeout)[source]

Extend the simulation timeout

Parameters

timeout – new new simulation timeout

Returns

“” if the call to ROS is successful

get_populations()[source]

Gets the neurons of the brain in the simulation

Returns

populations as dict

get_simulation_CSV_recorders_files(**kwargs)[source]

The function actually executed instead of the decorated one.

get_simulation_brain()[source]

Get the brain of the running simulation

Returns

dict with brain_data, brain_type, brain_populations and data_type

get_simulation_robots(**kwargs)[source]

The function actually executed instead of the decorated one.

get_simulation_transfer_functions(**kwargs)[source]

The function actually executed instead of the decorated one.

reset(reset_type, world_sdf=None, brain_path=None, populations=None)[source]

Reset the simulation.

Parameters
• reset_type – Denotes the kind of reset the user wants to perform, details about

• world_sdf – The world sdf

• brain_path – The brain path for the reset

• populations – To populations for the reset

reset types and details are given in the ResetSimulation service request message.

set_simulation_brain(brain_type='py', data=None, data_type='text', brain_populations=None)[source]

Set the brain of the running simulation (will pause the simulation)

Parameters
• brain_type – Type of the brain file (‘h5’ or ‘py’)

• data – Contents of the brain file. Encoding given in field data_type

• data_type – Type of the data field (‘text’ or ‘base64’)

Returns

response of the cle

set_simulation_populations(brain_type, brain_populations, data_type='text', change_population=1)[source]

Set the populations of the running simulation

Parameters
• brain_type – Type of the brain file (‘h5’ or ‘py’)

• brain_populations – Contents of the brain file. Encoding given in field data_type

• data_type – Type of the data field (‘text’ or ‘base64’)

• change_population – a flag to select an action on population name change, currently possible values are: 0 = ReplaceBehaviorEnum.ASK_USER ask permission to replace 1 = ReplaceBehaviorEnum.REPLACE replace old name with a new one 2 = ReplaceBehaviorEnum.NO_REPLACE proceed with no replace action

Returns

response of the cle

set_simulation_robot_initial_pose(**kwargs)[source]

The function actually executed instead of the decorated one.

stop_communication(reason)[source]

Tells the client to stop all communication to the simulation server because of the given reason

Parameters

reason – The reason why no more communication should be performed

exception ROSCLEClientException(*args)[source]

Bases: Exception

Exception within the CLE client

class ROSCLEServiceWrapper(service_name, service_class, ros_cle_client, invalidate_on_failure=True)[source]

Bases: object

Wraps the behaviour of a standard ROS service, throwing a detailed ROSCLEClientException in case of invalid client or ROS exceptions.

ROS_SERVICE_TIMEOUT = 180
property handler

Property getter for the __handler attribute

property invalidate_on_failure

Property getter for the __invalidate_on_failure attribute

property ros_cle_client

Property getter for the __ros_cle_client attribute

fallback_retval(val)[source]

This function is intended to be used as a decorator for the methods calling CLE services. It intercepts a ROSCLEClientException during the execution of a ROSServiceWrapper and returns the desired value instead.

Parameters

val – the fallback return value for the decorated method