Skip to content

Instantly share code, notes, and snippets.

@JasonLS
Created December 5, 2017 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JasonLS/9425e5da66859727ceb2bfbefc28d2a8 to your computer and use it in GitHub Desktop.
Save JasonLS/9425e5da66859727ceb2bfbefc28d2a8 to your computer and use it in GitHub Desktop.
#48x32 31.416 inches = full rotation at
#from bbpystepper import Stepper
#find battety cord and solder cord to connect to H Bridge
# connect GND of H bridge to beaglebone
import Adafruit_BBIO.PWM as PWM
import Adafruit_BBIO.GPIO as GPIO
import Adafruit_BBIO.ADC as ADC
import time
#out1 is redwire to motor out2 is black wire to motor out3 is red to other motor
ADC.setup()
value = ADC.read("P9_40")
rawv = ADC.read_raw("P9_40")
voltage = value * 1.8 #1.8V
value2 = ADC.read("P9_36")
rawv2 = ADC.read_raw("P9_36")
voltage2 = value * 1.8 #1.8V
value3 = ADC.read("P9_38")
rawv3 = ADC.read_raw("P9_38")
voltage3 = value3 * 1.8 #1.8V
D3 = voltage3/0.00699
D2 = voltage2/0.00699
D = voltage/0.00699
# indictorpin
GPIO.setup("P8_15", GPIO.OUT)
#leftmotor
GPIO.setup("P8_11", GPIO.OUT)#in1
GPIO.setup("P8_12", GPIO.OUT)#in2
PWM.start("P8_13",0)#ena
#rightmotor
GPIO.setup("P8_15", GPIO.OUT)#in3
GPIO.setup("P8_16", GPIO.OUT)#in4
PWM.start("P8_19",0)#enb
duty = 75
#rang 100ms
GPIO.setup("P9_41", GPIO.OUT)
def HiLoUl():
while G:
GPIO.output("P9_41",GPIO.LOW)
time.sleep(1)
GPIO.output("P9_41",GPIO.HIGH)
time.sleep(1)
def forward():
GPIO.output("P8_11",GPIO.HIGH)
GPIO.output("P8_15",GPIO.HIGH)
GPIO.output("P8_12",GPIO.LOW)
GPIO.output("P8_16",GPIO.LOW)
PWM.set_duty_cycle("P8_13",duty)
PWM.set_duty_cycle("P8_19",duty)
def stop():
GPIO.output("P8_11",GPIO.HIGH)
GPIO.output("P8_15",GPIO.HIGH)
GPIO.output("P8_12",GPIO.LOW)
GPIO.output("P8_16",GPIO.LOW)
PWM.set_duty_cycle("P8_13",0)
PWM.set_duty_cycle("P8_19",0)
def back():
GPIO.output("P8_11",GPIO.LOW)
GPIO.output("P8_15",GPIO.LOW)
GPIO.output("P8_12",GPIO.HIGH)
GPIO.output("P8_16",GPIO.HIGH)
PWM.set_duty_cycle("P8_13",duty)
PWM.set_duty_cycle("P8_19",duty)
def leftforward():
GPIO.output("P8_11",GPIO.HIGH)
GPIO.output("P8_12",GPIO.LOW)
PWM.set_duty_cycle("P8_13",duty)
def leftback():
GPIO.output("P8_11",GPIO.LOW)
GPIO.output("P8_12",GPIO.HIGH)
PWM.set_duty_cycle("P8_13",duty)
def rightforward():
GPIO.output("P8_15",GPIO.HIGH)
GPIO.output("P8_16",GPIO.LOW)
PWM.set_duty_cycle("P8_19",duty)
def rightback():
GPIO.output("P8_15",GPIO.LOW)
GPIO.output("P8_16",GPIO.HIGH)
PWM.set_duty_cycle("P8_19",duty)
def PPark():
m
def scanread():
while 1:
GPIO.output("P9_41",GPIO.HIGH)
time.sleep(1)
value = ADC.read("P9_40")
rawv = ADC.read_raw("P9_40")
voltage = value * 1.8 #1.8V
D = voltage/0.00699 #.00699
#41
value2 = ADC.read("P9_36")
rawv2 = ADC.read_raw("P9_36")
voltage2 = value * 1.8 #1.8V
D2 = voltage2/0.00699
#27
value3 = ADC.read("P9_38")
rawv3 = ADC.read_raw("P9_38")
voltage3 = value3 * 1.8 #1.8V
D3 = voltage3/0.00699
#15
print(D,D3)
time.sleep(1)
GPIO.output("P9_41",GPIO.LOW)
time.sleep(1)
def ReadValue():
while 1:
forward()
GPIO.output("P9_41",GPIO.HIGH)
time.sleep(1)
value = ADC.read("P9_40")
rawv = ADC.read_raw("P9_40")
voltage = value * 1.8 #1.8V
D = voltage/0.00699 #.00699
value2 = ADC.read("P9_36")
rawv2 = ADC.read_raw("P9_36")
voltage2 = value * 1.8 #1.8V
D2 = voltage2/0.00699
value3 = ADC.read("P9_38")
rawv3 = ADC.read_raw("P9_38")
voltage3 = value3 * 1.8 #1.8V
D3 = voltage3/0.00699
GPIO.output("P9_41",GPIO.LOW)
time.sleep(1)
if D and D3 >= 25:
forward()
time.sleep(2)
stop()
time.sleep(1)
stop()
rightback()
time.sleep(2)
stop()
back()
time.sleep(2)
stop()
leftforward()
time.sleep(1)
stop()
print "Done!" #change this to turn on LED or buzzer
break
while 1:
value = ADC.read("P9_40")
rawv = ADC.read_raw("P9_40")
voltage = value * 1.8 #1.8V
D = voltage/0.00699 #.00699
value2 = ADC.read("P9_36")
rawv2 = ADC.read_raw("P9_36")
voltage2 = value2 * 1.8 #1.8V
D2 = voltage2/0.00699 #.00699
value3 = ADC.read("P9_38")
rawv3 = ADC.read_raw("P9_38")
voltage3 = value3 * 1.8 #1.8V
D3 = voltage3/0.00699 #.00699
answer = raw_input("what would you like to do:")
if answer =='park':
forward()
if D2 <=33: #foward until distance ping for ultrasonic Evan Edit- Why was it less than, now greater than Also value should equal width of car in inches
stop()
elif answer == 'stop':
print "Ok!"
PWM.stop("P8_13")
PWM.stop("P8_19")
PWM.cleanup()
GPIO.output("P8_11", GPIO.LOW)
GPIO.output("P8_12", GPIO.LOW)
GPIO.output("P8_15", GPIO.LOW)
GPIO.output("P8_16", GPIO.LOW)
GPIO.output("P9_41",GPIO.LOW)
GPIO.cleanup()
break
elif answer == 'test':
forward()
if D and D3 >= 30:
stop()
elif answer == 'test2':
forward()
time.sleep(2)
stop()
time.sleep(.1)
forward()
time.sleep(.25)#time to travel one car lenght(seconds)
stop()
rightback()
time.sleep(.25)#time until 45 degree turn
stop()
elif answer == 'test3':
ReadValue()
elif answer == 'scan':
scanread()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment