Example #1
0
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)
Example #2
0
def set_position(ser, servo_id, position, verbose = VERBOSE, num_error_attempts = NUM_ERROR_ATTEMPTS):
    """
    Set the taget position of a servo (the servo will not move until an action packet is sent).
    
    :param ser: The ``serial`` object to use. 
    :param servo_id: The id of the servo.
    :param position: The position to set, (0, 1023). 
    :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.
    """
    
    packet = packets.get_write_position_packet(servo_id, position)
    write_and_get_response_multiple(ser, packet, servo_id, verbose, num_error_attempts)
Example #3
0
def set_position_no_response(ser,
                             servo_id,
                             position,
                             verbose=VERBOSE,
                             num_error_attempts=NUM_ERROR_ATTEMPTS):
    """
    Set the taget position of a servo with in "no wait response" mode.

    :param ser: The ``serial`` object to use.
    :param servo_id: The id of the servo.
    :param position: The position to set, (0, 1023).
    :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``.)

    """

    packet = packets.get_write_position_packet(servo_id, position)
    write_and_no_get_response(ser, packet)
Example #4
0
def set_position_no_response(ser,
                             servo_id,
                             position,
                             verbose=VERBOSE,
                             num_error_attempts=NUM_ERROR_ATTEMPTS):
    """
    Set the taget position of a servo (the servo will not move until an action packet is sent).

    :param ser: The ``serial`` object to use.
    :param servo_id: The id of the servo.
    :param position: The position to set, (0, 1023).
    :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.
    """

    packet = packets.get_write_position_packet(servo_id, position)
    write_and_no_get_response(ser, packet)
Example #5
0
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)