Esempio n. 1
0
def read_position(ser,
                  joints,
                  verbose=VERBOSE,
                  num_error_attempts=NUM_ERROR_ATTEMPTS):
    """
    Read the current position of each joint.

    Move each joint to this position so that servo
    does not jerk into position when moved later.

    :param ser: The ``serial`` object to use.
    :param joints: A list of servo IDs.
    :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. (Default: ``NUM_ERROR_ATTEMPTS``.)

    :returns: An array of values which correspond to the initial positions of the joints.

    """

    # Create a list to hold the positions
    init_positions = []

    # Iterate over the joints and read the position of each
    for j in joints:

        if verbose:
            print('Reading initial position for joint {0}...'.format(j))

        pos = packets.get_read_position_packet(j)
        init_positions.append(pos)

    return init_positions
Esempio n. 2
0
def read_position(ser, joints, verbose = VERBOSE, num_error_attempts = NUM_ERROR_ATTEMPTS):
    """
    Read the current position of each joint. 
    
    Move each joint to this position so that servo
    does not jerk into position when moved later.
    
    :param ser: The ``serial`` object to use. 
    :param joints: A list of servo IDs.
    :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. (Default: ``NUM_ERROR_ATTEMPTS``.)
    
    :returns: An array of values which correspond to the initial positions of the joints. 
    
    """
    
    # Create a list to hold the positions
    init_positions = []
    
    # Iterate over the joints and read the position of each
    for j in joints:
        
        if verbose:
            print('Reading initial position for joint {0}...'.format(j))
        
        pos = packets.get_read_position_packet(j)
        init_positions.append(pos)
        
    return init_positions
Esempio n. 3
0
def get_position(ser, servo_id, verbose = VERBOSE, num_error_attempts = NUM_ERROR_ATTEMPTS):
    """
    Read the current position as reported by a servo.
    
    :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.
    
    :returns: An integer indicating the reported position.
    """
    
    packet = packets.get_read_position_packet(servo_id)
    resp = write_and_get_response_multiple(ser, packet, servo_id, verbose, num_error_attempts)
    return resp.data[1] * 256 + resp.data[0]
Esempio n. 4
0
def get_position(ser,
                 servo_id,
                 verbose=VERBOSE,
                 num_error_attempts=NUM_ERROR_ATTEMPTS):
    """
    Read the current position as reported by a servo.

    :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.

    :returns: An integer indicating the reported position.
    """

    packet = packets.get_read_position_packet(servo_id)
    resp = write_and_get_response_multiple(ser, packet, servo_id, verbose,
                                           num_error_attempts)
    return resp.data[1] * 256 + resp.data[0]