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!")
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!")
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)
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)
import setup from setup import RPL import RoboPiLib as RoboPi RoboPi.RoboPiInit(“/dev/ttyAMA0”,115200) RoboPi.pinMode(1,RoboPi.OUTPUT) RoboPi.digitalWrite(16,1) RoboPi.pinMode(17,RoboPi.PWM) RoboPi.analogWrite(17,127) print RoboPi.analogRead(0) #RPL.servoWrite(0,1000) #RPL.servoWrite(1,1000) #x = 1 #while x == 1: # RoboPi.analogRead(1) # AnalogRead = RoboPi.analogRead(1) # AnalogRead = int(AnalogRead) # print AnalogRead # Dist = (500 * AnalogRead)/1024 # print Dist #import RoboPiLib as RoboPi
import RoboPiLib as RPL import setup x = 1 L = 1 R = 2 LS = 2 RS = 1 RPL.pinMode(LS, RPL.INPUT) RPL.pinMode(RS, RPL.INPUT) def left(): if readingL == 0: RPL.servoWrite(L, 1410) elif readingL == 1: 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():
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()
# python web2py.py -c server.crt -k server.key -a 'Engineering1!' -i 0.0.0.0 -p 8000 # Kirwin's vi tab preferences: set shiftwidth=2 softtabstop=2 expandtab import xml.etree.ElementTree as ET import RoboPiLib as RPL RPL.RoboPiInit("/dev/ttyAMA0", 115200) ###################### ## Motor Establishment ###################### freq = 3000 motorL = 0 RPL.pinMode(motorL, RPL.PWM) RPL.pwmWrite(motorL, 1500, freq) motorR = 1 RPL.pinMode(motorR, RPL.PWM) RPL.pwmWrite(motorR, 1500, freq) def read_parameters_as_xml(): parser = ET.ElementTree() # use .get('param') return parser.parse('command_parameters.txt') ################ ## Web Functions ################ def dashboard():
motorL = 0 motorR = 1 motorR_forward = 2000 motorR_backward = 1000 motorL_forward = 1000 motorL_backward = 2000 global mem mem = [["start",0]] global start start = time.time() try: RPL.pinMode(motorL,RPL.SERVO) RPL.servoWrite(motorL,1500) RPL.pinMode(motorR,RPL.SERVO) RPL.servoWrite(motorR,1500) except: pass ###################### ## Individual commands ###################### def stopAll(): try: RPL.servoWrite(motorL,1500) RPL.servoWrite(motorR,1500) except: print "error except"
## Motor Establishment ###################### freq = 3000 motorL = 0 motorR = 1 servo1 = 8 # Wrist Pitch servo2 = 9 # Wrist Roll servo3 = 10 # Grabber elbow_dir = 3 elbow_pulse = 5 shoulder_dir = 6 shoulder_pulse = 7 try: RPL.pinMode(motorL, RPL.PWM) RPL.pwmWrite(motorL, 1500, freq) RPL.pinMode(motorR, RPL.PWM) RPL.pwmWrite(motorR, 1500, freq) RPL.pinMode(servo1, RPL.SERVO) RPL.pinMode(servo2, RPL.SERVO) RPL.pinMode(servo3, RPL.SERVO) RPL.pinMode(elbow_dir, RPL.OUTPUT) RPL.pinMode(elbow_pulse, RPL.PWM) RPL.pwmWrite(elbow_pulse, 0, 1000) RPL.pinMode(shoulder_dir, RPL.OUTPUT) RPL.pinMode(shoulder_pulse, RPL.PWM) RPL.pwmWrite(shoulder_pulse, 0, 1000) except: pass
import RoboPiLib as RPL RPL.RoboPiInit("/dev/ttyAMA0", 115200) import sys import time sensor_pin_1 = 16 sensor_pin_2 = 17 RPL.pinMode(sensor_pin_1, RPL.INPUT) RPL.pinMode(sensor_pin_2, RPL.INPUT) ticks = 100000 ticksDone = 0 mtrLeft = [0, -1] mtrRight = [1, 1] outputLog = ["---"] def clearText(): print("\033c") def allStop(): RPL.servoWrite(0, 1500) RPL.servoWrite(1, 1500) RPL.servoWrite(0, 0) RPL.servoWrite(1, 0)
import RoboPiLib as RPL import sys, tty, termios, signal, setup, time from cytron import Cytron motor_controller = Cytron(max_pwm=20000, percent_power=10, m1_pwm=0, m1_dir=1) motor = motor_controller.m1 RPL.pinMode(motor_controller.m1["pwm"], RPL.PWM) RPL.pinMode(motor_controller.m1["dir"], RPL.OUTPUT) steering_pin = 3 pwm_percent = 50 print("initialized Motor Speed at {}/{} : {}%".format( (motor_controller.max_freq * pwm_percent) / 100, motor_controller.max_freq, pwm_percent)) fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) def interrupted(signum, frame): stop() def stop(): motor_controller.stop() RPL.servoWrite(steering_pin, 1500) def right(percent): RPL.servoWrite(steering_pin, 5 * percent + 1500)
import RoboPiLib as RPL import setup import time from time import sleep sensor_pinF = 0 sensor_pinL = 2 sensor_pinR = 3 RPL.pinMode(sensor_pinF, RPL.INPUT) RPL.pinMode(sensor_pinL, RPL.INPUT) RPL.pinMode(sensor_pinR, RPL.INPUT) R = 1 L = 0 values = [] for i in range(0,100): values.append(RPL.analogRead(sensor_pinF)) print(sum(values) / 100)
FmotorL = 0 FmotorR = 1 BmotorL = 2 BmotorR = 3 FmotorR_forward = 2000 FmotorR_backward = 1000 FmotorL_forward = 1000 FmotorL_backward = 2000 BmotorR_forward = 2000 BmotorR_backward = 1000 BmotorL_forward = 1000 BmotorL_backward = 2000 try: RPL.pinMode(FmotorL, RPL.SERVO) RPL.servoWrite(FmotorL, 1500) RPL.pinMode(FmotorR, RPL.SERVO) RPL.servoWrite(FmotorR, 1500) RPL.pinMode(BmotorL, RPL.SERVO) RPL.servoWrite(BmotorL, 1500) RPL.pinMode(BmotorR, RPL.SERVO) RPL.servoWrite(BmotorR, 1500) except: pass ###################### ## Individual commands ###################### def stopAll():
import RoboPiLib as RPL import wall_evasion RPL.pinMode(16,RPL.INPUT) RPL.pinMode(17,RPL.INPUT) while True: approach_and_turn16() approach_and_turn17()
import RoboPiLib as RPL import setup import sys, tty, termios, signal motor = 7 r_turn = 1000 l_turn = 2000 try: RPL.pinMode(motor,RPL.SERVO) RPL.servoWrite(motor,0) except: pass def stopAll(): try: RPL.servoWrite(motor,0) except: print "error except" pass def right(): RPL.servoWrite(motor,r_turn) def left(): RPL.servoWrite(motor,l_turn) fd = sys.stdin.fileno() # I don't know what this does old_settings = termios.tcgetattr(fd) # this records the existing console settings that are later changed with the tty.setraw... line so that they can be replaced when the loop ends
def DT_PWM_Speedrange(): ServoR = int(raw_input(0)) RPL.pinMode(ServoR, RPL.PWM) ServoL = int(raw_input(1)) RPL.pinMode(ServoL, RPL.PWM)
#!/usr/bin/python import RoboPiLib as RoboPi import time as time INPUT = RoboPi.INPUT LEFT_BUMPER = 22 RIGHT_BUMPER = 23 PRESSED = 0 RoboPi.RoboPiInit("/dev/ttyAMA0", 115200) RoboPi.pinMode(LEFT_BUMPER, INPUT) RoboPi.pinMode(RIGHT_BUMPER, INPUT) while 1: if (RoboPi.digitalRead(LEFT_BUMPER) == PRESSED): print "Left Bumper Pressed" if (RoboPi.digitalRead(RIGHT_BUMPER) == PRESSED): print "Right Bumper Pressed" time.sleep(0.1) RoboPi.RoboPiExit()
OUTPUT = RoboPi.OUTPUT PWM = RoboPi.PWM SERVO = RoboPi.SERVO MOTORA_IA = 12 MOTORA_IB = 13 MOTORB_IA = 14 MOTORB_IB = 15 RoboPi.RoboPiInit("/dev/ttyAMA0", 115200) while 1: # set both motors to go forward RoboPi.pinMode(MOTORA_IA, PWM) RoboPi.pinMode(MOTORA_IB, OUTPUT) RoboPi.pinMode(MOTORB_IA, PWM) RoboPi.pinMode(MOTORB_IB, OUTPUT) # slowly ramp up the sped for speed in xrange(0, 256, 2): RoboPi.analogWrite(MOTORA_IA, speed) RoboPi.analogWrite(MOTORB_IA, speed) time.sleep(0.1) # now ramp back town for speed in xrange(255, -1, -2):
import RoboPiLib as RoboPi import time as time RoboPi.RoboPiInit("/dev/ttyAMA0", 115200) #AMA0 has a zero servo = RoboPi.SERVO left_servo = 1 right_servo = 2 up_servo = 3 down_servo = 4 RoboPi.pinMode (left_servo, servo) RoboPi.pinMode (right_servo, servo) RoboPi.pinMode (up_servo, servo) RoboPi.pinMode (down_servo, servo) #stop = 0 #clockwise = 500 #counter_clockwise = 2500 def go_forward(): RoboPi.servoWrite(left_servo, 500) RoboPi.servoWrite(right_servo, 2500) RoboPi.servoWrite(up_servo, 2500) RoboPi.servoWrite(down_servo, 500) def go_backward(): RoboPi.servoWrite(left_servo, 2500) RoboPi.servoWrite(right_servo, 500) RoboPi.servoWrite(up_servo, 500)