示例#1
0
def pid_process(output, p, i, d, objCoord, centerCoord):
    # signal trap to handle keyboard interrupt
    signal.signal(signal.SIGINT, signal_handler)

    # create and init PID
    p = PID(p.value, i.value, d.value)
    p.initialize()
    time.sleep(2)

    while True:
        error = centerCoord.value - objCoord.value
        output.value = p.update(error)
示例#2
0
def pid_process(output, p, i, d, objCoord, centerCoord):
    # signal trap to handle keyboard interrupt
    signal.signal(signal.SIGINT, signal_handler)
 
    # create a PID and initialize it
    p = PID(p.value, i.value, d.value)
    p.initialize()
 
    # loop indefinitely
    while True:
        # calculate the error
        error = centerCoord.value - objCoord.value
        
        # update the value
        output.value = p.update(error)
def pid(output, coord, object_center):
    # Get the right values and initialize PID
    if coord == 'pan':
        pid = PID(panP, panI, panD)
        screen_center = centerX
    else:
        pid = PID(tiltP, tiltI, tiltD)
        screen_center = centerY
    pid.initialize()
    while True:
        # Calculate the error
        error = screen_center - object_center.value
        # If error is 0 then object is in center or is not detected, so re-initialize PID
        if abs(error) < screen_center / 10:
            pid.initialize()
            output.value = 0
        else:
            output.value = pid.update(error)
            time.sleep(0.01)