from dronekit import Vehicle class ScaledIMU2(object): def __init__(self, time_boot_us=None, xacc=None, yacc=None, zacc=None, xygro=None, ygyro=None, zgyro=None, xmag=None, ymag=None, zmag=None): self.time_boot_us = time_boot_us self.xacc = xacc self.yacc = yacc self.zacc = zacc self.xgyro = zgyro self.ygyro = ygyro self.zgyro = zgyro self.xmag = xmag self.ymag = ymag self.zmag = zmag def __str__(self): return "Scaled_IMU2: time_boot_us={},xacc={},yacc={},zacc={},xgyro={},ygyro={},zgyro={},xmag={},ymag={},zmag={}".format(self.time_boot_us, self.xacc, self.yacc,self.zacc,self.xgyro,self.ygyro,self.zgyro,self.xmag,self.ymag,self.zmag) class MyVehicle(Vehicle): def __init__(self, *args): super(MyVehicle, self).__init__(*args) # Create an Vehicle.scaled_imu2 object with initial values set to None. self._scaled_imu2 = ScaledIMU2() # Create a message listener using the decorator. @self.on_message('Scaled_IMU2') def listener(self, name, message): self._scaled_imu2.time_boot_us=message.time_usec self._scaled_imu2.xacc=message.xacc self._scaled_imu2.yacc=message.yacc self._scaled_imu2.zacc=message.zacc self._scaled_imu2.xgyro=message.xgyro self._scaled_imu2.ygyro=message.ygyro self._scaled_imu2.zgyro=message.zgyro self._scaled_imu2.xmag=message.xmag self._scaled_imu2.ymag=message.ymag self._scaled_imu2.zmag=message.zmag self.notify_attribute_listeners('scaled_imu2', self._scaled_imu2) @property def scaled_imu2(self): return self._scaled_imu2