예제 #1
0
import setup
from setup import RPL
import post_to_web as PTW # see post_to_web.py for instructions

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

def testing():
  RPL.servoWrite(0,2000)
  RPL.servoWrite(1,1000)
  time.sleep()

while True:
  PTW.state['d1'] = RPL.digitalRead(sensor_pin)
  PTW.post()

  import RoboPiLib as RPL
  import setup
  RPL.servoWrite(0,2000)
  RPL.servoWrite(1,1000)
  if RPL.digitalRead(sensor_pin) == 0:
     import RoboPiLib as RPL
     import setup
     RPL.servoWrite(0,1500)
     RPL.servoWrite(1,1000)
     time.sleep(2)
     RPL.servoWrite(0,2000)
     RPL.servoWrite(1,1000)
    

예제 #2
0
def testing():
  RPL.servoWrite(0,2000)
  RPL.servoWrite(1,1000)
  time.sleep()
예제 #3
0
파일: try.py 프로젝트: margenta19/13trials
import setup
from setup import RPL
import post_to_web as PTW

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

while True:
    PTW.state['d1'] = RPL.digitalRead(sensor_pin)
    PTW.post()

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

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

while True:
    PTW.state['d1'] = RPL.digitalRead(sensor_pin)
    PTW.post()

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

    if RPL.digitalRead(sensor_pin) == 0:
예제 #4
0
import setup
from setup import RPL
import post_to_web as PTW  # see post_to_web.py for instructions
import time
import RoboPiLib as RPL
#time.time- start equal to a value- can have it equal to the end of the program- to find the elapsed time- current time.time
#subtracted by the start time.time is divided- how many leftovers there are when that equals 0 the robot would stop
start = time.time()

x = 3

while True:
    elaptime = (time.time() - start)
    x = 0
    elaptime = int(elaptime)
    if elaptime % 1 == 0:
        RPL.servoWrite(1, 0)
        RPL.servoWrite(2, 0)
        x = x + 9
    if elaptime % 2 == 0:
        RPL.servoWrite(2, 1000)
        RPL.servoWrite(1, 250)
        x = x + 6
예제 #5
0
# if sensor reads 1- turn the motor off
# if sensor reads 0- continue

# looking in python the hard way at ex 33 to figure out
#if there is enough information there to make a while loop

#script to make i the sensor must come before

import setup
from setup import RPL
import post_to_web as PTW  # see post_to_web.py for instructions

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

while True:
    PTW.state['d1'] = RPL.digitalRead(sensor_pin)
    PTW.post()

if RPL.digitalRead(sensor_pin) == 1:
    import RoboPiLib as RPL
    import setup
    RPL.servoWrite(0, 1000)
    RPL.servoWrite(1000, 0)
if RPL.digitalRead(sensor_pin) == 0:
    import RoboPiLib as RPL
    import setup
    RPL.servoWrite(0, 0)
예제 #6
0
def usercont():
    back_sensor = 16
    left_sensor = 18
    rt_sensor = 17
    rt_wheel = 0
    lft_wheel = 1
    forward = 1000
    backward = 2000
    RPL.servoWrite(0, 0)
    RPL.servoWrite(1, 0)
    command = raw_input("> ")
    if command == "left":
        direction = raw_input("> ")
        if direction == "forward":
            RPL.servoWrite(lft_wheel, forward)
            followup = raw_input("> ")
            if followup == "stop":
                RPL.servoWrite(lft_wheel, 0)
                RPL.servoWrite(rt_wheel, 0)
                retrn()
        elif direction == "backward":
            RPL.servoWrite(lft_wheel, backward)
            followup = raw_input("> ")
            if followup == "stop":
                RPL.servoWrite(lft_wheel, 0)
                RPL.servoWrite(rt_wheel, 0)
                retrn()
    elif command == "right":
        direction = raw_input("> ")
        if direction == "backward":
            RPL.servoWrite(rt_wheel, forward)
            followup = raw_input("> ")
            if followup == "stop":
                RPL.servoWrite(lft_wheel, 0)
                RPL.servoWrite(rt_wheel, 0)
                retrn()
        elif direction == "forward":
            RPL.servoWrite(rt_wheel, backward)
            followup = raw_input("> ")
            if followup == "stop":
                RPL.servoWrite(lft_wheel, 0)
                RPL.servoWrite(rt_wheel, 0)
                retrn()
    elif command == "both":
        direction = raw_input("> ")
        if direction == "backward":
            RPL.servoWrite(lft_wheel, backward)
            RPL.servoWrite(rt_wheel, forward)
            followup = raw_input("> ")
            if followup == "stop":
                RPL.servoWrite(lft_wheel, 0)
                RPL.servoWrite(rt_wheel, 0)
                retrn()
        elif direction == "forward":
            RPL.servoWrite(rt_wheel, backward)
            RPL.servoWrite(lft_wheel, forward)
            followup = raw_input("> ")
            if followup == "stop":
                RPL.servoWrite(lft_wheel, 0)
                RPL.servoWrite(rt_wheel, 0)
                retrn()
    elif command == "stop":
        RPL.servoWrite(lft_wheel, 0)
        RPL.servoWrite(rt_wheel, 0)
    else:
        RPL.servoWrite(lft_wheel, 0)
        RPL.servoWrite(rt_wheel, 0)
