Exemplo n.º 1
0
def values():
  global frontright,frontmiddle,frontleft,right,left,back
  #Digital and analog readings
  #THESE NEED TO BE UPDATED CONSTANTLY
  right = RPL.analogRead(5)
  back = RPL.digitalRead(17)
  frontright = RPL.digitalRead(20)
  left = RPL.analogRead(6)
  #frontmiddle = RPL.digitalRead(19)
  frontmiddle = RPL.analogRead(7)
  frontleft = RPL.digitalRead(18)
  #print(values) to debug readings
  return "front right = %s\nfront middle = %s\nfront left = %s\nright = %s\nleft = %s\nback = %s" % (frontright,frontmiddle,frontleft,right,left,back)
Exemplo n.º 2
0
def checkPin(x, y):
    global multiplier
    if (y == 0):
        RPL.servoWrite(x, 2000)
        print("Moving motor " + str(x) + "... ")
        time.sleep(1)
        RPL.servoWrite(x, 1500)
        RPL.servoWrite(x, 0)
        print("Done with motor " + str(x) + ".")
        x += 1
        print("Motor testing completed!")
    if (y == 1):
        RPL.pinMode(pinArraySensorset1[x], RPL.INPUT)
        initialTime = float(time.clock() * multiplier)
        while (float(time.clock() * multiplier) < (initialTime + 4)):
            displayTextClear()
            print("Pin " + str(pinArraySensorset1[x]) + " output: " +
                  str(RPL.digitalRead(pinArraySensorset1[x])))
            time.sleep(0.2)
        print("Digital sensor testing complete!")
    if (y == 2):
        initialTime = float(time.clock() * multiplier)
        while (float(time.clock() * multiplier) < (initialTime + 4)):
            displayTextClear()
            print("Pin " + str(pinArraySensorset2[x]) + " output: " +
                  str(RPL.analogRead(pinArraySensorset2[x])))
            time.sleep(0.2)
        print("Analog sensor testing complete!")
Exemplo n.º 3
0
def move_forward():
    while True:
        RPL.pinMode(sensor_pinF, RPL.INPUT)
        reading1 = RPL.digitalRead(sensor_pinF)
        RPL.pinMode(sensor_pinL, RPL.INPUT)
        reading2 = RPL.digitalRead(sensor_pinL)
        RPL.pinMode(sensor_pinR, RPL.INPUT)
        reading3 = RPL.digitalRead(sensor_pinR)
        if reading1 == 1:
            RPL.servoWrite(0, 1450)
            RPL.servoWrite(1, 1550)
        elif reading1 == 0:
            if reading2 == 1:
                RPL.servoWrite(0, 1400)
                RPL.servoWrite(1, 1550)
            elif reading2 == 0:
                RPL.servoWrite(0, 1450)
                RPL.servoWrite(1, 1550)
Exemplo n.º 4
0
def checkPinsDigital():
    x = 0
    global multiplier
    multiplier = 1
    if (os.name != 'nt'):
        multiplier = 1000
    while (x < len(pinArraySensorset1)):
        RPL.pinMode(pinArraySensorset1[x], RPL.INPUT)
        initialTime = float(time.clock() * multiplier)
        while (float(time.clock() * multiplier) < (initialTime + 4)):
            displayTextClear()
            print("Pin " + str(pinArraySensorset1[x]) + " output: " +
                  str(RPL.digitalRead(pinArraySensorset1[x])))
            time.sleep(0.2)
        x += 1
    print("Digital sensor testing complete!")
Exemplo n.º 5
0
motorR = 2
right = 17
front = 16
left = 19
rgo = 2000
lgo = 200

# ^ all setup

