class GPIO(): def __init__(self): pass def __enter__(self): self.GP = GPIOProcessor() self.forward_pin = self.GP.getPin25() self.forward_pin.out() self.right_high = self.GP.getPin26() self.right_high.out() self.right_low = self.GP.getPin27() self.right_low.out() self.left_high = self.GP.getPin29() self.left_high.out() self.left_low = self.GP.getPin30() self.left_low.out() return self def __exit__(self, exc_type, exc_val, exc_tb): self.GP.cleanup() def brake(self): self.forward_pin.low() def unbrake(self): self.forward_pin.high() def turn_left(self): self.left_low.low() self.left_high.high() def turn_right(self): self.right_low.low() self.right_high.high()
class DC: def __init__(self): """ DC maps DragonBoard 410c GPIO pins for Debian to the L293N H-Bridge I/C, ready to receive control messages from Manager.py. Green wire : Pin 23 -> OpAmp Node 1 -> L298N h-bridge Input 2 White wire : Pin 24 -> OpAmp Node 4 -> L298N h-bridge Enable A Yellow wire : Pin 26 -> OpAmp Node 3 -> L298N h-bridge Input 1 Set Input 2 to Low, Input 1 to High for clockwise spin. """ self.gp = GPIOProcessor() # h-bridge self.green = self.gp.getPin23() self.white = self.gp.getPin24() self.yellow = self.gp.getPin26() self.green.out() self.white.out() self.yellow.out() # clockwise self.green.low() # Input 2 self.yellow.high() # Input 1 self.isPropSpinning = False def start_motor(self): """ Set Enable A to High to start motor. :rtype: Boolean :return: True if motor started, False if failed. """ try: self.white.low() self.white.high() self.isPropSpinning = True return True except KeyboardInterrupt(): print "Keyboard interrupt received. Cleaning up ..." self.gp.cleanup() return False def stop_motor(self): """ Set Enable A to Low to stop motor. :rtype: Boolean :return: True if motor stopped, False if failed. """ try: self.white.low() self.isPropSpinning = False return True except KeyboardInterrupt(): print "Keyboard interrupt received. Cleaning up ..." self.gp.cleanup()
try: steps_made = 0 pins = [ GP.getPin31(), GP.getPin32(), GP.getPin33(), GP.getPin34(), ] for p in pins: p.out() right = GP.getPin27() right.input() left = GP.getPin26() left.input() reset = GP.getPin24() reset.input() sequence = FULL_STEP_SEQUENCE i = 0 direction = 0 resetting = False while True: time.sleep(DELAY) for p in pins: p.low()
from GPIOLibrary import GPIOProcessor import time import math GP = GPIOProcessor() try: # Stepper Motor Controls A1 = GP.getPin34() # Green A2 = GP.getPin24() # Black B1 = GP.getPin33() # White B2 = GP.getPin26() # Yellow A1.out() A2.out() B1.out() B2.out() # Delay time T = 0.001 # Stepper Sequence (Forward ; Reverse) SS = [[[0,1,0,1],[1,0,0,1],[1,0,1,0],[0,1,1,0]], [[0,1,0,1],[0,1,1,0],[1,0,1,0],[1,0,0,1]]] # Forward/Reverse Indicator (0 - Forward, 1 - Reverse) FR = 0 # Step Angle SA = 1.8 # 1.8 degrees per step
from GPIOLibrary import GPIOProcessor import time import math GP = GPIOProcessor() try: # Stepper Motor Controls A1 = GP.getPin34() # Green A2 = GP.getPin24() # Black B1 = GP.getPin33() # White B2 = GP.getPin26() # Yellow A1.out() A2.out() B1.out() B2.out() # Delay time T = 0.001 # Stepper Sequence (Forward ; Reverse) SS = [[[0, 1, 0, 1], [1, 0, 0, 1], [1, 0, 1, 0], [0, 1, 1, 0]], [[0, 1, 0, 1], [0, 1, 1, 0], [1, 0, 1, 0], [1, 0, 0, 1]]] # Forward/Reverse Indicator (0 - Forward, 1 - Reverse) FR = 0 # Step Angle SA = 1.8 # 1.8 degrees per step
# GPIO assignment # TRIG Pin 23 # ECHO Pin 27 # GREEN Pin 24 # YELLOW Pin 25 # RED Pin 26 try: # Create GPIO variables trig = GP.getPin34() echo = GP.getPin27() green = GP.getPin24() yellow = GP.getPin25() red = GP.getPin26() trig.out() echo.input() green.out() yellow.out() red.out() # Duration of Activation (seconds) D = 10 # Approximate Speed of Sound (cm/s) speed = 34029 print "Begin" timeout = time.time() + D
MAGIC = "face600d" server_socket = socket.socket() server_host = '192.168.43.20' server_port = 5002 server_socket.bind((server_host, server_port)) server_socket.listen(5) c,addr = server_socket.accept() try: # Stepper Motor Controls A1 = GP.getPin23() # blue A2 = GP.getPin24() # pink B1 = GP.getPin25() # yellow B2 = GP.getPin26() # orange A1.out() A2.out() B1.out() B2.out() # Delay time T = 0.001 # Stepper Sequence (Forward ; Reverse) SS = [[[1,1,0,0],[0,1,1,0],[0,0,1,1],[1,0,0,1]], [[1,0,0,1],[0,0,1,1],[0,1,1,0],[1,1,0,0]]] # Step Angle SA = 0.18 #degrees per step
# GPIO assignment # TRIG Pin 23 # ECHO Pin 27 # GREEN Pin 24 # YELLOW Pin 25 # RED Pin 26 try: # Create GPIO variables trig = GP.getPin34() echo = GP.getPin27() green = GP.getPin24() yellow = GP.getPin25() red = GP.getPin26() trig.out() echo.input() green.out() yellow.out() red.out() # Duration of Activation (seconds) D = 10 # Approximate Speed of Sound (cm/s) speed = 34029 print "Begin" timeout=time.time()+D
#A1 = 34 Green #A2 = 33 White #A3 = 24 Black #A4 = 26 Yellow #PIR = 29 #Ind = 30 Din = GP.getPin27() Din.input() A1 = GP.getPin34() A1.out() A2 = GP.getPin33() A2.out() A3 = GP.getPin24() A3.out() A4 = GP.getPin26() A4.out() PIR = GP.getPin29() PIR.out() PIR.low() Ind = GP.getPin30() Ind.out() Ind.low() # Remote Average Pulse M = 800 # Stepper Motor Delay t = 0.001 # Stepper Motor Sequence (Forward / Reverse)