feat: HC-SR04 ultrasonic distance sensor driver (Issue #243) #245

Merged
sl-jetson merged 1 commits from sl-firmware/issue-243-ultrasonic into main 2026-03-02 12:46:18 -05:00
Collaborator

Implements STM32F7 non-blocking driver for HC-SR04 ultrasonic ranger with TIM1 input capture.

Features:

  • Trigger: PA0 GPIO output (10µs pulse)
  • Echo: PA1 TIM1_CH2 input capture (both edges)
  • Distance range: 20-5000mm (±3mm accuracy)
  • Non-blocking API with optional callback
  • Timeout detection (30ms max echo wait)
  • State machine: IDLE → TRIGGERED → MEASURING → COMPLETE/ERROR

Test Coverage:

  • 26 passing unit tests
  • Distance conversion accuracy
  • State machine transitions
  • Range validation boundaries
  • Timeout detection
  • Multiple sequential measurements

Integration:

  • ultrasonic_init() called in main() startup
  • Ready for autonomous navigation/obstacle avoidance

🤖 Generated with Claude Code

Implements STM32F7 non-blocking driver for HC-SR04 ultrasonic ranger with TIM1 input capture. **Features:** - Trigger: PA0 GPIO output (10µs pulse) - Echo: PA1 TIM1_CH2 input capture (both edges) - Distance range: 20-5000mm (±3mm accuracy) - Non-blocking API with optional callback - Timeout detection (30ms max echo wait) - State machine: IDLE → TRIGGERED → MEASURING → COMPLETE/ERROR **Test Coverage:** - 26 passing unit tests - Distance conversion accuracy - State machine transitions - Range validation boundaries - Timeout detection - Multiple sequential measurements **Integration:** - ultrasonic_init() called in main() startup - Ready for autonomous navigation/obstacle avoidance 🤖 Generated with Claude Code
sl-webui added 1 commit 2026-03-02 12:22:20 -05:00
Implements STM32F7 non-blocking driver for HC-SR04 ultrasonic ranger with TIM1 input capture.
Supports distance measurement via echo pulse width analysis.

Features:
- Trigger: PA0 GPIO output (10µs pulse)
- Echo: PA1 TIM1_CH2 input capture (both edges)
- TIM1 configured for 1MHz clock (1µs per count)
- Distance range: 20-5000mm (±3mm accuracy)
- Distance = (pulse_width_us / 2) / 29.1mm
- Non-blocking API with optional callback
- Timeout detection (30ms max echo wait)
- State machine: IDLE → TRIGGERED → MEASURING → COMPLETE/ERROR

API Functions:
- ultrasonic_init(): Configure GPIO and TIM1
- ultrasonic_trigger(): Start measurement
- ultrasonic_set_callback(): Register completion callback
- ultrasonic_get_state(): Query current state
- ultrasonic_get_result(): Retrieve measurement result
- ultrasonic_tick(): Periodic timeout handler

Test Suite:
- 26 passing unit tests
- Distance conversion accuracy (100mm-2000mm)
- State machine transitions
- Range validation (20-5000mm boundaries)
- Timeout detection
- Multiple sequential measurements

Integration:
- ultrasonic_init() called in main() startup after servo_init()
- Non-blocking operation suitable for autonomous navigation/obstacle avoidance

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
sl-jetson merged commit 81786f5e4e into main 2026-03-02 12:46:18 -05:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: seb/saltylab-firmware#245
No description provided.