예제 #7
0
def motorLeft():
    RPL.servoWrite(1, 000)
    RPL.servoWrite(2, 1000)
예제 #8
0
import setup
from setup import RPL
import post_to_web as PTW  # see post_to_web.py for instructions
import time
import RoboPiLib as RPL

start = time.time()

x = 1

while True:
    x = 0
    RPL.servoWrite(1, 0)
    RPL.servoWrite(2, 0)
    x = x + 12
예제 #9
0
def motorForw():
    RPL.servoWrite(1, 2000)
    RPL.servoWrite(2, 1000)
예제 #10
0
def motorstop():
    RPL.servoWrite(1, 000)
    RPL.servoWrite(2, 000)
예제 #11
0
파일: Robot2.py 프로젝트: sfrenz19/Module13
import setup
from setup import RPL
rightsensor = 23
rightmotor = 0
leftmotor = 1
while True:
    if RPL.readDistance(rightsensor) < 40000:
        RPL.servoWrite(rightmotor, 2000)
    else:
        RPL.servoWrite(rightmotor, 0)
예제 #12
0
파일: beginning.py 프로젝트: Acole19/mod13
import setup
from setup import RPL
import time
start = time.time()

x = 0
while x <= 5:
    start = time.time()
    z = 7
    while z == 7:
        current = time.time()

        if current - start < 50:
            RPL.servoWrite(1, 500)
            RPL.servoWrite(0, 2500)

        elif current - start > 50 and current - start < 100:
            RPL.servoWrite(1, 2500)
            RPL.servoWrite(0, 500)
        if current - start > 100:
            z = 9
    x += 1
    print "loop %s" % x
예제 #13
0
파일: middle.py 프로젝트: Acole19/mod13
import setup
from setup import RPL
z = 3
rear = 17
left = 1
right = 0
while z == 3
    while RPL.readDist(rear) > 70000:
        RPL.servoWrite(0,2500)
        RPL.servoWrite(1,1499)
    while RPL.readDist(rear) > 40000:
        RPL.servoWrite(0,1500)
        RPL.servoWrite(1,500)

    if RPL.readDist(rear) < 1000:
        RPL.servoWrite(0,0)
        RPL.servoWrite(1,0)
        z = 5

print "Task Complete"
예제 #14
0
	ServoL = int(raw_input(1))
	RPL.pinMode(ServoL, RPL.PWM)

  # analogRead(1) = side slant left
  # analogRead(2) = side slant right
  # analogRead(3) = front left
  # analogRead(4) = front right
  # analogRead(5) = side left
  # analogRead(6) = side right
  # analogRead(7) = front slant left
  # analogRead(8) = front slant right


while True:
    if RPL.analogRead(3) < 600 or RPL.analogRead(5) < 600:      # turns right if a wall or object on the left side is detected
        RPL.servoWrite(0, 1450)
        RPL.servoWrite(1, 2000)
    if RPL.analogRead(4) < 600 or RPL.analogRead(6) < 600:      # turns left if a wall or object on the right side is detected
        RPL.servoWrite(0, 1000)
        RPL.servoWrite(1, 1550)
    if 50 > RPL.analogRead(1) - RPL.analogRead(2) > -50:              # drives straight
        RPL.servoWrite(0, 1000)
        RPL.servoWrite(1, 2000)
    if RPL.analogRead(2) > RPL.analogRead(1) + 50:                 # turn right if sensor reads the ground
        RPL.servoWrite(0, 1450)
        RPL.servoWrite(1, 2000)
    if RPL.analogRead(1) > RPL.analogRead(2) + 50:                 # turn left if sensor reads the ground
        RPL.servoWrite(0, 1000)
        RPL.servoWrite(1, 1550)
    if RPL.analogRead(7) > 500 and RPL.analogRead(8) > 500:         # drive in reverse
        RPL.servoWrite(0, 1600)
예제 #15
0
def motorRight():
    RPL.servoWrite(1, 2000)
    RPL.servoWrite(2, 000)