RPL.servoWrite(motorR, rgo)
RPL.servoWrite(motorL, lgo) # start off both motors going straight
while True:
    RPL.servoWrite(motorR, rgo) # reset motors to straight through each loop
    RPL.servoWrite(motorL, lgo)

    while RPL.digitalRead(front) == 0: # something ahead, turn until nothing
        RPL.servoWrite(motorL, rgo) # turn left
        if RPL.digitalRead(left) == 0: # if something to the right, turn left
            RPL.servoWrite(motorL, lgo)
            RPL.servoWrite(motorR, lgo)
        if RPL.digitalRead(front) != 0: # nothing to front
            now = time.time()
            future = now + .5 # continue turning for an extra .5s
            while True:
                if time.time() > future:
                    RPL.servoWrite(motorR, rgo)
                    RPL.servoWrite(motorL, lgo)
                    break
            break

    while RPL.digitalRead(right) == 0: # something to right...
Exemplo n.º 6
0
right = 19
front = 16
left = 17
analogL = 1

rgo = 2000
lgo = 1000

# ^ setup

RPL.servoWrite(motorR, rgo)
RPL.servoWrite(motorL, lgo) # turn on both motors going straight

while True:
    RPL.servoWrite(motorR, rgo)
    RPL.servoWrite(motorL, lgo)

    while RPL.analogRead(analogL) >= 400: # middle range, can go straight
        RPL.servoWrite(motorR, rgo)
        RPL.servoWrite(motorL, lgo)

    while RPL.analogRead(analogL) < 400: # no longer middle
        if RPL.digitalRead(left) == 0: # digital also sense, so close
            RPL.servoWrite(motorR, 0) # turn away from wall
            RPL.servoWrite(motorL, lgo)

        if RPL.digitalRead(left) == 1: # digital doesn't sense, far
            RPL.servoWrite(motorR, rgo) # turn towards wall
            RPL.servoWrite(motorL, 0)
Exemplo n.º 7
0
rslow = 1500
lgo = 100
lslow = 600

RPL.servoWrite(motorR, rgo)
RPL.servoWrite(motorR, rgo)
RPL.servoWrite(motorL, lgo)
RPL.servoWrite(motorL, lgo)

while True:
    RPL.servoWrite(motorR, rgo)
    RPL.servoWrite(motorL, lgo)

    while RPL.analogRead(analogR) >= 300:  # middle range, can go straight
        print "we good"
        RPL.servoWrite(motorR, rgo)
        RPL.servoWrite(motorL, lgo)

    while RPL.analogRead(analogR) < 300:  # no longer middle
        while RPL.digitalRead(19) == 0:  # digital also sense, so close
            print "close"
            print RPL.analogRead(analogR)
            RPL.servoWrite(motorR, rslow)
            RPL.servoWrite(motorL, lgo)

        while RPL.digitalRead(19) == 1:  # digital doesn't sense, far
            print "far"
            print RPL.analogRead(analogR)
            RPL.servoWrite(motorR, rgo)
            RPL.servoWrite(motorL, lslow)
Exemplo n.º 8
0
    RPL.servoWrite(motorL, lgo)
    RPL.servoWrite(motorR, rgo)


def stop():
    RPL.servoWrite(motorL, 0)
    RPL.servoWrite(motorR, 0)


while True:
    while True:  # forward
        RPL.analogRead(fana)
        RPL.analogRead(back)
        Fanalog = RPL.analogRead(fana)
        Banalog = RPL.analogRead(bana)
        frontsensor = RPL.digitalRead(16)
        straight = Fanalog - Banalog

        #if there is something in front it will turn left
        if frontsensor == 0:
            RPL.servoWrite(motorL, lgo)
            RPL.servoWrite(motorR, 0)

        # calibrating the distance off the wall:
        if Fanalog <= closedist and Banalog <= closedist:
            RPL.servoWrite(motorL, lslow)
            RPL.servoWrite(motorR, rgo)

        if Fanalog >= fardist and Banalog >= fardist:
            RPL.servoWrite(motorL, lgo)
            RPL.servoWrite(motorR, rslow)
Exemplo n.º 9
0
import RoboPiLib as RPL  # (robotonomy setup.py)
from setup import RPL  # (robotonomy README.md)
import time
RPL.RoboPiInit("/dev/ttyAMA0", 115200)  # (robotonomy setup.py)

