morse.middleware package

Subpackages

Submodules

morse.middleware.abstract_datastream module

class AbstractDatastream(component_instance, kwargs)[source]

Bases: object

The class is inherited by all serializers/deserializers. Concrete classes need to implement default().

property component_name
property data
abstract default(ci='unused')[source]

default method called by MORSE logic

Sensor: must read local_data, format and publish them. Actuator: must read a new incoming command and update local_data.

finalize()[source]

finalize the specific datastream

Can be overriden if needed

initialize()[source]

initialize the specific datastream

Can be overriden if needed

morse.middleware.hla_datastream module

class HLABaseNode(klass, fom, node_name, federation, sync_point, sync_register, time_sync, timestep, lookahead)[source]

Bases: object

finalize()[source]

Close all open HLA connections.

init_time()[source]
class HLADatastreamManager(args, kwargs)[source]

Bases: DatastreamManager

External communication using sockets.

action()[source]

Main action, called each simulation round

finalize()[source]

Destructor method.

register_component(component_name, component_instance, mw_data)[source]

Open the port used to communicate by the specified component.

class MorseBaseAmbassador(rtia, federation, time_sync, timestep, lookahead)[source]

Bases: FederateAmbassador

advance_time()[source]
announceSynchronizationPoint(label, tag)[source]
attributeOwnershipAcquisitionNotification(obj, attr)[source]
attribute_handle(name, obj_handle)[source]
delete_object(name)[source]
discoverObjectInstance(obj, objectclass, name)[source]
federationSynchronized(label)[source]
get_attributes(obj_name)[source]
get_object(name)[source]
initialize_time_regulation()[source]
object_handle(name)[source]
publish_attributes(name, obj_handle, attr_handles)[source]
reflectAttributeValues(obj, attributes, tag, order, transport, time=None, retraction=None)[source]
register_object(handle, name)[source]
register_sync_point(label)[source]
suscribe_attributes(name, obj_handle, attr_handles)[source]
timeAdvanceGrant(time)[source]
timeConstrainedEnabled(time)[source]
timeRegulationEnabled(time)[source]
unsuscribe_attributes(obj_handle)[source]
update_attribute(obj_handle, value)[source]
wait_until_sync(label)[source]

morse.middleware.moos_datastream module

class MOOSDatastreamManager(args, kwargs)[source]

Bases: DatastreamManager

Handle communication between Blender and MOOS.

morse.middleware.pocolibs_datastream module

class DummyPoster(name)[source]

Bases: object

exception InvalidRead(value)[source]

Bases: Exception

class PocolibsDataStreamInput(component_instance, kwargs)[source]

Bases: AbstractDatastream

finalize()[source]

finalize the specific datastream

Can be overriden if needed

initialize(kind)[source]

initialize the specific datastream

Can be overriden if needed

read()[source]
class PocolibsDataStreamOutput(component_instance, kwargs)[source]

Bases: AbstractDatastream

finalize()[source]

finalize the specific datastream

Can be overriden if needed

initialize(kind)[source]

initialize the specific datastream

Can be overriden if needed

write(obj)[source]
class PocolibsDatastreamManager(args, kwargs)[source]

Bases: DatastreamManager

Handle communication between Blender and Pocolibs.

compute_date()[source]

Compute the current time

( we only require that the date increases using a constant step so real time is ok)

exception PosterNotFound(value)[source]

Bases: Exception

poster_name(component_name, mw_data)[source]

morse.middleware.pocolibs_request_manager module

class PocolibsRequestManager[source]

Bases: RequestManager

Implements Pocolibs requests to control the MORSE simulator.

This is done by re-implementing (parts of) the TCLserv protocol.

HOST = ''
PORT = 9473
finalization()[source]

Terminate the ports used to accept requests

initialization()[source]

This method is meant to be overloaded by middlewares to perform specific initializations.

Must return True is the initialization is successful, False in other cases.

main()[source]

This is the main method of the RequestManagerClass: it reads external incoming requests, dispatch them through the on_incoming_request() method, and write back answers.

Subclasses are expected to overload this method.

on_service_completion(intern_rqst_id, result)[source]

This method is called when a asynchronous request completes.

Subclasses are expected to overload this method with code to notify the original request emitter.

Parameters
  • request_id (uuid) – the request id, as return by on_incoming_request() when processing an asynchronous request

  • result – the service execution result.

