def move_to_vector(ser, vector, verbose = VERBOSE, num_error_attempts = NUM_ERROR_ATTEMPTS): """ Move multiple servos concurrently. :param ser: The ``serial`` object to use. :param vector: A list of vectors in the form (id, position, velocity). :param verbose: If True, status information will be printed. Default: ``VERBOSE``. :param num_error_attempts: The number of attempts to make to send the packet when an error is encountered. :returns: ``None``. """ for i in range(0,len(vector)): servo_id = vector[i][0] angle = vector[i][1] velocity = vector[i][2] if verbose: print('Setting angle for {0} to {1}...'.format(id, angle)) packet = packets.get_write_position_packet(servo_id, angle) dynamixel.write_and_get_response_multiple(ser, packet, id, verbose, num_error_attempts) if verbose: print('Setting velocity for {0} to {1}...'.format(id, velocity)) packet = packets.get_write_velocity_packet(servo_id, velocity) dynamixel.write_and_get_response_multiple(ser, packet, id, verbose, num_error_attempts) if verbose: print('Sending action packet.') packet = packets.get_action_packet() ser.write(packet)
def send_action_packet(ser): """ Send an action packet, which causes all servos to move to their previously-specified target positions. :param ser: The ``serial`` object to use. :raises: An ``Exception`` if no packet is successfully read after ``attempts`` attempts. """ ser.write(packets.get_action_packet())
def init(ser, servo_id, verbose = VERBOSE, num_error_attempts = NUM_ERROR_ATTEMPTS): """ "Initialize" a servo by reading its current position and then writing that position. :param ser: The ``serial`` object to use. :param servo_id: The id of the servo. :param verbose: If True, status information will be printed. (Default: ``VERBOSE``). :param attempts: The number of attempts to make to send the packet when an error is encountered. (Default: ``NUM_ERROR_ATTEMPTS``.) :raises: An ``Exception`` if no packet is successfully read after ``attempts`` attempts. """ position = get_position(ser, servo_id, verbose, num_error_attempts) set_position(ser, servo_id, position, verbose, num_error_attempts) ser.write(packets.get_action_packet())
def init(ser, servo_id, verbose=VERBOSE, num_error_attempts=NUM_ERROR_ATTEMPTS): """ "Initialize" a servo by reading its current position and then writing that position. :param ser: The ``serial`` object to use. :param servo_id: The id of the servo. :param verbose: If True, status information will be printed. (Default: ``VERBOSE``). :param attempts: The number of attempts to make to send the packet when an error is encountered. (Default: ``NUM_ERROR_ATTEMPTS``.) :raises: An ``Exception`` if no packet is successfully read after ``attempts`` attempts. """ position = get_position(ser, servo_id, verbose, num_error_attempts) set_position(ser, servo_id, position, verbose, num_error_attempts) ser.write(packets.get_action_packet())
def move_to_vector(ser, vector, verbose=VERBOSE, num_error_attempts=NUM_ERROR_ATTEMPTS): """ Move multiple servos concurrently. :param ser: The ``serial`` object to use. :param vector: A list of vectors in the form (id, position, velocity). :param verbose: If True, status information will be printed. Default: ``VERBOSE``. :param num_error_attempts: The number of attempts to make to send the packet when an error is encountered. :returns: ``None``. """ for i in range(0, len(vector)): servo_id = vector[i][0] angle = vector[i][1] velocity = vector[i][2] if verbose: print('Setting angle for {0} to {1}...'.format(id, angle)) print("BBBBBBBBBB\n", vector[i]) print("AAAAAAA", angle) packet = packets.get_write_position_packet(servo_id, angle) dynamixel.write_and_get_response_multiple(ser, packet, id, verbose, num_error_attempts) if verbose: print('Setting velocity for {0} to {1}...'.format(id, velocity)) packet = packets.get_write_velocity_packet(servo_id, velocity) dynamixel.write_and_get_response_multiple(ser, packet, id, verbose, num_error_attempts) if verbose: print('Sending action packet.') packet = packets.get_action_packet() ser.write(packet)