from adafruit_servokit import ServoKit import time import Jetson.GPIO as GPIO from multiprocessing import Process from playsound import playsound import pyrealsense2 as rs #mode='auto' mode = 'user' GPIO.cleanup() # Declare the GPIO settings GPIO.setmode(GPIO.BOARD) BS = 15 LS = 13 RS = 11 HS = 16 GPIO.setup(BS, GPIO.IN) Bc = 1 - GPIO.input(BS) GPIO.setup(LS, GPIO.IN) Lc = 1 - GPIO.input(LS) GPIO.setup(RS, GPIO.IN) Rc = 1 - GPIO.input(RS) GPIO.setup(HS, GPIO.IN)
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries # # SPDX-License-Identifier: MIT """Tegra T186 pin names""" import atexit from Jetson import GPIO GPIO.setmode(GPIO.TEGRA_SOC) GPIO.setwarnings(False) # shh! class Pin: """Pins dont exist in CPython so...lets make our own!""" IN = 0 OUT = 1 LOW = 0 HIGH = 1 PULL_NONE = 0 PULL_UP = 1 PULL_DOWN = 2 id = None _value = LOW _mode = IN def __init__(self, bcm_number): self.id = bcm_number def __repr__(self):
def GPIO_main(self): # self.timer.moveToThread(self.GPIOThreadHandle) global clickState global firstTime global secondTime global program_step global print_once_flag global timeEclipse global clickFlag global click_once global time_long_set global time_long_long_set global falling_edge_flag global rising_edge_flag global cansel_flag global ok_flag # Pin Setup: GPIO.setmode(GPIO.BOARD) # BOARD pin-numbering scheme # GPIO.setup([led_pin_1, led_pin_2], GPIO.OUT) # LED pins set as output GPIO.setup(gpi_grabimage, GPIO.IN) # button pin set as input # Initial state for LEDs: # GPIO.output(led_pin_1, GPIO.LOW) # GPIO.output(led_pin_2, GPIO.LOW) GPIO.add_event_detect(gpi_grabimage, GPIO.BOTH, callback=self.blink, bouncetime=200) # print("Starting demo now! Press CTRL+C to exit") pwm = PCA9685() pwm.setPWMFreq(50) pwm.setPWM(3, 0, 0) # 关闭可见激光 pwm.setPWM(4, 0, 0) # 关闭红外光源 pwm.setPWM(5, 0, 0) # 关闭红外激光 try: while True: if (clickState == 1): timeEclipse = time.time() - firstTime if (timeEclipse > time_long_set): ok_flag = 1 clickFlag = 1 clickState = 0 firstTime = 0 # print("state 3") else: # time.sleep(0.01) click_once = 0 if (clickState == 2): timeEclipse = secondTime - firstTime if (timeEclipse < time_long_set): cansel_flag = 1 clickFlag = 2 secondTime = 0 firstTime = 0 clickState = 0 if (clickFlag == 1): # print("this is single click") clickState = 0 clickFlag = 0 elif (clickFlag == 2): # print("this is double click") clickState = 0 clickFlag = 0 if (clickFlag == 3): clickState = 0 clickFlag = 0 # print("this is changan") if (program_step == 1 and print_once_flag == 0): # print("点亮可见激光") # print("点亮不可见激光") # print("点亮光源") pwm.setPWM(3, 0, 4095) # 点亮可见激光 pwm.setPWM(4, 0, 4095) # 点亮红外光源 pwm.setPWM(5, 0, 4095) # 点亮红外激光 print("======================================================================") print_once_flag = 1 if (program_step == 2 and print_once_flag == 1): # print("熄灭光源") pwm.setPWM(4, 0, 0) # 熄灭红外光源 print("抓拍一张激光图像") # 将此句话替换成拍照激光图片的函数即可 time.sleep(0.5) # self.signal_cap_laserimg.emit() self.trigger_laser_img() pwm.setPWM(3, 0, 0) # 熄灭可见激光 pwm.setPWM(5, 0, 0) # 熄灭红外激光 time.sleep(0.5) print("抓拍一张heise图像") # 将此句话替换成拍照heise图片的函数即可 # self.signal_cap_nolightimg.emit() self.trigger_nolight_img() # self.trigger_laser_img() # self.trigger_nolight_img() # print("打开光源") # print("熄灭可见激光") # print("熄灭不可见激光") pwm.setPWM(4, 0, 4095) # 打开红外光源 pwm.setPWM(3, 0, 0) # 熄灭可见激光 pwm.setPWM(5, 0, 0) # 熄灭红外激光 print("抓拍一张灰度图像") # 将此句话替换成拍照灰度图片的函数即可 # self.signal_cap_inferredimg.emit() time.sleep(0.5) self.trigger_inferred_img() print('2222') # time.sleep(0.5) print('3333') pwm.setPWM(4, 0, 0) # 熄灭红外光源 print('4444') print("开始上传激光图像") # 将此句话替换成上传激光图片的函数即可 print("开始上传灰度图像") # 将此句话替换成上传灰度图片的函数即可 # self.signal.emit() self.signal_send_imgs.emit() # self.send_conbine_img() # time.sleep(0.5) print("显示轮廓图像") # 将此句话替换成显示轮廓图片的函数即可 print("等待确认回复") print("======================================================================") print_once_flag = 2 if (program_step == 2 and cansel_flag == 1 and print_once_flag == 2): cansel_flag = 0 print("取消重新开始") self.signal_cancel_result.emit() # self.cancel_result() print("======================================================================") print_once_flag = 0 program_step = 0 if (program_step == 2 and ok_flag == 1 and print_once_flag == 2): ok_flag = 0 print("确认重新开始") self.signal_confirm_result.emit() # self.confirm_result() print("======================================================================") print_once_flag = 0 program_step = 0 finally: GPIO.cleanup() # cleanup all GPIOs
def GPIO_main(self): # self.timer.moveToThread(self.GPIOThreadHandle) global clickState global firstTime global secondTime global program_step global print_once_flag global timeEclipse global clickFlag global click_once global time_long_set global time_long_long_set global falling_edge_flag global rising_edge_flag global cansel_flag global ok_flag # Pin Setup: GPIO.setmode(GPIO.BOARD) # BOARD pin-numbering scheme # GPIO.setup([led_pin_1, led_pin_2], GPIO.OUT) # LED pins set as output GPIO.setup(gpi_grabimage, GPIO.IN) # button pin set as input GPIO.add_event_detect(gpi_grabimage, GPIO.BOTH, callback=self.blink, bouncetime=200) # print("Starting demo now! Press CTRL+C to exit") pwm = PCA9685() pwm.setPWMFreq(50) pwm.setPWM(3, 0, 0) # 关闭可见激光 pwm.setPWM(4, 0, 0) # 关闭红外光源 pwm.setPWM(5, 0, 0) # 关闭红外激光 try: while True: if (clickState == 1): timeEclipse = time.time() - firstTime if (timeEclipse > time_long_set): ok_flag = 1 clickFlag = 1 clickState = 0 firstTime = 0 # print("state 3") else: # time.sleep(0.01) click_once = 0 if (clickState == 2): timeEclipse = secondTime - firstTime if (timeEclipse < time_long_set): cansel_flag = 1 clickFlag = 2 secondTime = 0 firstTime = 0 clickState = 0 if (clickFlag == 1): # print("this is single click") clickState = 0 clickFlag = 0 elif (clickFlag == 2): # print("this is double click") clickState = 0 clickFlag = 0 if (clickFlag == 3): clickState = 0 clickFlag = 0 # print("this is changan") if (program_step == 1 and print_once_flag == 0): # print("点亮可见激光") # print("点亮不可见激光") # print("点亮光源") self.label_3.setText('') pwm.setPWM(3, 0, 4095) # 点亮可见激光 pwm.setPWM(4, 0, 4095) # 点亮红外光源 pwm.setPWM(5, 0, 4095) # 点亮红外激光 print( "======================================================================" ) print_once_flag = 1 if (program_step == 2 and print_once_flag == 1): # print("熄灭光源") pwm.setPWM(4, 0, 0) # 熄灭红外光源 print("抓拍一张激光图像") # 将此句话替换成拍照激光图片的函数即可 # set laser exposure current_expo = c_float() self.clientImID = int(round(time.time() * 1000)) ret = self.cam.MV_CC_GetFloatValue('ExposureTime', current_expo) if (current_expo.value != self.laser_exposure): ret = self.cam.MV_CC_SetFloatValue( 'ExposureTime', self.laser_exposure) time.sleep(0.25) self.trigger_laser_img() while (True): res = judge_image_property0921.is_laserImage_proper( self.laserImg) if (res[0] == 1): break elif (res[0] == 0): if ((self.laser_exposure < 1000)): self.laser_exposure = 1000 self.trigger_laser_img() break if ((self.laser_exposure > 5000)): self.laser_exposure = 5000 self.trigger_laser_img() break self.laser_exposure = max( 1000, self.laser_exposure + 200) self.trigger_laser_img() elif (res[0] == 2): if ((self.laser_exposure > 5000)): self.laser_exposure = 5000 self.trigger_laser_img() break if ((self.laser_exposure < 1000)): self.laser_exposure = 1000 self.trigger_laser_img() break self.laser_exposure = min( 5000, self.laser_exposure - 200) self.trigger_laser_img() pwm.setPWM(3, 0, 0) # 熄灭可见激光 pwm.setPWM(5, 0, 0) # 熄灭红外激光 # print("打开光源") # print("熄灭可见激光") # print("熄灭不可见激光") pwm.setPWM(4, 0, 4095) # 打开红外光源 pwm.setPWM(3, 0, 0) # 熄灭可见激光 pwm.setPWM(5, 0, 0) # 熄灭红外激光 current_expo = c_float() ret = self.cam.MV_CC_GetFloatValue('ExposureTime', current_expo) if (current_expo.value != self.inferred_exposure): ret = self.cam.MV_CC_SetFloatValue( 'ExposureTime', self.inferred_exposure) time.sleep(0.25) print("抓拍一张灰度图像") # 将此句话替换成拍照灰度图片的函数即可 self.trigger_inferred_img() while (True): res = judge_image_property0921.is_grayImage_proper( self.inferredImg) if (res[0] == 1): break elif (res[0] == 0): if ((self.inferred_exposure < 100)): self.inferred_exposure = 100 self.trigger_inferred_img() break if ((self.inferred_exposure > 3000)): self.inferred_exposure = 3000 self.trigger_inferred_img() break self.inferred_exposure = max( 100, self.inferred_exposure + 200) self.trigger_inferred_img() elif (res[0] == 2): if ((self.inferred_exposure > 3000)): self.inferred_exposure = 3000 self.trigger_inferred_img() break if ((self.inferred_exposure < 100)): self.inferred_exposure = 100 self.trigger_inferred_img() break self.inferred_exposure = min( 3000, self.inferred_exposure - 200) self.trigger_inferred_img() pwm.setPWM(4, 0, 0) # 熄灭红外光源 print("开始上传激光图像") # 将此句话替换成上传激光图片的函数即可 print("开始上传灰度像") # 将此句话替换成上传灰度图片的函数即可 self.signal_send_imgs.emit() print("显示轮廓图像") # 将此句话替换成显示轮廓图片的函数即可 print("等待确认回复") print( "======================================================================" ) print_once_flag = 2 if (program_step == 2 and cansel_flag == 1 and print_once_flag == 2): cansel_flag = 0 print("取消重新开始") self.signal_cancel_result.emit() # self.cancel_result() print( "======================================================================" ) print_once_flag = 0 program_step = 0 if (program_step == 2 and ok_flag == 1 and print_once_flag == 2): ok_flag = 0 print("确认重新开始") self.signal_confirm_result.emit() # self.confirm_result() print( "======================================================================" ) print_once_flag = 0 program_step = 0 finally: GPIO.cleanup() # cleanup all GPIOs
def setPins(self): GPIO.setmode(GPIO.BOARD) # enable mode to use pin numbers GPIO.setup(self.gpio_low_input, GPIO.OUT, initial=GPIO.HIGH) GPIO.setup(self.triggerPin, GPIO.OUT) GPIO.setup(self.echoPin, GPIO.IN)
import cv2 import numpy as np import math import time import Jetson.GPIO as GPIO # MOTORS SETUP # GPIO.cleanup() #clean trash from ports GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) # Motor left GPIO.setup(18, GPIO.OUT) # IN1 GPIO.setup(17, GPIO.OUT) # IN2 # Motor right GPIO.setup(23, GPIO.OUT) # IN3 GPIO.setup(22, GPIO.OUT) # IN4 # define color detection boundaries lowerBound = np.array([29, 85, 6]) upperBound = np.array([64, 255, 255]) # camera setup dispW = 640 dispH = 480 flip = 2 camSet = 'nvarguscamerasrc ! video/x-raw(memory:NVMM), width=1980, height=1080, format=NV12, framerate=59/1 ! nvvidconv flip-method=' + str( flip) + ' ! video/x-raw, width=' + str(dispW) + ', height=' + str( dispH ) + ', format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink' cam = cv2.VideoCapture(camSet) # setting up kernel properties with matrices kernelOpen = np.ones((5, 5))