2019-09-24 21:09:34 -04:00
|
|
|
import time
|
|
|
|
from Motor import *
|
|
|
|
import RPi.GPIO as GPIO
|
|
|
|
class Line_Tracking:
|
2020-07-07 20:24:44 -04:00
|
|
|
def __init__(self):
|
|
|
|
self.IR01 = 14
|
|
|
|
self.IR02 = 15
|
|
|
|
self.IR03 = 23
|
|
|
|
GPIO.setmode(GPIO.BCM)
|
|
|
|
GPIO.setup(self.IR01,GPIO.IN)
|
|
|
|
GPIO.setup(self.IR02,GPIO.IN)
|
|
|
|
GPIO.setup(self.IR03,GPIO.IN)
|
2019-09-24 21:09:34 -04:00
|
|
|
def run(self):
|
|
|
|
while True:
|
|
|
|
self.LMR=0x00
|
2020-07-07 20:24:44 -04:00
|
|
|
if GPIO.input(self.IR01)==True:
|
2019-09-24 21:09:34 -04:00
|
|
|
self.LMR=(self.LMR | 4)
|
2020-07-07 20:24:44 -04:00
|
|
|
if GPIO.input(self.IR02)==True:
|
2019-09-24 21:09:34 -04:00
|
|
|
self.LMR=(self.LMR | 2)
|
2020-07-07 20:24:44 -04:00
|
|
|
if GPIO.input(self.IR03)==True:
|
2019-09-24 21:09:34 -04:00
|
|
|
self.LMR=(self.LMR | 1)
|
|
|
|
if self.LMR==2:
|
|
|
|
PWM.setMotorModel(800,800,800,800)
|
|
|
|
elif self.LMR==4:
|
2019-10-15 21:33:44 -04:00
|
|
|
PWM.setMotorModel(-1500,-1500,2500,2500)
|
2019-09-24 21:09:34 -04:00
|
|
|
elif self.LMR==6:
|
2019-10-15 21:33:44 -04:00
|
|
|
PWM.setMotorModel(-2000,-2000,4000,4000)
|
2019-09-24 21:09:34 -04:00
|
|
|
elif self.LMR==1:
|
2019-10-15 21:33:44 -04:00
|
|
|
PWM.setMotorModel(2500,2500,-1500,-1500)
|
2019-09-24 21:09:34 -04:00
|
|
|
elif self.LMR==3:
|
2019-10-15 21:33:44 -04:00
|
|
|
PWM.setMotorModel(4000,4000,-2000,-2000)
|
2019-09-24 21:09:34 -04:00
|
|
|
elif self.LMR==7:
|
2020-07-07 20:24:44 -04:00
|
|
|
#pass
|
|
|
|
PWM.setMotorModel(0,0,0,0)
|
2019-09-24 21:09:34 -04:00
|
|
|
|
|
|
|
infrared=Line_Tracking()
|
|
|
|
# Main program logic follows:
|
|
|
|
if __name__ == '__main__':
|
|
|
|
print ('Program is starting ... ')
|
|
|
|
try:
|
|
|
|
infrared.run()
|
2020-07-07 20:24:44 -04:00
|
|
|
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program will be executed.
|
2019-09-24 21:09:34 -04:00
|
|
|
PWM.setMotorModel(0,0,0,0)
|