|
|
|
@ -3,11 +3,11 @@ import os
|
|
|
|
|
import time
|
|
|
|
|
import RPi.GPIO as GPIO
|
|
|
|
|
from base_ctrl import BaseController
|
|
|
|
|
#######################################
|
|
|
|
|
#############信号引脚定义##############
|
|
|
|
|
#######################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GPIO.setmode(GPIO.BCM)
|
|
|
|
|
GPIO.setwarnings(False)
|
|
|
|
|
#底盘连接
|
|
|
|
|
def is_raspberry_pi5():
|
|
|
|
|
with open('/proc/cpuinfo', 'r') as file:
|
|
|
|
|
for line in file:
|
|
|
|
@ -17,75 +17,18 @@ def is_raspberry_pi5():
|
|
|
|
|
else:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
#云台连接
|
|
|
|
|
|
|
|
|
|
base = BaseController('/dev/ttyAMA0', 115200)
|
|
|
|
|
|
|
|
|
|
class CAR:
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self.LED0 = 10 #LED0的IO口定义
|
|
|
|
|
self.LED1 = 9 #LED1的IO口定义
|
|
|
|
|
self.LED2 = 25 #LED2的IO口定义
|
|
|
|
|
self.ENA = 13 #//L298 使能A
|
|
|
|
|
self.ENB = 20 #//L298 使能B
|
|
|
|
|
self.IN1 = 19 #//电机接口1
|
|
|
|
|
self.IN2 = 16 #//电机接口2
|
|
|
|
|
self.IN3 = 21 #//电机接口3
|
|
|
|
|
self.IN4 = 26 #//电机接口4
|
|
|
|
|
GPIO.setup(self.LED0, GPIO.OUT, initial=GPIO.HIGH) ##led0初始化为高电平
|
|
|
|
|
GPIO.setup(self.LED1, GPIO.OUT, initial=GPIO.HIGH) ##led1初始化为高电平
|
|
|
|
|
GPIO.setup(self.LED2, GPIO.OUT, initial=GPIO.HIGH) ##led2初始化为高电平
|
|
|
|
|
GPIO.setup(self.ENA, GPIO.OUT, initial=GPIO.LOW) ##ENA初始化为低电平
|
|
|
|
|
GPIO.setup(self.ENB, GPIO.OUT, initial=GPIO.LOW) ##ENB初始化为低电平
|
|
|
|
|
GPIO.setup(self.IN1, GPIO.OUT, initial=GPIO.LOW) ##IN1初始化为低电平
|
|
|
|
|
GPIO.setup(self.IN2, GPIO.OUT, initial=GPIO.LOW) ##IN2初始化为低电平
|
|
|
|
|
GPIO.setup(self.IN3, GPIO.OUT, initial=GPIO.LOW) ##IN3初始化为低电平
|
|
|
|
|
GPIO.setup(self.IN4, GPIO.OUT, initial=GPIO.LOW) ##IN4初始化为低电平
|
|
|
|
|
|
|
|
|
|
def led(self):
|
|
|
|
|
GPIO.output(self.LED0,False)
|
|
|
|
|
GPIO.output(self.LED1,False)
|
|
|
|
|
GPIO.output(self.LED2,False)###LED0,LED1,LED2 = 亮 亮 亮
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
GPIO.output(self.LED0,True)
|
|
|
|
|
GPIO.output(self.LED1,False)
|
|
|
|
|
GPIO.output(self.LED2,False)###LED0,LED1,LED2 = 灭 亮 亮
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
GPIO.output(self.LED0,False)
|
|
|
|
|
GPIO.output(self.LED1,True)
|
|
|
|
|
GPIO.output(self.LED2,False)###LED0,LED1,LED2 = 亮 灭 亮
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
GPIO.output(self.LED0,False)
|
|
|
|
|
GPIO.output(self.LED1,False)
|
|
|
|
|
GPIO.output(self.LED2,True)###LED0,LED1,LED2 = 亮 亮 灭
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
GPIO.output(self.LED0,False)
|
|
|
|
|
GPIO.output(self.LED1,False)
|
|
|
|
|
GPIO.output(self.LED2,False)###LED0,LED1,LED2 = 亮 亮 亮
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
GPIO.output(self.LED0,True)
|
|
|
|
|
GPIO.output(self.LED1,True)
|
|
|
|
|
GPIO.output(self.LED2,True)###LED0,LED1,LED2 = 灭 灭 灭
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
print("run: led")
|
|
|
|
|
|
|
|
|
|
def led_light(self):
|
|
|
|
|
GPIO.output(self.LED0,False)
|
|
|
|
|
GPIO.output(self.LED1,False)
|
|
|
|
|
GPIO.output(self.LED2,False)###LED0,LED1,LED2 = 亮 亮 亮
|
|
|
|
|
print("run: led_light")
|
|
|
|
|
|
|
|
|
|
def led_dark(self):
|
|
|
|
|
GPIO.output(self.LED0,True)
|
|
|
|
|
GPIO.output(self.LED1,True)
|
|
|
|
|
GPIO.output(self.LED2,True)###LED0,LED1,LED2 = 灭 灭 灭
|
|
|
|
|
print("run: led_dark")
|
|
|
|
|
input_x = 0
|
|
|
|
|
input_y = 0
|
|
|
|
|
input_speed = 0
|
|
|
|
|
input_acc = 0
|
|
|
|
|
|
|
|
|
|
def stop(self): # 停止运行
|
|
|
|
|
GPIO.output(self.ENA,False)
|
|
|
|
|
GPIO.output(self.ENB,False)
|
|
|
|
|
GPIO.output(self.IN1,False)
|
|
|
|
|
GPIO.output(self.IN2,False)
|
|
|
|
|
GPIO.output(self.IN3,False)
|
|
|
|
|
GPIO.output(self.IN4,False)
|
|
|
|
|
base.send_command({"T":1,"L":0,"R":0})
|
|
|
|
|
print("run: stop move")
|
|
|
|
|
|
|
|
|
|
def Q(self): # 停止的快捷键
|
|
|
|
@ -95,7 +38,7 @@ class CAR:
|
|
|
|
|
|
|
|
|
|
def forward(self): # 前进
|
|
|
|
|
base.send_command({"T":1,"L":0.2,"R":0.2})
|
|
|
|
|
time.sleep(2)
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
base.send_command({"T":1,"L":0,"R":0})
|
|
|
|
|
print("run: move !!!!forward")
|
|
|
|
|
|
|
|
|
@ -105,12 +48,9 @@ class CAR:
|
|
|
|
|
self.forward()
|
|
|
|
|
|
|
|
|
|
def back(self): # 后退
|
|
|
|
|
GPIO.output(self.ENA,True)
|
|
|
|
|
GPIO.output(self.ENB,True)
|
|
|
|
|
GPIO.output(self.IN1,True)
|
|
|
|
|
GPIO.output(self.IN2,False)
|
|
|
|
|
GPIO.output(self.IN3,True)
|
|
|
|
|
GPIO.output(self.IN4,False)
|
|
|
|
|
base.send_command({"T":1,"L":-0.2,"R":-0.2})
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
base.send_command({"T":1,"L":0,"R":0})
|
|
|
|
|
print("run: move back")
|
|
|
|
|
|
|
|
|
|
def S(self): # 后退的快捷键
|
|
|
|
@ -119,12 +59,9 @@ class CAR:
|
|
|
|
|
self.back()
|
|
|
|
|
|
|
|
|
|
def left(self): # 左转
|
|
|
|
|
GPIO.output(self.ENA,True)
|
|
|
|
|
GPIO.output(self.ENB,True)
|
|
|
|
|
GPIO.output(self.IN1,False)
|
|
|
|
|
GPIO.output(self.IN2,True)
|
|
|
|
|
GPIO.output(self.IN3,True)
|
|
|
|
|
GPIO.output(self.IN4,False)
|
|
|
|
|
base.send_command({"T":1,"L":-0.2,"R":0.2})
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
base.send_command({"T":1,"L":0,"R":0})
|
|
|
|
|
print("run: move left")
|
|
|
|
|
|
|
|
|
|
def A(self): # 左转的快捷键
|
|
|
|
@ -133,15 +70,28 @@ class CAR:
|
|
|
|
|
self.left()
|
|
|
|
|
|
|
|
|
|
def right(self): # 右转
|
|
|
|
|
GPIO.output(self.ENA,True)
|
|
|
|
|
GPIO.output(self.ENB,True)
|
|
|
|
|
GPIO.output(self.IN1,True)
|
|
|
|
|
GPIO.output(self.IN2,False)
|
|
|
|
|
GPIO.output(self.IN3,False)
|
|
|
|
|
GPIO.output(self.IN4,True)
|
|
|
|
|
base.send_command({"T":1,"L":0.2,"R":-0.2})
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
base.send_command({"T":1,"L":0,"R":0})
|
|
|
|
|
print("run: move right")
|
|
|
|
|
|
|
|
|
|
def D(self): # 右转的快捷键
|
|
|
|
|
self.right()
|
|
|
|
|
def d(self):
|
|
|
|
|
self.right()
|
|
|
|
|
self.right()
|
|
|
|
|
|
|
|
|
|
def up(self):
|
|
|
|
|
self.input_y+=10
|
|
|
|
|
base.gimbal_ctrl(self.input_x, self.input_y, self.input_speed, self.input_acc)
|
|
|
|
|
|
|
|
|
|
def down(self):
|
|
|
|
|
self.input_y-=10
|
|
|
|
|
base.gimbal_ctrl(self.input_x, self.input_y, self.input_speed, self.input_acc)
|
|
|
|
|
|
|
|
|
|
def yunleft(self):
|
|
|
|
|
self.input_x-=10
|
|
|
|
|
base.gimbal_ctrl(self.input_x, self.input_y, self.input_speed, self.input_acc)
|
|
|
|
|
|
|
|
|
|
def yunright(self):
|
|
|
|
|
self.input_x+=10
|
|
|
|
|
base.gimbal_ctrl(self.input_x, self.input_y, self.input_speed, self.input_acc)
|