post_registration(component, service, is_async)[source]

This method is meant to be overloaded by middlewares that have specific initializations to do when a new service is exposed.

Parameters
  • component_name (string) – name of the component that declare this service

  • service_name (string) – Name of the service (if not overloaded in the @service decorator, should be the Python function name that implement the service)

  • is_async (boolean) – If true, means that the service is asynchronous.

Returns

True if the registration succeeded.

Return type

boolean

morse.middleware.ros_datastream module

The ROS ‘datastream manager’ is responsible for ROS topic management in MORSE. It publishes simulated sensors and subscribes to topics controlling simulated actuators.

As you may have noticed, the morse.middleware.ros_datastream.ROSDatastreamManager class is actually empty: contrary to sockets, for instance, that always use direct JSON serialization of MORSE Python objects, there is no generic way to encode/decode ROS messages.

Thus, morse/middleware/ros contains one specific serialization/deserialization class for each sensor/actuator. These classes inherit either from morse.middleware.ros.abstract_ros.ROSPublisher or from:py:class:morse.middleware.ros.abstract_ros.ROSSubscriber.

If you want to add support for a new type of topic, you likely want to add it as a new serialization implementation in this directory.

Note also that management of ROS services and ROS actions takes place in ros_request_manager.py.

class ROSDatastreamManager(args, kwargs)[source]

Bases: DatastreamManager

Handle communication between Blender and ROS.

morse.middleware.ros_request_manager module

morse.middleware.socket_datastream module

class MorseEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]

Bases: JSONEncoder

default(obj)[source]

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
class SocketDatastreamManager(args, kwargs)[source]

Bases: DatastreamManager

External communication using sockets.

action()[source]

Main action, called each simulation round

get_all_stream_ports()[source]

Get stream ports for all streams.

get_stream_port(name)[source]

Get stream port for stream name.

list_streams()[source]

List all publish streams.

register_component(component_name, component_instance, mw_data)[source]

Open the port used to communicate by the specified component.

class SocketPublisher(component_instance, kwargs)[source]

Bases: SocketServ

default(ci='unused')[source]

default method called by MORSE logic

Sensor: must read local_data, format and publish them. Actuator: must read a new incoming command and update local_data.

encode()[source]
class SocketReader(component_instance, kwargs)[source]

Bases: SocketServ

decode(msg)[source]
default(ci='unused')[source]

default method called by MORSE logic

Sensor: must read local_data, format and publish them. Actuator: must read a new incoming command and update local_data.

class SocketServ(component_instance, kwargs)[source]

Bases: AbstractDatastream

close_socket(sock)[source]
finalize()[source]

Terminate the ports used to accept requests

initialize()[source]

initialize the specific datastream

Can be overriden if needed

morse.middleware.socket_request_manager module

class SocketRequestManager[source]

Bases: RequestManager

Implements services to control the MORSE simulator over raw ASCII sockets.

The syntax of requests is:

>>> id component_name service [params with Python syntax]

id is an identifier set by the client to conveniently identify the request. It must be less that 80 chars in [a-zA-Z0-9].

The server answers:

>>> id status result_in_python|error_msg

status is one of the constants defined in morse.core.status.

finalization()[source]

Terminate the ports used to accept requests

initialization()[source]

This method is meant to be overloaded by middlewares to perform specific initializations.

Must return True is the initialization is successful, False in other cases.

main()[source]

This is the main method of the RequestManagerClass: it reads external incoming requests, dispatch them through the on_incoming_request() method, and write back answers.

Subclasses are expected to overload this method.

on_service_completion(request_id, results)[source]

This method is called when a asynchronous request completes.

Subclasses are expected to overload this method with code to notify the original request emitter.

Parameters
  • request_id (uuid) – the request id, as return by on_incoming_request() when processing an asynchronous request

  • result – the service execution result.

post_registration(component, service, is_async)[source]

This method is meant to be overloaded by middlewares that have specific initializations to do when a new service is exposed.

Parameters
  • component_name (string) – name of the component that declare this service

  • service_name (string) – Name of the service (if not overloaded in the @service decorator, should be the Python function name that implement the service)

  • is_async (boolean) – If true, means that the service is asynchronous.

Returns

True if the registration succeeded.

Return type

boolean

