Update
Update Code
This commit is contained in:
		
							parent
							
								
									4dd324f101
								
							
						
					
					
						commit
						f646870b12
					
				| @ -488,19 +488,19 @@ class mywindow(QMainWindow,Ui_Client): | |||||||
|     def on_btn_Mode(self,Mode): |     def on_btn_Mode(self,Mode): | ||||||
|         if Mode.text() == "M-Free": |         if Mode.text() == "M-Free": | ||||||
|             if Mode.isChecked() == True: |             if Mode.isChecked() == True: | ||||||
|                 self.timer.start(34) |                 #self.timer.start(34) | ||||||
|                 self.TCP.sendData(cmd.CMD_MODE+self.intervalChar+'one'+self.endChar) |                 self.TCP.sendData(cmd.CMD_MODE+self.intervalChar+'one'+self.endChar) | ||||||
|         if Mode.text() == "M-Light": |         if Mode.text() == "M-Light": | ||||||
|             if Mode.isChecked() == True: |             if Mode.isChecked() == True: | ||||||
|                 self.timer.stop() |                 #self.timer.stop() | ||||||
|                 self.TCP.sendData(cmd.CMD_MODE+self.intervalChar+'two'+self.endChar) |                 self.TCP.sendData(cmd.CMD_MODE+self.intervalChar+'two'+self.endChar) | ||||||
|         if Mode.text() == "M-Sonic": |         if Mode.text() == "M-Sonic": | ||||||
|             if Mode.isChecked() == True: |             if Mode.isChecked() == True: | ||||||
|                 self.timer.stop() |                 #self.timer.stop() | ||||||
|                 self.TCP.sendData(cmd.CMD_MODE+self.intervalChar+'three'+self.endChar)     |                 self.TCP.sendData(cmd.CMD_MODE+self.intervalChar+'three'+self.endChar)     | ||||||
|         if Mode.text() == "M-Line": |         if Mode.text() == "M-Line": | ||||||
|             if Mode.isChecked() == True: |             if Mode.isChecked() == True: | ||||||
|                 self.timer.stop() |                 #self.timer.stop() | ||||||
|                 self.TCP.sendData(cmd.CMD_MODE+self.intervalChar+'four'+self.endChar) |                 self.TCP.sendData(cmd.CMD_MODE+self.intervalChar+'four'+self.endChar) | ||||||
|           |           | ||||||
|                                    |                                    | ||||||
|  | |||||||
| @ -1,22 +1,23 @@ | |||||||
| import time | import time | ||||||
| from Motor import * | from Motor import * | ||||||
| import RPi.GPIO as GPIO | import RPi.GPIO as GPIO | ||||||
| IR01 = 14 |  | ||||||
| IR02 = 15 |  | ||||||
| IR03 = 23 |  | ||||||
| GPIO.setmode(GPIO.BCM) |  | ||||||
| GPIO.setup(IR01,GPIO.IN) |  | ||||||
| GPIO.setup(IR02,GPIO.IN) |  | ||||||
| GPIO.setup(IR03,GPIO.IN) |  | ||||||
| class Line_Tracking: | class Line_Tracking: | ||||||
|  |     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) | ||||||
|     def run(self): |     def run(self): | ||||||
|         while True: |         while True: | ||||||
|             self.LMR=0x00 |             self.LMR=0x00 | ||||||
|             if GPIO.input(IR01)==True: |             if GPIO.input(self.IR01)==True: | ||||||
|                 self.LMR=(self.LMR | 4) |                 self.LMR=(self.LMR | 4) | ||||||
|             if GPIO.input(IR02)==True: |             if GPIO.input(self.IR02)==True: | ||||||
|                 self.LMR=(self.LMR | 2) |                 self.LMR=(self.LMR | 2) | ||||||
|             if GPIO.input(IR03)==True: |             if GPIO.input(self.IR03)==True: | ||||||
|                 self.LMR=(self.LMR | 1) |                 self.LMR=(self.LMR | 1) | ||||||
|             if self.LMR==2: |             if self.LMR==2: | ||||||
|                 PWM.setMotorModel(800,800,800,800) |                 PWM.setMotorModel(800,800,800,800) | ||||||
| @ -29,7 +30,8 @@ class Line_Tracking: | |||||||
|             elif self.LMR==3: |             elif self.LMR==3: | ||||||
|                 PWM.setMotorModel(4000,4000,-2000,-2000) |                 PWM.setMotorModel(4000,4000,-2000,-2000) | ||||||
|             elif self.LMR==7: |             elif self.LMR==7: | ||||||
|                 pass |                 #pass | ||||||
|  |                 PWM.setMotorModel(0,0,0,0) | ||||||
|              |              | ||||||
| infrared=Line_Tracking() | infrared=Line_Tracking() | ||||||
| # Main program logic follows: | # Main program logic follows: | ||||||
| @ -37,5 +39,5 @@ if __name__ == '__main__': | |||||||
|     print ('Program is starting ... ') |     print ('Program is starting ... ') | ||||||
|     try: |     try: | ||||||
|         infrared.run() |         infrared.run() | ||||||
|     except KeyboardInterrupt:  # When 'Ctrl+C' is pressed, the child program destroy() will be  executed. |     except KeyboardInterrupt:  # When 'Ctrl+C' is pressed, the child program  will be  executed. | ||||||
|         PWM.setMotorModel(0,0,0,0) |         PWM.setMotorModel(0,0,0,0) | ||||||
|  | |||||||
| @ -3,21 +3,22 @@ from Motor import * | |||||||
| import RPi.GPIO as GPIO | import RPi.GPIO as GPIO | ||||||
| from servo import * | from servo import * | ||||||
| from PCA9685 import PCA9685 | from PCA9685 import PCA9685 | ||||||
| GPIO.setwarnings(False) |  | ||||||
| trigger_pin = 27 |  | ||||||
| echo_pin = 22 |  | ||||||
| GPIO.setmode(GPIO.BCM) |  | ||||||
| GPIO.setup(trigger_pin,GPIO.OUT) |  | ||||||
| GPIO.setup(echo_pin,GPIO.IN) |  | ||||||
| class Ultrasonic: | class Ultrasonic: | ||||||
|  |     def __init__(self): | ||||||
|  |         GPIO.setwarnings(False) | ||||||
|  |         self.trigger_pin = 27 | ||||||
|  |         self.echo_pin = 22 | ||||||
|  |         GPIO.setmode(GPIO.BCM) | ||||||
|  |         GPIO.setup(self.trigger_pin,GPIO.OUT) | ||||||
|  |         GPIO.setup(self.echo_pin,GPIO.IN) | ||||||
|     def send_trigger_pulse(self): |     def send_trigger_pulse(self): | ||||||
|         GPIO.output(trigger_pin,True) |         GPIO.output(self.trigger_pin,True) | ||||||
|         time.sleep(0.00015) |         time.sleep(0.00015) | ||||||
|         GPIO.output(trigger_pin,False) |         GPIO.output(self.trigger_pin,False) | ||||||
| 
 | 
 | ||||||
|     def wait_for_echo(self,value,timeout): |     def wait_for_echo(self,value,timeout): | ||||||
|         count = timeout |         count = timeout | ||||||
|         while GPIO.input(echo_pin) != value and count>0: |         while GPIO.input(self.echo_pin) != value and count>0: | ||||||
|             count = count-1 |             count = count-1 | ||||||
|       |       | ||||||
|     def get_distance(self): |     def get_distance(self): | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user