What is a component?
from morse.core.sensor import Sensor
class GPS(Sensor):
    add_data('x', 0.0, 'float', 'X position in the world')
    add_data('y', 0.0, 'float', 'Y position in the world')
    add_data('z', 0.0, 'float', 'Z position in the world')
    def default_action(self):
        x = self.position_3d.x
        y = self.position_3d.y
        z = self.position_3d.z
        # Store the data acquired by this sensor that could be sent
        #  via a middleware.
        self.local_data['x'] = float(x)
        self.local_data['y'] = float(y)
        self.local_data['z'] = float(z)
The GPS sensor implementation.
Important stuff:
    -  Explicit declaration of exported data
    
-  The sensor is 'perfect'
    
-  It only manipulates its local_data (to write values)
 
from morse.core.services import service
from morse.core.actuator import Acutator
class VWActuator(Actuator):
    add_data('x', 0.0, 'float', 'linear velocity towards x (m/s)')
    add_data('w', 0.0, 'float', 'angular velocity (rad/s)')
    @service
    def set_speed(self, v, w):
        self.local_data['v'] = v
        self.local_data['w'] = w
    @service
    def stop(self):
        self.local_data['v'] = 0.0
        self.local_data['w'] = 0.0
    def default_action(self):
        vx, vy, vz = 0.0, 0.0, 0.0
        rx, ry, rz = 0.0, 0.0, 0.0
        # Scale the speeds to the time used by Blender
        vx = self.local_data['v'] / self.frequency
        rz = self.local_data['w'] / self.frequency
        # Give the movement instructions directly to the parent
        parent = self.robot_parent.blender_obj
        parent.applyMovement([vx, vy, vz], True)
        parent.applyRotation([rx, ry, rz], True)
The (V,W) actuator implementation.
Important stuff:
    -  Exported services are regular Python function, simply decorated with @service (or @async_service for asynchronous services)
    
-  This time, we read local_data
    
-  Interaction with the 3D world via the Blender's Python API
    
-  Components may have independant running frequencies
 
    Modifiers
import random
from morse.core.modifier import Modifier
class IMUNoise(Modifier):
    def register_component(self, name, instance, modifier_data):
        instance.output_modifiers.append(noisify)
        self._gyro_std_dev = 0.5
        self._accel_std_dev = 0.5
    def noisify(self, instance):
        for i in range(0, 3):
            instance.local_data['angular_velocity'][i] = \
                random.gauss(instance.local_data['angular_velocity'][i], 
                             self._gyro_std_dev)
            instance.local_data['linear_acceleration'][i] = \
                random.gauss(instance.local_data['linear_acceleration'][i], 
                             self._accel_std_dev)