Exemplo n.º 1
0
def RoboCommand(words):
	global command
	strg='' 
	for w in words[:]:
	     if (w !=0):
		strg=strg+str(w)
	if (strg == 'WALK'):api.PlayAction(83)
	elif (strg == 'STOP'):api.PlayAction(82)
	elif (strg == 'STAND'):api.PlayAction(82)
	elif (strg == 'SIT'):api.PlayAction(80)
	elif (strg == 'FINAL'):
		api.PlayAction(83)
		while int(reading(0))>30:
			print 'walking' #30cm is the distance between the two robots- we can set the final line at this point
		api.PlayAction(82)
	elif (strg == 'SOS'):print 'api.PlayAction(SOS )'
	elif (strg == 'UVA'):api.PlayAction(84)
Exemplo n.º 2
0
# -*- coding: UTF-8 -*-
from PCA9685 import PCA9685  #导入驱动,
import time
import ultrasonic
pwm = PCA9685()
pwm.init()  #初始化pca9685
pwm.setsq(60)  #设置频率
pwm.allinit()  #把16个通道初始化

jiaodu = 90
while 1:
    while jiaodu < 130:
        pwm.setduoji(0, jiaodu)  #设置0通道角度
        #        pwm.setduoji(1,jiaodu)#设置1通道角度
        #        jiaodu=jiaodu+1
        #        time.sleep(0.01)
        print jiaodu
        ultrasonic.reading(0)
    while jiaodu > 30:
        pwm.setduoji(0, jiaodu)
        #        pwm.setduoji(1,jiaodu)
        #        jiaodu=jiaodu-1
        #        time.sleep(0.01)
        print jiaodu
        ultrasonic.reading(0)
Exemplo n.º 3
0
import time
import ultrasonic as us
import infrared as ir
import RPi.GPIO as GPIO

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)

distance = 0
detect = 0
motion_detect = 0
sensor = 0
LED = 14
GPIO.setup(LED, GPIO.OUT)

while True:
    motion_detect = ir.motion_detect(detect)
    if motion_detect == 1:
        distance = us.reading(sensor)
        print("distance:" + str(distance))
        if distance < 30:
            GPIO.output(LED, 1)
        elif distance > 400:
            print("error")
        else:
            GPIO.output(LED, 0)
Exemplo n.º 4
0
from ultrasonic import reading
while True:
    print reading(0)