Go to the documentation of this file.00001 import struct
00002 from BAL.protocol.packages.header import TakeoverHeader
00003
00004 MOTOR_TO_TAKEOVER = 3
00005 MOTOR_TO_TAKEOVER_SIZE = 17
00006
00007 REVERSE = -1
00008 NORMAL = 1
00009
00010
00011 class MotorToTakeover(TakeoverHeader):
00012 def __init__(self, ch=None, max_command=None, pin=None, tab=None, min_joy=None, mid_joy=None ,max_joy=None, to_clib=None, deadband=None, rev=None):
00013 super(MotorToTakeover, self).__init__(MOTOR_TO_TAKEOVER)
00014 self._ch = ch
00015 self._max_command = max_command
00016 self._pin = pin
00017 self._tab = tab
00018 self._min_joy = min_joy
00019 self._max_joy = max_joy
00020 self._mid_joy = mid_joy
00021 self._to_clib = to_clib
00022 self._deadband = deadband
00023
00024 self._rev = rev
00025 if ch is not None:
00026 self.set_checksum(self.cal_checksum())
00027
00028 def get_channel(self):
00029 return self._ch
00030
00031 def get_max_command(self):
00032 return self._max_command
00033
00034 def get_pin(self):
00035 return self._pin
00036
00037 def get_tab(self):
00038 return self._tab
00039
00040 def get_min_joystick(self):
00041 return self._min_joy
00042
00043 def get_max_joystick(self):
00044 return self._max_joy
00045
00046 def get_mid_joystick(self):
00047 return self._mid_joy
00048
00049 def get_deadband(self):
00050 return self._deadband
00051
00052 def to_clib(self):
00053 return self._to_clib
00054
00055 def get_length(self):
00056 return super(MotorToTakeover, self).get_length() + MOTOR_TO_TAKEOVER_SIZE
00057
00058 def is_reverse(self):
00059 return self._rev == REVERSE
00060
00061 def to_bytes(self):
00062 return super(MotorToTakeover, self).to_bytes() \
00063 + struct.pack('<B', self._ch) \
00064 + struct.pack('<H', self._max_command) \
00065 + struct.pack('<B', self._pin) \
00066 + struct.pack('<B', self._tab) \
00067 + struct.pack('<H', self._min_joy) \
00068 + struct.pack('<H', self._mid_joy) \
00069 + struct.pack('<H', self._max_joy) \
00070 + struct.pack('<?', self._to_clib) \
00071 + struct.pack('<f', self._deadband) \
00072 + struct.pack('<b', self._rev)
00073
00074 def convert_to_pkg(self, raw_data):
00075 super(MotorToTakeover, self).convert_to_pkg(raw_data)
00076 self._ch = struct.unpack('<B', bytearray(raw_data[3]))[0]
00077 self._max_command = struct.unpack('<H', bytearray(raw_data[4:6]))[0]
00078 self._pin = struct.unpack('<B', bytearray(raw_data[6]))[0]
00079 self._tab = struct.unpack('<B', bytearray(raw_data[7]))[0]
00080 self._min_joy = struct.unpack('<H', bytearray(raw_data[8:10]))[0]
00081 self._mid_joy = struct.unpack('<H', bytearray(raw_data[10:12]))[0]
00082 self._max_joy = struct.unpack('<H', bytearray(raw_data[12:14]))[0]
00083 self._to_clib = struct.unpack('<?', bytearray(raw_data[14]))[0]
00084 self._deadband = struct.unpack('<f', bytearray(raw_data[15:19]))[0]
00085 self._rev = struct.unpack('<b', bytearray(raw_data[19]))[0]
00086
00087
00088
00089
00090