sequential_pattern¶
Module Contents¶
Classes¶
Plays through a sequence of steps described in the script json |
Functions¶
|
Set names, collect params, and give service to server |
- class sequential_pattern.SequentialPattern(name, script)¶
Bases:
harmoni_common_lib.service_manager.HarmoniServiceManagerPlays through a sequence of steps described in the script json
Script is made of a sequence of ‘set’ objects. Each set has a sequence of steps. The steps provide directions for an action request to a node. Steps can consist of a list of steps which will be executed in parallel.
- Set types include:
‘setup’ which plays once at the start ‘sequence’ which plays through once ‘loop’ which continues indefinitely
- Actions specify the service id (e.g. tts_default), and the following:
‘action_goal’ the type of command to give to the service (e.g. DO, START, STOP, etc.) ‘resource_type’ the type of server expected to provide the service ‘wait_for’ the condition to wait for ‘trigger’ the additional message to send to the service
Results from services are stored in a single dictionary with the service name as the key and the results in a list. Each result is tagged with the time received and data recieved.
Detections are gathered with individual callbacks to each detector’s topic and stored with the results.
- _setup_clients(self)¶
Set up clients to all services that have been scripted
Also checks that the service matches what has been specified in the decision configuration file.
- _get_services(self, script)¶
Extract all the services used in a given script.
- Parameters
script (list of dicts) – list of sets of actions that
- Returns
names of all the services
- Return type
list
- _result_callback(self, result)¶
Recieve and store result with timestamp
- _feedback_callback(self, feedback)¶
Feedback is currently just logged
- _detecting_callback(self, data, service_name)¶
Store data from detection to client_results dictionary
- start(self)¶
Iterate through steps of the script until reaching the end.
- stop(self)¶
Stop the Pattern Player
- pause(self)¶
Pause the Behavior Pattern
- setup_services(self, setup_steps)¶
Setup sensor and detector services
Sensors and detectors are directed to turn ‘ON’ and a callback is created for detectors.
- Parameters
setup_steps (list of dicts) – call to each sensor/detector to set up.
- do_steps(self, sequence, looping=False)¶
Directs the services to do each of the steps scripted in the sequence
- Parameters
sequence (list of dicts) – Each dict specifies a call to a service
looping (bool, optional) – If true will loop the sequence indefinitely. Defaults to False.
- handle_step(self, step, optional_data=None)¶
Handle cases for different types of steps
- Handles:
parallel execution of list steps erronious calls to sensors pulling latest data from detectors making requests of actuators or other services
- Parameters
step ([type]) – [description]
optional_data ([type], optional) – [description]. Defaults to None.
- Returns
[description]
- Return type
[type]
- make_service_request(self, service, details, optional_data)¶
Sends a goal to a service
- Parameters
service (str) – Name of the service
details (dict) – goal details
optional_data (str) – can be either the prior result or the trigger from the script
- Returns
the result of the request
- Return type
str
- make_detector_request(self, service, details)¶
Get detection result from detector service
- Parameters
service (str) – Name of the detector service
details (dict) – dictionary of request details. ‘wait_for’ is the only relevant item
- Returns
the string version of the last detection
- Return type
str
- get_new_result(self, service)¶
Waits for a new result for the service to be set
- Parameters
service (str) – Name of the service
- Returns
Result data
- Return type
str
- sequential_pattern.main()¶
Set names, collect params, and give service to server