예제 #16
0
import time
import setup
from setup import RPL
z = time.clock()
while True:
    y = time.clock() - z
    if y % 2 == 0:
        RPL.servoWrite(1, 2000)
        RPL.servoWrite(0, 1000)
    if y % 4 == 0:
        RPL.servoWrite(1, 0)
        RPL.servoWrite(0, 0)
RPL.servoWrite(0, 0)
RPL.servoWrite(1, 0)
예제 #17
0
def drive():
    if 1.5 > X and 1.5 > Y:
        RPL.servoWrite(0,1000)  # drive straight
        RPL.servoWrite(1,2000)
    if X < 0 and 2 > Y > 0:
        RPL.servoWrite(0,200)  # turn right
        RPL.servoWrite(1,2000)
    if 2 > X > 0 and Y < 0:
        RPL.servoWrite(0,1000)    # turn left
        RPL.servoWrite(1,200)
    if 2 > X > 1.5 and 2 > Y > 1.5:
        RPL.servoWrite(0,0)         # stop
        RPL.servoWrite(1,0)
    if X > 2 or Y > 2:
        RPL.servoWrite(0,0)    # backwards
        RPL.servoWrite(1,0)
예제 #18
0
#swag

import setup
from setup import RPL
import post_to_web as PTW

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

while True:
    PTW.state['d1'] = RPL.digitalRead(sensor_pin)
    PTW.post()

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

    if RPL.digitalRead(sensor_pin) == 0:
        import RoboPiLib as RPL
        import setup
        RPL.servoWrite(2, 0)
        RPL.servoWrite(1, 0)
예제 #19
0
import setup
from setup import RPL
import post_to_web as PTW
import time
left_sensor = 15
rear = 16
rt_wheel = 0
lft_wheel = 1
forward = 1000
backward = 2000
condit = 7
x = 0
while condit != 18:
    RPL.servoWrite(1, 2000)
    RPL.servoWrite(2, 1000)
    if RPL.readDistance(16) < 1000:
        RPL.servoWrite(2, 0)
        RPL.servoWrite(1, 0)
        condit = 18
    if x >= 10:
        z = 3
        RPL.servoWrite(1, 2000)
        RPL.servoWrite(2, 0000)
        time.sleep(.5)
        RPL.servoWrite(1, 2500)
        RPL.servoWrite(2, 1499)
        time.sleep(.5)
        RPL.servoWrite(1, 1500)
        RPL.servoWrite(2, 1499)
        while z == 3:
            if RPL.readDistance(rear) < 1000:
예제 #20
0
from setup import RPL
import RoboPiLib as RPL

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


def analogRead(pin):
    putPacket(ANREAD, bytearray([5]), 1)
    buff = getPacket()
    return int(buff[3][1]) | (int(buff[3][2]) << 8)


while True:
    if RPL.analogRead(5) > 450 and RPL.analogRead(3) > 450:
        RPL.servoWrite(2, 1490)
        RPL.servoWrite(1, 300)
        print "ok"
    if 400 > RPL.analogRead(5) and RPL.analogRead(3) > 250:
        RPL.servoWrite(2, 2000)
        RPL.servoWrite(1, 1470)
        print "yeah"
    if RPL.analogRead(5) >= 400 and RPL.analogRead(5) <= 450:
        RPL.servoWrite(2, 2000)
        RPL.servoWrite(1, 300)
        print "gratata"
    if RPL.analogRead(3) < 250:
        RPL.servoWrite(2, 2000)
        RPL.servoWrite(1, 0)
    if RPL.digitalRead(17) == 0:
        break
예제 #21
0
def sensorcont():
    back_sensor = 16
    left_sensor = 18
    rt_sensor = 17
    rt_wheel = 0
    lft_wheel = 1
    forward = 1000
    backward = 2000
    RPL.servoWrite(0, 0)
    command = raw_input("> ")
    if command == "forward":
        RPL.servoWrite(rt_wheel, backward)
        RPL.servoWrite(lft_wheel, forward)
        stop = 4
        while stop != 1:
            cease = raw_input("> ")
            if RPL.readDistance(rt_sensor) < 45000:
                RPL.servoWrite(lft_wheel, 0)
            if RPL.readDistance(rt_sensor) > 70000:
                RPL.servoWrite(lft_wheel, 1000)
                RPL.servoWrite(rt_wheel, 0)
            elif RPL.readDistance(rt_sensor) < 70000 and RPL.readDistance(
                    rt_sensor) > 45000:
                RPL.servoWrite(lft_wheel, 1000)
                RPL.servoWrite(rt_wheel, 2000)
            elif cease == "stop":
                stop = 1
        RPl.servoWrite(0, 0)
        RPL.servoWrite(1, 0)