Update pin config and fix the distance measure logic#4
Conversation
bf36f3d to
7eee2c5
Compare
There was a problem hiding this comment.
Pull Request Overview
Switch GPIO numbering to BOARD mode and update pin constants accordingly; adjust the ultrasonic distance measurement logic with new timeout handling.
- Switch RPi GPIO mode from BCM to BOARD.
- Update pin constants to BOARD physical pin numbers.
- Refactor readDistance timing loops and timeouts.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| Scripts/PinDescription.py | Updates pin constants to BOARD numbering to match new GPIO mode. |
| Scripts/GpioManager.py | Changes GPIO mode to GPIO.BOARD when running on a Raspberry Pi. |
| Scripts/Main.py | Refactors ultrasonic echo timing loops and timeouts in readDistance. |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Signed-off-by: Arghya Biswas <arghyabiswas05@gmail.com>
7eee2c5 to
59b3105
Compare
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| if RPI_ENV: | ||
| print("Running on Raspberry Pi environment.") | ||
| GPIO.setmode(GPIO.BCM) | ||
| GPIO.setmode(GPIO.BOARD) |
There was a problem hiding this comment.
Switching the global GPIO mode to BOARD is a breaking change for any callers that may still provide BCM pin numbers. Consider making the numbering mode configurable (e.g., via config/env) and validating at startup, or clearly documenting this change and enforcing it with an assertion/log so misconfigurations are caught early.
| MOTOR_PIN = 32 | ||
| ULTRASONIC_TRIG = 40 | ||
| ULTRASONIC_ECHO = 38 |
There was a problem hiding this comment.
These constants are now physical BOARD pin numbers. Add a brief module-level comment stating that PinDescription uses GPIO.BOARD numbering to avoid confusion with BCM.
| if time.monotonic() - startTime > 1: | ||
| return -1 # Timeout waiting for echo to start |
There was a problem hiding this comment.
The timeout value 1 is duplicated and acts as a magic number. Extract it to a named constant (e.g., TIMEOUT_S = 1.0) and consider also defining a named error sentinel (e.g., DISTANCE_TIMEOUT = -1) to make the intent and usage clearer.
| if time.monotonic() - pulseStart > 1: | ||
| return -1 # Timeout waiting for echo to end |
There was a problem hiding this comment.
The timeout value 1 is duplicated and acts as a magic number. Extract it to a named constant (e.g., TIMEOUT_S = 1.0) and consider also defining a named error sentinel (e.g., DISTANCE_TIMEOUT = -1) to make the intent and usage clearer.
No description provided.