Esempio n. 1
0
 def check_initialised(self):
     command = AlpesCommand(PREFIXES.LECTURE_REGISTRE,
                            REGISTRE_INITIALISATION, 1)
     self.serial.write(command.pack())
     response = AlpesResponse(
         self.serial.read(command.expected_response_size))
     return response.data[0] == 1
Esempio n. 2
0
 def left_or_right(self):
     command = AlpesCommand(PREFIXES.LECTURE_REGISTRE,
                            1000 + REGISTRES.ID_DROITE_GAUCHE, 1)
     self.serial.write(command.pack())
     response = AlpesResponse(
         self.serial.read(command.expected_response_size))
     self.id = 'left' if response.data[0] == 2 else 'right'
     return self.id
Esempio n. 3
0
 def __read_registers_consecutively(self, first_register_position,
                                    number_of_registers):
     command = AlpesCommand(PREFIXES.LECTURE_REGISTRE,
                            first_register_position, number_of_registers,
                            [])
     self.serial.write(command.pack())
     return AlpesResponse(self.serial.read(
         command.expected_response_size)).data
Esempio n. 4
0
 def read_velocities(self):  #, get_directions = 'False'):
     # Asks the hand and returns angular velocity of the motors in turns/min
     command = AlpesCommand(PREFIXES.LECTURE_VITESSE_MOTEUR, 0, 6,
                            self.current_limit)
     self.serial.write(command.pack())
     response = AlpesResponse(
         self.serial.read(command.expected_response_size)).data
     return [d / 100 for d in response]  # Conversion to turns/min
Esempio n. 5
0
 def read_positions(self):
     command = AlpesCommand(PREFIXES.LECTURE_POSITION_CODEUR, 0, 6,
                            self.current_limit)
     self.serial.write(command.pack())
     response = AlpesResponse(
         self.serial.read(command.expected_response_size))
     # Sometimes when rotating backwards, motors go slightly beyond the origin point of rotation,
     # which results in values like 65535 that are, in fact, impossible.
     # In my opinion, it only clutters the user's data and therefore I filter it out.
     result = list(map(lambda x: x if x < 65500 else 0, response.data))
     limits = [21000, 19000, 43000, 43000, 43000, 43000]
     result = list(map(lambda x, y: x if x < y else y, result, limits))
     return result
Esempio n. 6
0
 def __write_registers_consecutively(self, first_register_position,
                                     number_of_registers, data):
     if not isinstance(data, list):
         raise ValueError(
             'Provided data should be a list, even in single value')
     if len(data) != number_of_registers:
         raise ValueError(
             'Number of registers requested for writing does not match the length of provided data'
         )
     command = AlpesCommand(PREFIXES.ECRITURE_REGISTRE,
                            first_register_position, number_of_registers,
                            data)
     self.serial.write(command.pack())
     return AlpesResponse(self.serial.read(command.expected_response_size))
Esempio n. 7
0
 def read_velocities_and_directions(self):
     # Asks the hand and returns angular velocity of the motors in turns/min
     # ATTENTION: this method is left here in case someone wants to re-test it.
     # Previous attempts to receive the direction of rotation from the hand were not successful: contents of DIR_MOTEUR_CODEUR do not change in function of direction.
     command = AlpesCommand(PREFIXES.LECTURE_VITESSE_MOTEUR, 0, 6,
                            self.current_limit)
     self.serial.write(command.pack())
     response = AlpesResponse(
         self.serial.read(command.expected_response_size)).data
     # Getting sign of velocity is optional since it requires additional reading procedure
     # and may slow down the acquisition. In most of the cases, sign can be derived from the command.
     directions = self.read_registers_across(REGISTRES.DIR_MOTEUR_CODEUR)
     #print('AlpesHand.read_velocities_and_directions:', directions)
     signs = [(d & 2) > 0
              for d in directions]  # Read second bit of the response
     for i in range(len(response)):
         if not signs[i]:
             response[i] *= -1
     return response