Skip to content

Update pin config and fix the distance measure logic#4

Merged
arghyabi merged 1 commit into
masterfrom
fix_pin_config_and_fix_distance_measure
Sep 21, 2025
Merged

Update pin config and fix the distance measure logic#4
arghyabi merged 1 commit into
masterfrom
fix_pin_config_and_fix_distance_measure

Conversation

@arghyabi
Copy link
Copy Markdown
Owner

No description provided.

@arghyabi arghyabi requested a review from Copilot September 21, 2025 10:33
@arghyabi arghyabi force-pushed the fix_pin_config_and_fix_distance_measure branch from bf36f3d to 7eee2c5 Compare September 21, 2025 10:34
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread Scripts/Main.py Outdated
Comment thread Scripts/Main.py Outdated
Comment thread Scripts/Main.py Outdated
Comment thread Scripts/PinDescription.py
Signed-off-by: Arghya Biswas <arghyabiswas05@gmail.com>
@arghyabi arghyabi force-pushed the fix_pin_config_and_fix_distance_measure branch from 7eee2c5 to 59b3105 Compare September 21, 2025 10:39
@arghyabi arghyabi requested a review from Copilot September 21, 2025 10:39
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread Scripts/GpioManager.py
if RPI_ENV:
print("Running on Raspberry Pi environment.")
GPIO.setmode(GPIO.BCM)
GPIO.setmode(GPIO.BOARD)
Copy link

Copilot AI Sep 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread Scripts/PinDescription.py
Comment on lines +1 to +3
MOTOR_PIN = 32
ULTRASONIC_TRIG = 40
ULTRASONIC_ECHO = 38
Copy link

Copilot AI Sep 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread Scripts/Main.py
Comment on lines +35 to +36
if time.monotonic() - startTime > 1:
return -1 # Timeout waiting for echo to start
Copy link

Copilot AI Sep 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread Scripts/Main.py
Comment on lines +41 to +42
if time.monotonic() - pulseStart > 1:
return -1 # Timeout waiting for echo to end
Copy link

Copilot AI Sep 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@arghyabi arghyabi merged commit 63e542c into master Sep 21, 2025
1 check passed
@arghyabi arghyabi deleted the fix_pin_config_and_fix_distance_measure branch September 21, 2025 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants