import logging; logger = logging.getLogger("morse." + __name__)
import pymoos.MOOSCommClient
from morse.middleware.moos import AbstractMOOS

class BoatActuatorReader(AbstractMOOS):
    def initialize(self):
        AbstractMOOS.initialize(self)

        # register for control variables from the database
        self.m.Register("U1")
        self.m.Register("U2")

    def default(self, ci='unused'):
        current_time = pymoos.MOOSCommClient.MOOSTime()
        # get latest mail from the MOOS comm client
        messages = self.getRecentMail() #self.m.FetchRecentMail()

        # look for command messages: u1 and u2
        for message in messages:
            if (message.GetKey() =="U1") and (message.IsDouble()):
                self.data['u1'] = message.GetDouble() # command linear acceleration
            elif  (message.GetKey()=="U2") and (message.IsDouble()):
                self.data['u2'] = message.GetDouble() # command angular rudder