morse.middleware.text_datastream module

class BasePublisher(component_instance, kwargs)[source]

Bases: AbstractDatastream

default(ci)[source]

default method called by MORSE logic

Sensor: must read local_data, format and publish them. Actuator: must read a new incoming command and update local_data.

encode_data()[source]
finalize()[source]

finalize the specific datastream

Can be overriden if needed

header()[source]
initialize()[source]

initialize the specific datastream

Can be overriden if needed

class CSVPublisher(component_instance, kwargs)[source]

Bases: BasePublisher

encode_data()[source]
header()[source]
class Publisher(component_instance, kwargs)[source]

Bases: BasePublisher

encode_data()[source]
header()[source]
class TextDatastreamManager(args, kwargs)[source]

Bases: DatastreamManager

Produce text files as output for the components

morse.middleware.yarp_datastream module

class YarpDatastreamManager(args, kwargs)[source]

Bases: DatastreamManager

Handle communication between Blender and YARP.

finalize()[source]

Close all currently opened ports and release the network.

class YarpPort(component_instance, kwargs)[source]

Bases: AbstractDatastream

connect2topic(topic)[source]

Connect a yarp port to a specific yarp topic.

finalize()[source]

finalize the specific datastream

Can be overriden if needed

initialize(port_creator_fn, is_input)[source]

initialize the specific datastream

Can be overriden if needed

class YarpPublisher(component_instance, kwargs)[source]

Bases: YarpPort

default(ci)[source]

default method called by MORSE logic

Sensor: must read local_data, format and publish them. Actuator: must read a new incoming command and update local_data.

encode(bottle)[source]
encode_message(bottle, data, component_name)[source]

Prepare the content of the bottle

This function can be recursively called in case of list processing

initialize()[source]

initialize the specific datastream

Can be overriden if needed

class YarpReader(component_instance, kwargs)[source]

Bases: YarpPort

default(ci)[source]

default method called by MORSE logic

Sensor: must read local_data, format and publish them. Actuator: must read a new incoming command and update local_data.

initialize()[source]

initialize the specific datastream

Can be overriden if needed

morse.middleware.yarp_json_request_manager module

class YarpRequestManager[source]

Bases: RequestManager

Implements services to control the MORSE simulator over YARP

The syntax of requests is: >>> id component_name service [params with Python syntax]

‘id’ is an identifier set by the client to conveniently identify the request. It must be less that 80 chars in [a-zA-Z0-9].

The server answers: >>> id OK|FAIL result_in_python|error_msg

finalization()[source]

This method is meant to be overloaded by middlewares to perform specific finalizations.

Must return True is the finalization is successful, False in other cases.

initialization()[source]

This method is meant to be overloaded by middlewares to perform specific initializations.

Must return True is the initialization is successful, False in other cases.

main()[source]

Read commands from the ports, and prepare the response

on_service_completion(request_id, results)[source]

This method is called when a asynchronous request completes.

Subclasses are expected to overload this method with code to notify the original request emitter.

Parameters
  • request_id (uuid) – the request id, as return by on_incoming_request() when processing an asynchronous request

  • result – the service execution result.

post_registration(component_name, service, is_async)[source]

Register a connection of a service with YARP

morse.middleware.yarp_request_manager module

class YarpRequestManager[source]

Bases: RequestManager

Implements services to control the MORSE simulator over YARP

The syntax of requests is: >>> id component_name service [params with Python syntax]

‘id’ is an identifier set by the client to conveniently identify the request. It must be less that 80 chars in [a-zA-Z0-9].

The server answers: >>> id OK|FAIL result_in_python|error_msg

finalization()[source]

This method is meant to be overloaded by middlewares to perform specific finalizations.

Must return True is the finalization is successful, False in other cases.

initialization()[source]

This method is meant to be overloaded by middlewares to perform specific initializations.

Must return True is the initialization is successful, False in other cases.

main()[source]

Read commands from the ports, and prepare the response

on_service_completion(request_id, results)[source]

This method is called when a asynchronous request completes.

Subclasses are expected to overload this method with code to notify the original request emitter.

Parameters
  • request_id (uuid) – the request id, as return by on_incoming_request() when processing an asynchronous request

  • result – the service execution result.

post_registration(component_name, service, is_async)[source]

Register a connection of a service with YARP

Module contents