motorL = 1  # (robo-control control.py)
motorR = 0  # (robo-control control.py)
sensor_pin = 16  # (robotonomy basic.py)

RPL.servoWrite(motorR, 2000)  # (robo-control control.py)
RPL.servoWrite(motorL, 1000)  # (robo-control control.py)
RPL.pinMode(sensor_pin, RPL.INPUT)  # (robo-control control.py)

while RPL.digitalRead(sensor_pin) == 1:  # (robotonomy basic.py)
    RPL.servoWrite(motorR, 2000)  # (robo-control control.py)
    RPL.servoWrite(motorL, 1000)  # (robo-control control.py)
else:
    RPL.servoWrite(motorR, 0)  # (robo-control control.py)
    RPL.servoWrite(motorL, 0)  # (robo-control control.py)
Exemplo n.º 10
0
import RoboPiLib as RPL
from setup import RPL
import time
import post_to_web as PTW
RPL.RoboPiInit("/dev/ttyAMA0", 115200)

motorL = 1
motorR = 0
sensor_pin = 16

RPL.servoWrite(motorR, 1000)
RPL.servoWrite(motorL, 2000)
RPL.pinMode(sensor_pin, RPL.INPUT)

while RPL.digitalRead(sensor_pin) == 1:
    PTW.state['d1'] = RPL.digitalRead(sensor_pin)
    RPL.servoWrite(motorR, 1000)
    RPL.servoWrite(motorL, 2000)
    PTW.post()
else:
    PTW.state['d1'] = RPL.digitalRead(sensor_pin)
    RPL.servoWrite(motorR, 0)
    RPL.servoWrite(motorL, 0)
    PTW.post()
Exemplo n.º 11
0
import RoboPiLib as RPL
import setup
x = 1
Sensor_pin = 16
RPL.pinMode(sensor_pin, RPL.INPUT)
while x == 1:
    reading = RPL.digitalRead(sensor_pin)
    if reading == 0:
        RPL.servoWrite(0, 1600)
    elif reading == 1:
        RPL.servoWrite(0, 300)
Exemplo n.º 12
0
motorR = 2
motorL = 0
# lsens = 23
# fsens = 16

# motorR forward = 1000
# motorL forward = 2000

# Okay so this is good but I think we need to do a thing to actually make it...
# ...turn into a gap because right now it's just turning away from a wall

RPL.servoWrite(motorR, 100)
RPL.servoWrite(motorL, 2000)
print "going"
while True:
    if RPL.digitalRead(23) == 0:
        RPL.servoWrite(motorR, 100)
        RPL.servoWrite(motorL, 2000)
        print "something"
    if RPL.digitalRead(23) == 1:
        timeb = time.time()
        RPL.servoWrite(motorR, 100)
        RPL.servoWrite(motorL, 2000)
        print "gap"
        if RPL.digitalRead(23) == 0:
            timea = time.time()
            timeg = timea - timeb
            while timeg < 2:
                RPL.servoWrite(motorR, 100)
                RPL.servoWrite(motorL, 2000)
                print "moving on"
Exemplo n.º 13
0
import RoboPiLib as RPL
from setup import RPL
import time
import post_to_web as PTW
RPL.RoboPiInit("/dev/ttyAMA0", 115200)

motorL = 2
motorR = 1
sensor_pin = 17
j = 3
i = 5.

while RPL.digitalRead(sensor_pin) == 1:
    PTW.state['d1'] = RPL.digitalRead(sensor_pin)
    RPL.servoWrite(motorR, 1000)
    RPL.servoWrite(motorL, 2000)
    PTW.post()
    if RPL.digitalRead(sensor_pin) != 1:
        break

while RPL.digitalRead(sensor_pin) == 0:
    PTW.state['d1'] = RPL.digitalRead(sensor_pin)
    PTW.post()
    move = time.time()
    while time.time() < (move + i):
        RPL.servoWrite(motorR, 1475)
        RPL.servoWrite(motorL, 1520)
    while time.time() > (move + i):
        RPL.servoWrite(motorR, 0)
        RPL.servoWrite(motorL, 0)
