import jetson.inference
import jetson.utils
import os
import time
import gpio as GPIO
#model = "../python/training/detection/ssd/models/pingpongballs/ssd-mobilenet.onnx"
#labels = "../python/training/detection/ssd/models/pingpongballs/labels.txt"
#input_blob = "input_0"
#output_cvg = "scores"
#output_bbox = "boxes"
def sweeper():
ENA = 40
IN2 = 38
IN1 = 36
GPIO.setmode(GPIO.BOARD)
GPIO.setup(ENA, GPIO.OUT,initial=GPIO.LOW)
GPIO.setup(IN1, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(IN2, GPIO.OUT, initial=GPIO.LOW)
GPIO.output(ENA,GPIO.HIGH)
GPIO.output(IN1, GPIO.HIGH)
GPIO.output(IN2, GPIO.LOW)
time.sleep(3)
GPIO.output(ENA,GPIO.LOW)
GPIO.output(IN1, GPIO.LOW)
GPIO.output(IN2, GPIO.LOW)
GPIO.cleanup()
def forward():
ENA = 37
IN2 = 33
IN1 = 35
IN3 = 29
IN4 = 31
ENB = 32
GPIO.setup(ENA, GPIO.OUT,initial=GPIO.LOW)
GPIO.setup(IN1, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(IN2, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(ENB, GPIO.OUT,initial=GPIO.LOW)
GPIO.setup(IN3, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(IN4, GPIO.OUT, initial=GPIO.LOW)
GPIO.output(ENA,GPIO.HIGH)
GPIO.output(ENB,GPIO.HIGH)
GPIO.output(IN1, GPIO.HIGH)
GPIO.output(IN2, GPIO.LOW)
GPIO.output(IN3, GPIO.HIGH)
GPIO.output(IN4, GPIO.LOW)
time.sleep(1)
GPIO.output(ENA,GPIO.LOW)
GPIO.output(ENB,GPIO.LOW)
GPIO.output(IN1, GPIO.LOW)
GPIO.output(IN2, GPIO.LOW)
GPIO.output(IN3, GPIO.LOW)
GPIO.output(IN4, GPIO.LOW)
time.sleep(0.5)
GPIO.cleanup()
def right():
ENA = 37
IN2 = 33
IN1 = 35
IN3 = 29
IN4 = 31
ENB = 32
GPIO.setup(ENA, GPIO.OUT,initial=GPIO.LOW)
GPIO.setup(IN1, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(IN2, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(ENB, GPIO.OUT,initial=GPIO.LOW)
GPIO.setup(IN3, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(IN4, GPIO.OUT, initial=GPIO.LOW)
GPIO.output(ENA,GPIO.HIGH)
GPIO.output(ENB,GPIO.HIGH)
GPIO.output(IN1, GPIO.LOW)
GPIO.output(IN2, GPIO.HIGH)
GPIO.output(IN3, GPIO.HIGH)
GPIO.output(IN4, GPIO.LOW)
time.sleep(0.5)
GPIO.output(ENA,GPIO.LOW)
GPIO.output(ENB,GPIO.LOW)
GPIO.output(IN1, GPIO.LOW)
GPIO.output(IN2, GPIO.LOW)
GPIO.output(IN3, GPIO.LOW)
GPIO.output(IN4, GPIO.LOW)
time.sleep(0.5)
GPIO.cleanup()
#creating the output text file, that we will write to each time we see a ping pong ball
output_file = open("output.txt","w")
net = jetson.inference.detectNet(argv=["--model=../python/training/detection/ssd/models/pingpongballs/ssd-mobilenet.onnx", "--labels=../python/training/detection/ssd/models/pingpongballs/labels.txt", "--input-blob=input_0", "--output-cvg=scores", "--output-bbox=boxes"],threshold=0.5)
camera = jetson.utils.videoSource("csi://0")
display = jetson.utils.videoOutput()
while True:
img = camera.Capture()
detections = net.Detect(img)
#ClassID 1 = White Ping Pong Ball, will not be using
#ClassID 2 = Orange Ping Pong Ball
validPingPong = 2
for detection in detections:
# output_file.write(str(detection.ClassID) + "\n")
if detection.ClassID ==2:
# sweeper()
print(1)
#An object to avoid
#if detection.ClassID > validPingPong:
#rotate or whatever
#Orange ping pong ball detected
#elif detection.ClassID == 2:
#move forward to scoop it
#time.sleep(0.1)
display.Render(img)
display.SetStatus("Object Detection | Network {:.0f} FPS".format(net.GetNetworkFPS()))
output_file.close()
I am running this script on the jetson inference docker container.
This my custom detectnet script. I wanted to add a function to move a some dc motors when an specific object was detected however, I am receiving errors. When i run the program, sometimes the program crashes startup and the gstreasmer gives an end of stream(EOS) message. It ran before once but crashed when the object the program was supposed to detect appeared infront of the camera module. I was trying to operate the dc motors with the gpio module however, it requires me to install the gpio module in the docker container every time or else the gpio module isn’t recognized. Any solutions for these issues.