mercredi 12 août 2020

Script not recognizing false-statement from different script

  • Python version: 3.7.3
  • TensorFlow version: 2.2.0
  • Operating System: Raspbian

I am trying to follow get my Raspberry Pi to successfully scan, then track a RPi camera, following this repository. When I issue the 'rpi-deep-pantilt track Raspi' command, it successfully starts detecting in a stationary position, but if it detects an object, it begins tracking. I need it to make 60deg increments while detecting, so I incorporated the bolded lines into the manager.py script:

import logging
from multiprocessing import Value, Process, Manager

import pantilthat as pth
import signal
import sys
**import time
import RPi.GPIO as GPIO**

**from rpi_deep_pantilt.detect.util.visualization import draw_bounding_box_on_image**
from rpi_deep_pantilt.detect.camera import run_pantilt_detect
from rpi_deep_pantilt.control.pid import PIDController

**#Specifying GPIO Pin name
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(8,GPIO.OUT)**

**scan_on=True**

logging.basicConfig()
LOGLEVEL = logging.getLogger().getEffectiveLevel()

RESOLUTION = (320, 320)

SERVO_MIN = -90
SERVO_MAX = 90

CENTER = (
    RESOLUTION[0] // 2,
    RESOLUTION[1] // 2
)

# function to handle keyboard interrupt
def signal_handler(sig, frame):
    # print a status message
    print("[INFO] You pressed `ctrl + c`! Exiting...")

    # disable the servos
    pth.servo_enable(1, False)
    pth.servo_enable(2, False)
    GPIO.output(8,GPIO.LOW)

    # exit
    sys.exit()


def in_range(val, start, end):
    # determine the input value is in the supplied range
    return (val >= start and val <= end)


def set_servos(pan, tilt):
    # signal trap to handle keyboard interrupt
    signal.signal(signal.SIGINT, signal_handler)
   
    while True:
        pan_angle = -1 * pan.value
        tilt_angle = tilt.value
        
        # if the pan angle is within the range, pan
        if in_range(pan_angle, SERVO_MIN, SERVO_MAX):
            pth.pan(pan_angle)
        else:
            logging.info(f'pan_angle not in range {pan_angle}')

        if in_range(tilt_angle, SERVO_MIN, SERVO_MAX):
            pth.tilt(tilt_angle)
        else:
            logging.info(f'tilt_angle not in range {tilt_angle}')
        
        **if scan_on == True:
            pth.servo_one(90)
            pth.servo_two(25)
            time.sleep(10)
            
            pth.servo_one(30)
            pth.servo_two(25)
            time.sleep(10)
            
            pth.servo_one(-30)
            pth.servo_two(25)
            time.sleep(10)
            
            pth.servo_one(-90)
            pth.servo_two(25)
            time.sleep(10)**
.
.

The last few lines are the scanning procedures. They work, but once an object is detected, it doesn't exit the scanning cycle. This is the part of my visualizion.py script that is referenced in manager.py:

def draw_bounding_box_on_image(image,
                               ymin,
                               xmin,
                               ymax,
                               xmax,
                               color='red',
                               thickness=4,
                               display_str_list=(),
                               use_normalized_coordinates=True):
   
    GPIO.output(8,GPIO.HIGH)
    scan_on = False
    draw = ImageDraw.Draw(image)
    im_width, im_height = image.size
.
.

I used the GPIO to light up an LED, letting me know when the bounding box has been overlaid on the camera feed. At this point my system should identify that scan_on = False, and it should exit the scan cycle and revert to the default tracking mode. My manager.py script must not pick it up because it continues to run the scanning, meaning scan_on = True. I figure it's an issue in my manager.py script, just don't know where to start.

Aucun commentaire:

Enregistrer un commentaire