Exemplo n.º 14
0
import RoboPiLib as RPL
import time
RPL.RoboPiInit("/dev/ttyAMA0",115200)

motorL = 7
motorR = 6
sensor_R = 16
sensor_M = 17
sensor_L = 18
j = 3.5

RPL.servoWrite(motorR, 2000)
RPL.servoWrite(motorL, 1000)

while RPL.digitalRead(sensor_R) or RPL.digitalRead(sensor_M) or RPL.digitalRead(sensor_L)!= 1:
	while RPL.digitalRead(sensor_R) == 0:
   		move = time.time()
   		while time.time() < (move + j):
        		RPL.servoWrite(motorL, 1490)
        		RPL.servoWrite(motorR, 2000)
		if time.time() > (move + j):
        		RPL.servoWrite(motorL, 1000)
        		RPL.servoWrite(motorR, 2000)
	while RPL.digitalRead(sensor_L) == 0:
    		run = time.time()
    		while time.time() < (run + j):
        		RPL.servoWrite(motorL, 1000)
        		RPL.servoWrite(motorR, 1510)
		if time.time() > (run + j):
        		RPL.servoWrite(motorL, 1000)
        		RPL.servoWrite(motorR, 2000)
Exemplo n.º 15
0

def start_right():
    RPL.servoWrite(2, 1550)
    RPL.servoWrite(1, 1420)
    print "Turning Right"


def start_left():
    RPL.servoWrite(1, 1460)
    RPL.servoWrite(2, 1550)
    print "Turning Left"


while True:
    sensorL = RPL.digitalRead(22)
    sensorM = RPL.digitalRead(20)
    sensorR = RPL.digitalRead(23)
    move_forward = False
    move_left = False
    move_right = False
    go_reverse = False

    if sensorL == 1:
        move_right = True
    elif sensorM == 1:
        go_reverse = True
    elif sensorR == 1:
        move_left = True
    else:
        move_forward = True
Exemplo n.º 16
0
import RoboPiLib as RPL
import setup
import post_to_web as PTW

sensor_pin = 16
RPL.pinMode(sensor_pin, RPL.INPUT)

running = True
braking = False
m1Speed = 1400
m2Speed = 1600
while running:
    reading = RPL.digitalRead(sensor_pin)

    if reading == 0:
        braking = True
    if braking == True and m1Speed != 1500 and m2Speed != 1500:
        print("If statement fired")
        m1Speed += 10
        m2Speed -= 10
    if m1Speed == 1500 and m2Speed == 1500:
        m1Speed = 00
        m2Speed = 00
        running = False

    RPL.servoWrite(0, m1Speed)
    RPL.servoWrite(1, m2Speed)

    PTW.state['d1'] = RPL.digitalRead(sensor_pin)
    PTW.state['d2'] = RPL.servoRead(0)
    PTW.state['d3'] = RPL.servoRead(1)
Exemplo n.º 17
0
from time import sleep
sensor_pinF = 16
sensor_pinL = 18
sensor_pinR = 17
a = 0
b = 0


def fire():
    for fire in range(0, b):
        RPL.servoWrite(0, 1400)
        RPL.servoWrite(1, 1600)
        sleep(1)
        RPL.servoWrite(0, 1500)
        RPL.servoWrite(1, 1500)
        sleep(1)


while True:
    RPL.pinMode(sensor_pinF, RPL.INPUT)
    reading1 = RPL.digitalRead(sensor_pinF)
    RPL.pinMode(sensor_pinL, RPL.INPUT)
    reading2 = RPL.digitalRead(sensor_pinL)
    RPL.pinMode(sensor_pinR, RPL.INPUT)
    reading3 = RPL.digitalRead(sensor_pinR)
    if reading1 == 0:
        b += 1
        a += b
        fire()
        print("the motor has fired ", a, " times.")
Exemplo n.º 18
0
def stop():
    RPL.servoWrite(motorL, 0)
    RPL.servoWrite(motorR, 0)


