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)
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)
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
# 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)
import setup 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) import RPL RPL.init() import time f_reverse = 1000 neutral = 1500 f_forward = 2000 #anglepersecond = 30 def DT_PWM_Speedrange(): ServoR = int(raw_input(0)) RPL.pinMode(ServoR, RPL.PWM) 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
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)
def motorRight(): RPL.servoWrite(1, 2000) RPL.servoWrite(2, 000) back_sensor = 16 rt_wheel = 0 lft_wheel = 1 forward = 1000 backward = 2000 condit = 7 x = 0 while condit != 16: motorForw() if RPL.readDistance(17) < 1000: condit = 16 if Distance() > 50000: motorLeft() time.sleep(.5) elif Distance() < 10000: motorRight() time.sleep(.5) else: x += 1 motorForw() motorstop() print x #prints the total number of times a sycle went with a Distance value imbetween 50000 and 10000
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 = 4 while True: elaptime = (time.time() - start) x = 0 elaptime = int(elaptime) if elaptime % 6 == 0: RPL.servoWrite(1, 0) RPL.servoWrite(2, 0) x = x + 12 if elaptime % 12 == 0: RPL.servoWrite(1, 500) RPL.servoWrite(2, 2000) x = x + 6
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
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)
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: if RPL.digitalRead(sensor_pin) == 1: import RoboPiLib as RPL import setup RPL.servoWrite(0, 1000) RPL.servoWrite(1, 2000) if RPL.digitalRead(sensor_pin) == 0: import RoboPiLib as RPL import setup RPL.servoWrite(0, 1450) RPL.servoWrite(1, 1550) x = 0 while x == 0: import time import setup from setup import RPL import RoboPiLib as RPL start = time.time() while True: elapsed = time.time() - start y = 1
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(1,2000) if RPL.digitalread(sensor_pin) == 0 import RoboPiLib as RPL import setup RPL.servowrite(0,1) RPL.servowrite(0,0)
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"
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:
def motorForw(): RPL.servoWrite(1, 2000) RPL.servoWrite(2, 1000)
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
def motorstop(): RPL.servoWrite(1, 000) RPL.servoWrite(2, 000)
def testing(): RPL.servoWrite(0,2000) RPL.servoWrite(1,1000) time.sleep()
def motorLeft(): RPL.servoWrite(1, 000) RPL.servoWrite(2, 1000)
def DT_PWM_Speedrange(): ServoR = int(raw_input(0)) RPL.pinMode(ServoR, RPL.PWM) ServoL = int(raw_input(1)) RPL.pinMode(ServoL, RPL.PWM)
def motorRight(): RPL.servoWrite(1, 2000) RPL.servoWrite(2, 000)
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) if RPL.digitalRead(sensor_pin) == 0: import RoboPiLib as RPL import setup RPL.servoWrite(0,0) RPL.servoWrite(1,0) x = 0 while x == 0: import time import setup from setup import RPL import RoboPiLib as RPL start = time.time() while True: elapsed = time.time() - start y = 1 if int(elapsed) != 0: y = 2 while int(elapsed) % 2 == 0: RPL.servoWrite(2,2000) RPL.servoWrite(1,500)
def Distance(): return RPL.readDistance(16)
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()
import setup from setup import RPL import RoboPiLib as RPL sensor_pin = 5 RPL.pinMode(sensor_pin,RPL.INPUT) from marvelmind import MarvelmindHedge from time import sleep import sys def main(): hedge = MarvelmindHedge(tty = "/dev/ttyACM0", adr=None, debug=False) # create MarvelmindHedge thread hedge.start() # start thread while True: try: sleep(1) # print (hedge.position()) # get last position and print hedge.print_position() if (hedge.distancesUpdated): hedge.print_distances() except KeyboardInterrupt: hedge.stop() # stop and close serial port sys.exit() 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)
import setup 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:
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)