Compare commits
	
		
			2 Commits
		
	
	
		
			576f9ee94e
			...
			master
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | d943874797 | ||
|  | f99eaacfec | 
							
								
								
									
										23
									
								
								limits.py
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								limits.py
									
									
									
									
									
								
							| @@ -2,21 +2,30 @@ import time | |||||||
| import sys | import sys | ||||||
| import RPi.GPIO as GPIO | import RPi.GPIO as GPIO | ||||||
|  |  | ||||||
|  |  | ||||||
|  | PATH_OPEN = 0 | ||||||
|  | PATH_BLOCKED = 1 | ||||||
|  | LIMIT_LOWER_RIGHT = 19 | ||||||
|  | LIMIT_LOWER_LEFT = 20 | ||||||
|  | LIMIT_UPPER_RIGHT = 21 | ||||||
|  |  | ||||||
|  |  | ||||||
| GPIO.setmode(GPIO.BCM) | GPIO.setmode(GPIO.BCM) | ||||||
|  |  | ||||||
| GPIO.setup(19, GPIO.IN, pull_up_down=GPIO.PUD_UP) | GPIO.setup(LIMIT_LOWER_RIGHT, GPIO.IN, pull_up_down=GPIO.PUD_UP) | ||||||
| GPIO.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_UP) | GPIO.setup(LIMIT_LOWER_LEFT, GPIO.IN, pull_up_down=GPIO.PUD_UP) | ||||||
| GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP) | GPIO.setup(LIMIT_UPPER_RIGHT, GPIO.IN, pull_up_down=GPIO.PUD_UP) | ||||||
|  |  | ||||||
| # 1 = optical path blocked, 0 = open |  | ||||||
|  | # True = optical path blocked, False = open | ||||||
|  |  | ||||||
| def test(): | def test(): | ||||||
|     while True: |     while True: | ||||||
|         try: |         try: | ||||||
|             print( |             print( | ||||||
|                 'GPIO19:', GPIO.input(19), |                 'Lower Right (GPIO19):', GPIO.input(LIMIT_LOWER_RIGHT) == PATH_BLOCKED, | ||||||
|                 'GPIO20:', GPIO.input(20), |                 '| Lower Left (GPIO20):', GPIO.input(LIMIT_LOWER_LEFT) == PATH_BLOCKED, | ||||||
|                 'GPIO21:', GPIO.input(21), |                 '| Upper Right (GPIO21):', GPIO.input(LIMIT_UPPER_RIGHT) == PATH_BLOCKED, | ||||||
|             ) |             ) | ||||||
|  |  | ||||||
|             time.sleep(1) |             time.sleep(1) | ||||||
|   | |||||||
							
								
								
									
										30
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								main.py
									
									
									
									
									
								
							| @@ -12,9 +12,11 @@ import aiomqtt | |||||||
| import serial | import serial | ||||||
| import glob | import glob | ||||||
| import time | import time | ||||||
|  | import RPi.GPIO as GPIO | ||||||
|  |  | ||||||
| import dyn4 | import dyn4 | ||||||
| import relays | import relays | ||||||
|  | import limits | ||||||
|  |  | ||||||
| ENCODER_PPR = 65536 | ENCODER_PPR = 65536 | ||||||
|  |  | ||||||
| @@ -24,6 +26,13 @@ dmm1 = None | |||||||
| dmm2 = None | dmm2 = None | ||||||
|  |  | ||||||
|  |  | ||||||
|  | # 2025-10-24 facts: | ||||||
|  | #    Motor1 is left | ||||||
|  | #    Motor2 is right | ||||||
|  | #    Positive RPM moves the crosshead down | ||||||
|  | #    Negative RPM moves the crosshead up | ||||||
|  |  | ||||||
|  |  | ||||||
| MOTOR_EN1 = 1 | MOTOR_EN1 = 1 | ||||||
| MOTOR_EN2 = 2 | MOTOR_EN2 = 2 | ||||||
| DISABLED = None | DISABLED = None | ||||||
| @@ -257,6 +266,27 @@ async def monitor_dyn4(): | |||||||
|                 logging.info('Pos difference: %s, rev1: %s, rev2: %s, scaler1: %s, scaler2: %s, target: %s, rpm1: %s, rpm2: %s', |                 logging.info('Pos difference: %s, rev1: %s, rev2: %s, scaler1: %s, scaler2: %s, target: %s, rpm1: %s, rpm2: %s', | ||||||
|                     difference, rev1, rev2, motor1_scaler, motor2_scaler, RPM_TARGET, motor1_rpm, motor2_rpm) |                     difference, rev1, rev2, motor1_scaler, motor2_scaler, RPM_TARGET, motor1_rpm, motor2_rpm) | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         # check limit switches | ||||||
|  |         if ONE_MOTOR: | ||||||
|  |             pass | ||||||
|  |         else: | ||||||
|  |             GOING_DOWNWARD = motor1_rpm > 0 or motor2_rpm > 0 | ||||||
|  |             GOING_UPWARD = motor1_rpm < 0 or motor2_rpm < 0 | ||||||
|  |  | ||||||
|  |             if GOING_DOWNWARD: | ||||||
|  |                 if GPIO.input(limits.LIMIT_LOWER_RIGHT) == limits.PATH_BLOCKED or GPIO.input(limits.LIMIT_LOWER_LEFT) == limits.PATH_BLOCKED: | ||||||
|  |                     motor1_rpm = 0 | ||||||
|  |                     motor2_rpm = 0 | ||||||
|  |                     logging.info('Lower limit switch hit, preventing downward travel.') | ||||||
|  |  | ||||||
|  |             if GOING_UPWARD: | ||||||
|  |                 if GPIO.input(limits.LIMIT_UPPER_RIGHT) == limits.PATH_BLOCKED: | ||||||
|  |                     motor1_rpm = 0 | ||||||
|  |                     motor2_rpm = 0 | ||||||
|  |                     logging.info('Upper limit switch hit, preventing upward travel.') | ||||||
|  |  | ||||||
|  |  | ||||||
|         if ONE_MOTOR: |         if ONE_MOTOR: | ||||||
|             logging.debug('Setting motor1: %s', motor1_rpm) |             logging.debug('Setting motor1: %s', motor1_rpm) | ||||||
|             dmm1.set_speed(motor1_rpm) |             dmm1.set_speed(motor1_rpm) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user