def turnL():
    RPL.servoWrite(motorL, 1480)
    RPL.servoWrite(motorR, motorR_forward)


def turnR():
    RPL.servoWrite(motorL, motorL_forward)
    RPL.servoWrite(motorR, 1520)


while counter == 0:

    front_obstacle = RPL.digitalRead(17)
    right_obstacle = RPL.digitalRead(16)
    left_obstacle = RPL.digitalRead(18)

    if front_obstacle == 1:
        forward()

    if front_obstacle == 0:
        turnL()

    if right_obstacle == 0:
        turnL()
Exemplo n.º 19
0
#brings in time
import time
start = time.time()
#to make sensors work
import setup
import RoboPiLib as RPL
#sensor pin reading
pin = raw_input("What is the pin number? ")
#to make definable in a function
close = RPL.digitalRead(pin)
#which pin the motor is in
motorL = 1
mororR = 0
#it runs when the pin is not reading anything
while close is 1:
    RPL.servoWrite(mororL, 1000)
    RPL.servoWrite(motorR, 2000)
#it stops when the sensor senses something
else:
    RPL.servoWrite(mororL, 0)
    RPL.servoWrite(motorR, 0)
    return
#write code to slow down robot
end = time.time()
Exemplo n.º 20
0
import setup
import RoboPiLib as RPL
import time

sensor_pin = 16
RPL.pinMode(sensor_pin, RPL.INPUT)

while True:
    if RPL.digitalRead(sensor_pin) == 1:
        import RoboPiLib as RPL
        import setup
        RPL.servoWrite(0, 2000)
        RPL.servoWrite(1, 500)

    if RPL.digitalRead(sensor_pin) == 0:
        import RoboPiLib as RPL
        import setup
        RPL.servoWrite(0, 0)
        RPL.servoWrite(1, 0)
Exemplo n.º 21
0
        RPL.servoWrite(L, 1500)


def right():
    if readingL == 0:
        RPL.servoWrite(R, 1590)
    elif readingL == 1:
        RPL.servoWrite(R, 1500)


def both():
    RPL.servoWrite(L, 1590)
    RPL.servoWrite(R, 1410)


def none():
    RPL.servoWrite(L, 1500)
    RPL.servoWrite(R, 1500)


while x == 1:
    readingL = RPL.digitalRead(LS)
    readingR = RPL.digitalRead(RS)
    if readingL == 0 and readingR == 0:
        both()
    elif readingL == 1 and readingR == 1:
        none()
    else:
        left()
        right()
Exemplo n.º 22
0
import setup
import RoboPiLib as RPL
import time

motorR = 2
motorL = 0

while True:
    while RPL.digitalRead(16) == 1:
        RPL.servoWrite(motorL, 100)
        RPL.servoWrite(motorR, 2000)
        print "nothing"

    while RPL.digitalRead(16) == 0:
        future = time.time() + 0.5
        while time.time() < future:
            RPL.servoWrite(motorL, 600)
            RPL.servoWrite(motorR, 1500)
            print "slowing"
            while time.time() >= future:
                RPL.servoWrite(motorL, 0)
                RPL.servoWrite(motorR, 0)
                print "stop"
Exemplo n.º 23
0
motorR_forward = 2000
motorR_backward = 1000
motorL_forward = 1000
motorL_backward = 2000


counter = 0

def forward():
  RPL.servoWrite(motorL,motorL_forward)
  RPL.servoWrite(motorR,motorR_forward)

def stop():
  RPL.servoWrite(motorL, 0)
  RPL.servoWrite(motorR, 0)

while counter == 0:

    RPL.digitalRead(17)

    obstacle = RPL.digitalRead(17)

    if obstacle == 1:

        forward()

    if obstacle == 0:
        stop()
        counter = counter + 1
Exemplo n.º 24
0
front = 16
left = 19

rgo = 2000
lgo = 200

