migrate to 2 rpi board
This commit is contained in:
		
							parent
							
								
									f7014f5fef
								
							
						
					
					
						commit
						f68e037537
					
				
					 4 changed files with 37 additions and 8 deletions
				
			
		
							
								
								
									
										5
									
								
								app.py
									
										
									
									
									
								
							
							
						
						
									
										5
									
								
								app.py
									
										
									
									
									
								
							|  | @ -8,14 +8,15 @@ import kuukar.kuukar_sensors as kuukar_sensors | |||
| import kuukar.kuukar_environment as kuukar_environment | ||||
| from flask import Flask, request | ||||
| 
 | ||||
| from kuukar.kuukar_config import SERIAL_MCU | ||||
| from kuukar.kuukar_config import SERIAL_MCU, SERIAL_DRV | ||||
| 
 | ||||
| app = Flask(__name__) | ||||
| 
 | ||||
| mcu = telemetrix_rpi_pico.TelemetrixRpiPico(com_port=SERIAL_MCU) | ||||
| drv = telemetrix_rpi_pico.TelemetrixRpiPico(com_port=SERIAL_DRV) | ||||
| sensors = kuukar_sensors.sensors(mcu) | ||||
| leds = kuukar_leds.leds(mcu) | ||||
| motion = kuukar_motion.motion(mcu, leds, sensors) | ||||
| motion = kuukar_motion.motion(mcu, drv, leds, sensors) | ||||
| lcd = kuukar_lcd.lcd(motion, sensors) | ||||
| environment = kuukar_environment.environment(lcd, leds, sensors) | ||||
| collision = kuukar_collision.collision(mcu, lcd, leds) | ||||
|  |  | |||
|  | @ -1,4 +1,5 @@ | |||
| SERIAL_MCU = "COM4" | ||||
| SERIAL_DRV = "COM20" | ||||
| 
 | ||||
| # HC Sonar Pins | ||||
| SONAR_1_TRIG_PIN = 0 | ||||
|  |  | |||
|  | @ -11,8 +11,9 @@ class motion: | |||
| 
 | ||||
|     roaming = False | ||||
| 
 | ||||
|     def __init__(self, mcu: telemetrix_rpi_pico.TelemetrixRpiPico, leds: leds, sensors: sensors) -> None: | ||||
|     def __init__(self, mcu: telemetrix_rpi_pico.TelemetrixRpiPico, drv: telemetrix_rpi_pico.TelemetrixRpiPico, leds: leds, sensors: sensors) -> None: | ||||
|         self.mcu = mcu | ||||
|         self.drv = drv | ||||
|         self.leds = leds | ||||
|         self.sensors = sensors | ||||
|         self.roam_thread = threading.Thread(target=self.__roam_looper) | ||||
|  | @ -21,15 +22,15 @@ class motion: | |||
|         drive_pins = [MOTOR_FL_F, MOTOR_FL_R, MOTOR_FR_F, | ||||
|                       MOTOR_FR_R, MOTOR_RL_F, MOTOR_RL_R, MOTOR_RR_F, MOTOR_RR_R] | ||||
|         for drive_pin in drive_pins: | ||||
|             self.mcu.set_pin_mode_pwm_output(drive_pin) | ||||
|             self.drv.set_pin_mode_pwm_output(drive_pin) | ||||
| 
 | ||||
|     def motor_write(self, forward_pin: int, reverse_pin: int, speed: int): | ||||
|         if speed < 0: | ||||
|             self.mcu.pwm_write(forward_pin, 0) | ||||
|             self.mcu.pwm_write(reverse_pin, -speed) | ||||
|             self.drv.pwm_write(forward_pin, 0) | ||||
|             self.drv.pwm_write(reverse_pin, -speed) | ||||
|         elif speed >= 0: | ||||
|             self.mcu.pwm_write(forward_pin, speed) | ||||
|             self.mcu.pwm_write(reverse_pin, 0) | ||||
|             self.drv.pwm_write(forward_pin, speed) | ||||
|             self.drv.pwm_write(reverse_pin, 0) | ||||
| 
 | ||||
|     def drive(self, speed: int): | ||||
|         self.motor_write(MOTOR_FL_F, MOTOR_FL_R, speed) | ||||
|  |  | |||
							
								
								
									
										26
									
								
								pure_test.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								pure_test.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,26 @@ | |||
| from telemetrix_rpi_pico import telemetrix_rpi_pico | ||||
| import time | ||||
| import kuukar.kuukar_config as config | ||||
| 
 | ||||
| global mcu,drv,distance | ||||
| mcu = telemetrix_rpi_pico.TelemetrixRpiPico("COM4") | ||||
| drv = telemetrix_rpi_pico.TelemetrixRpiPico("COM20") | ||||
| 
 | ||||
| distance = 0 | ||||
| drv.set_pin_mode_pwm_output(config.MOTOR_RR_F) | ||||
| drv.pwm_write(config.MOTOR_RR_F,30) | ||||
| 
 | ||||
| def sonarcallback(data): | ||||
|     global mcu,drv,distance | ||||
|     pin = data[1] | ||||
|     distance = data[2] | ||||
|          | ||||
| mcu.set_pin_mode_sonar(config.SONAR_2_TRIG_PIN,config.SONAR_2_ECHO_PIN, sonarcallback) | ||||
| 
 | ||||
| while True: | ||||
|     print(distance) | ||||
|     if distance < 20.0 and distance != 0: | ||||
|         drv.pwm_write(config.MOTOR_RR_F,0) | ||||
|         print("STOP") | ||||
|         time.sleep(1) | ||||
|         drv.pwm_write(config.MOTOR_RR_F,30) | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue