import logging; logger = logging.getLogger("morse." + __name__)

import morse.core.sensor

from morse.core import blenderapi
from morse.core.services import service, async_service
from morse.core import status
from morse.helpers.components import add_data, add_property

import random

class Dvl(morse.core.sensor.Sensor):
    _name = "Dvl"
    _short_desc = "Measure the velocity of an object"

    # define here the data fields exported by your sensor
    # format is: field name, default initial value, type, description
    add_data('velocity', [], 'Vector', 'Velocity')

    def __init__(self, obj, parent=None):
        logger.info("%s initialization" % obj.name)
        # Call the constructor of the parent class
        morse.core.sensor.Sensor.__init__(self, obj, parent)
        logger.info('Component initialized')

    def default_action(self):
        #parent = self.robot_parent.bge_object
        vx=self.robot_parent._v+1/10000*(random.random()-1/2)
        vy=0#+1/10*random.random()-1/20
        vz=0#+1/10*random.random()-1/20

        self.local_data['velocity'] = [vx, vy, vz]
