Пример #1
0
 def create_message(self):
     self._message[0] = bytes(
         ByteUtils.translate_int_to_bytes(self.COMMAND_FIRST_BYTE, number_of_bytes=1, signed=False)
     )
     self._message[1] = bytes(
         ByteUtils.translate_int_to_bytes(self.SET_TARGET_BYTE, number_of_bytes=1, signed=False)
     )
     self._message[2] = bytes(
         ByteUtils.translate_int_to_bytes(self._channel_number, number_of_bytes=1, signed=False)
     )
     self._message[3] = bytes(
         ByteUtils.translate_int_to_bytes(self._convert_angle_for_pololu(), number_of_bytes=1, signed=False)
     )
 def _set_message_bytes(self):
     self._message[1] = bytes([ByteUtils.translate_int_to_bytes(self._speed_motor_1, number_of_bytes = 2, signed = True)[0]])
     self._message[2] = bytes([ByteUtils.translate_int_to_bytes(self._speed_motor_1, number_of_bytes = 2, signed = True)[1]])
     self._message[3] = bytes([ByteUtils.translate_int_to_bytes(self._speed_motor_2, number_of_bytes = 2, signed = True)[0]])
     self._message[4] = bytes([ByteUtils.translate_int_to_bytes(self._speed_motor_2, number_of_bytes = 2, signed = True)[1]])
     self._message[5] = bytes([ByteUtils.translate_int_to_bytes(self._speed_motor_3, number_of_bytes = 2, signed = True)[0]])
     self._message[6] = bytes([ByteUtils.translate_int_to_bytes(self._speed_motor_3, number_of_bytes = 2, signed = True)[1]])
     self._message[7] = bytes([ByteUtils.translate_int_to_bytes(self._speed_motor_4, number_of_bytes = 2, signed = True)[0]])
     self._message[8] = bytes([ByteUtils.translate_int_to_bytes(self._speed_motor_4, number_of_bytes = 2, signed = True)[1]])
Пример #3
0
 def _set_message_bytes(self):
     self._message[1] = bytes([ByteUtils.translate_int_to_bytes(self._position_x, number_of_bytes = 2, signed = True)[0]])
     self._message[2] = bytes([ByteUtils.translate_int_to_bytes(self._position_x, number_of_bytes = 2, signed = True)[1]])
     self._message[3] = bytes([ByteUtils.translate_int_to_bytes(self._position_y, number_of_bytes = 2, signed = True)[0]])
     self._message[4] = bytes([ByteUtils.translate_int_to_bytes(self._position_y, number_of_bytes = 2, signed = True)[1]])
     self._message[5] = bytes([ByteUtils.translate_int_to_bytes(self._speed_limit, number_of_bytes = 2, signed = True)[0]])
     self._message[6] = bytes([ByteUtils.translate_int_to_bytes(self._speed_limit, number_of_bytes = 2, signed = True)[1]])
     self._message[7] = bytes([ByteUtils.translate_int_to_bytes(self._sequence_number, number_of_bytes = 2, signed = True)[0]])
     self._message[8] = bytes([ByteUtils.translate_int_to_bytes(self._sequence_number, number_of_bytes = 2, signed = True)[1]])
 def _set_message_bytes(self):
     self._message[1] = bytes([ByteUtils.translate_int_to_bytes(self._routine_number, number_of_bytes = 2, signed = True)[0]])
     self._message[2] = bytes([ByteUtils.translate_int_to_bytes(self._routine_number, number_of_bytes = 2, signed = True)[1]])
     self._message[3] = bytes([ByteUtils.translate_int_to_bytes(0, number_of_bytes = 2, signed = True)[0]])
     self._message[4] = bytes([ByteUtils.translate_int_to_bytes(0, number_of_bytes = 2, signed = True)[1]])
     self._message[5] = bytes([ByteUtils.translate_int_to_bytes(0, number_of_bytes = 2, signed = True)[0]])
     self._message[6] = bytes([ByteUtils.translate_int_to_bytes(0, number_of_bytes = 2, signed = True)[1]])
     self._message[7] = bytes([ByteUtils.translate_int_to_bytes(self._sequence_number, number_of_bytes = 2, signed = True)[0]])
     self._message[8] = bytes([ByteUtils.translate_int_to_bytes(self._sequence_number, number_of_bytes = 2, signed = True)[1]])
Пример #5
0
 def _set_message_bytes(self):
     converted_theta = self._convert_theta_to_int()
     self._message[1] = bytes([ByteUtils.translate_int_to_bytes(converted_theta, number_of_bytes = 2, signed = True)[0]])
     self._message[2] = bytes([ByteUtils.translate_int_to_bytes(converted_theta, number_of_bytes = 2, signed = True)[1]])
     self._message[3] = bytes([ByteUtils.translate_int_to_bytes(self._speed_limit, number_of_bytes = 2, signed = True)[0]])
     self._message[4] = bytes([ByteUtils.translate_int_to_bytes(self._speed_limit, number_of_bytes = 2, signed = True)[1]])
     self._message[5] = bytes([ByteUtils.translate_int_to_bytes(0, number_of_bytes = 2, signed = True)[0]])
     self._message[6] = bytes([ByteUtils.translate_int_to_bytes(0, number_of_bytes = 2, signed = True)[1]])
     self._message[7] = bytes([ByteUtils.translate_int_to_bytes(self._sequence_number, number_of_bytes = 2, signed = True)[0]])
     self._message[8] = bytes([ByteUtils.translate_int_to_bytes(self._sequence_number, number_of_bytes = 2, signed = True)[1]])
Пример #6
0
    def _translate_data(self, last_message_parameters):
        if len(last_message_parameters) != Constants.MESSAGE_SIZE - 3:
            raise CommunicationException("Tried to process a message that was not the right size")

        self._capacitor_voltage = ByteUtils.converts_two_bytes_to_int(ByteUtils.group_bytes_in_pairs(last_message_parameters[0:2]))
        self._secret_code = ByteUtils.converts_bytes_to_char(last_message_parameters[2])
        self._treasure_completion = ByteUtils.convert_bytes_to_int(last_message_parameters[3], signed = False)
        self._motor_1_setpoint_completion = ByteUtils.convert_bytes_to_int(last_message_parameters[4], signed = False)
        self._motor_2_setpoint_completion = ByteUtils.convert_bytes_to_int(last_message_parameters[5], signed = False)
        self._motor_3_setpoint_completion = ByteUtils.convert_bytes_to_int(last_message_parameters[6], signed = False)
        self._motor_4_setpoint_completion = ByteUtils.convert_bytes_to_int(last_message_parameters[7], signed = False)
Пример #7
0
 def _verify_checksum(self):
     checksum = 0
     for i in range(0, 10):
         checksum += ByteUtils.convert_bytes_to_int(self.messages_buffer[i], signed = False)
     return (checksum % 256) == 0