示例#1
0
def scan():
    scanList = []
    for i in range(10, 110, 10):
        print 'i =', i
        servo.setServo(i)
        time.sleep(1)
        scanList.append(us.getDistance())
    servo.servoMiddle()
    return scanList
示例#2
0
def scan():
    scan_list = []
    dis = 0.0
    for i in range(10, 100, 5):
        servo.setServo(i)
        time.sleep(0.5)
        dis = us.getDistance()
        while dis > 1000 or dis < 5:
            print 'dis =', dis
            dis = us.getDistance()
        scan_list.append(dis)
    servo.servoMiddle()
    return scan_list
示例#3
0
def find_obstacle():
    print 'Finding Obstacles...'
    dis = 0.0
    for i in range(30, 80, 10):
        servo.setServo(i)
        time.sleep(0.5)
        dis = us.getDistance()
        while dis > 500 or dis < 5:
            dis = us.getDistance()
        if dis < critical_distance:
            servo.servoMiddle()
            print 'Obstacle Found !'
            return True
    servo.servoMiddle()
    print 'No Obstacles !'
    return False
示例#4
0
            print 'DELAY_360_RIGHT -0.001 =>', DELAY_360_RIGHT, 's'

        elif keyp == '5':
            print '================================================'
            print 'DISTANCE =>', DISTANCE, 'cm'
            print 'ANGLE =>', ANGLE, 'deg'
            print 'CAR_SPEED_FORWARD =>', CAR_SPEED_FORWARD, 'cm/s'
            print 'DELAY_360_RIGHT =>', DELAY_360_RIGHT, 's'
            print 'DELAY_360_LEFT =>', DELAY_360_LEFT, 's'
            print '================================================'

        elif keyp == '0':
            scanList = []
            dis = 0.0
            for i in range(10, 100, 10):
                servo.setServo(i)
                time.sleep(0.5)
                dis = us.getDistance()
                while dis > 1000 or dis < 5:
                    dis = us.getDistance()
                scanList.append(dis)
            servo.servoMiddle()
            print '  ===  '.join(map(str, scanList))

        elif keyp == 'x':
            break

    cleanup()

except KeyboardInterrupt:
    cleanup()
示例#5
0
            car.Rreverse()
            print 'Rreverse'
        elif keyp == ' ':
            car.stop()
            print 'Stop'

        #   UltraSound Sensor

        elif keyp == 't':
            print 'distance =', us.getDistance(), "cm"

        #   Servo Motor

        elif keyp == 'i':
            position = 50
            servo.setServo(position)
            print 'Servo set to Middle Position'
        elif keyp == 'o':
            position = 0
            servo.setServo(position)
            print 'Servo set to Left Position'
        elif keyp == 'p':
            position = 100
            servo.setServo(position)
            print 'Servo set to Right Position'

        elif keyp == 'y':
            if position < 100:
                position += step
                servo.setServo(position)
                print 'Servo Position +', step, '=', position
示例#6
0
import tty
import termios
from socket import *

servo.init()

HOST = ''
PORT = 21567
BUFSIZE = 1024
ADDR = (HOST,PORT)

tcpSerSock = socket(AF_INET, SOCK_STREAM)
tcpSerSock.bind(ADDR)
tcpSerSock.listen(5)

while True:
        print 'Waiting for connection'
        tcpCliSock,addr = tcpSerSock.accept()
        print '...connected from :', addr
        try:
                while True:
                        data = ''
                        data = tcpCliSock.recv(BUFSIZE)
                        if not data:
                                break
                        servo.setServo(int(data))
                        print 'Servo Position', '=', int(data)
        except KeyboardInterrupt:
                fun.stopServo()
                fun.cleanup()
tcpSerSock.close();
示例#7
0
def cleanup():
    print 'Cleaning up Servo Motor ...'
    servo.cleanup()
    print 'Done Cleaning up Servo Motor.'

servo.init()

begin = 10
end = 90

print 'Servo Radar Program has Started ...'

try:
    if begin < 0 :
        begin = 0
    if end > 100 :
        end = 100
    
    while True:
        for x in range(begin, end):
            servo.setServo(x)
            time.sleep(0.005)
        x=end
        while x > begin:
            servo.setServo(x)
            time.sleep(0.005)
            x -= 1
except KeyboardInterrupt:
    cleanup()