RPL.servoWrite(motorR, rgo)
RPL.servoWrite(motorR, rgo)
RPL.servoWrite(motorL, lgo)
RPL.servoWrite(motorL, lgo)
while True:
    RPL.servoWrite(motorR, rgo)
    RPL.servoWrite(motorL, lgo)
    print ".............."

    while RPL.digitalRead(front) == 0 and RPL.digitalRead(
            right) == 0:  # reverse
        if RPL.digitalRead(left) == 0:
            RPL.servoWrite(motorR, lgo)
            RPL.servoWrite(motorL, rgo)

    while RPL.digitalRead(front) == 0:  # something ahead, turn until nothing
        RPL.servoWrite(motorL, rgo)
        print "++++++"
        if RPL.digitalRead(front) != 0:  # nothing to side, go
            now = time.time()
            future = now + 1
            while True:
                if time.time() > future:
                    RPL.servoWrite(motorR, rgo)
                    RPL.servoWrite(motorL, lgo)
Exemplo n.º 25
0
import RoboPiLib as RPL
import setup
import post_to_web as PTW

lmotor = 0
rmotor = 1

d1 = 16
d2 = 17

while True:
  d1read = RPL.digitalRead(d1)
  d2read = RPL.digitalRead(d2)
  
  
  if d1read == 1 and d2read == 1:
    RPL.servoWrite(lmotor,1400)
    RPL.servoWrite(rmotor,1600)
    
  elif d1read == 0 and d2read == 0:
    RPL.servoWrite(lmotor,0)
    RPL.servoWrite(rmotor,0)
    print('so long comerade')
    exit()
    
  elif d1read == 0 or d2read == 0:
    RPL.servoWrite(lmotor,1500)
    RPL.servoWrite(rmotor,1500)
    
    
  PTW.state['d1'] = d1read
Exemplo n.º 26
0
def sokomade():
    while RPL.digitalRead(17) == 0:
        RPL.servoWrite(1, 0)
        RPL.servoWrite(2, 0)
        if RPL.digitalRead(17) == 1:
            forward()
Exemplo n.º 27
0
import setup
import RoboPiLib as RPL

sensor_pin = 17
RPL.pinMode(sensor_pin,RPL.INPUT)

while True:
  while RPL.digitalRead(sensor_pin) == 1:
    RPL.servoWrite(0,500)
    RPL.servoWrite(1,2000)
  while RPL.digitalRead(sensor_pin)== 0:
    first_time == time.time()
    while 1 >= time.time() - first_time:
      RPL.servoWrite(0,
Exemplo n.º 28
0
import RoboPiLib as RPL
import post_to_web as PTW
RPL.RoboPiInit("/dev/ttyAMA0", 115200)
import time

while True:
    PTW.state['d1'] = RPL.digitalRead(16)
    time.sleep(0.3)
    PTW.post()
Exemplo n.º 29
0
def forward():
    while RPL.digitalRead(17) == 1:
        RPL.servoWrite(1, 1000)
        RPL.servoWrite(2, 2000)
        if RPL.digitalRead(17) == 0:
            stoppu()
Exemplo n.º 30
0
import RoboPiLib as RPL
import time
import post_to_web as PTW
RPL.RoboPiInit("/dev/ttyAMA0", 115200)

motorL = 1
motorR = 7
sensor_R = 16
sensor_M = 17
sensor_L = 18
j = 3
i = 4.0

while RPL.digitalRead(sensor_R) and RPL.digitalRead(
        sensor_M) and RPL.digitalRead(sensor_L) == 1:
    PTW.state['d1'] = RPL.digitalRead(sensor_pin)
    RPL.servoWrite(motorR, 1000)
    RPL.servoWrite(motorL, 2000)
    PTW.post()
    if RPL.digitalRead(sensor_R) or RPL.digitalRead(
            sensor_M) or RPL.digitalRead(sensor_L) == 0:
        break

while RPL.digitalRead(sensor_R) == 0:
    PTW.state['d1'] = RPL.digitalRead(sensor_R)
    move = time.time()
    while time.time() < (move + i):
        RPL.servoWrite(motorR, 1490)
        RPL.servoWrite(motorL, 1520)
        PTW.post()
    while time.time() > (move + i):