sonar

sonar.py

Overview

sonar.py is a synthetic ultrasound range-finder component that emits constant sensor_msgs/Range messages at 10 Hz. It enables sensor-fusion, navigation and obstacle-avoidance pipelines to be exercised even without real hardware or ROS bags.

Interfaces (strongly-typed, stateless)

Direction

Topic

Message type / Notes

Provided

/{robot}/sonar

sensor_msgs/Range – single-beam, 10 Hz

Contract

Pre-conditions

  • Node launched with a valid robot_id CLI argument.

  • Downstream expects Range.ULTRASOUND readings at ∼10 Hz.

Post-conditions

  • Publishes exactly one Range per loop iteration.

  • range field is fixed at 3.0 m.

  • Header uses frame_id “sonar” and current time stamp.

Invariants

  • Loop frequency = 10 Hz ± 5%.

  • field_of_view = 0.1 rad, min_range = 0.2 m, max_range = 4.0 m.

Quality-of-Service KPIs

Metric

Target

Rationale

Message rate

10 Hz ± 0.5 Hz

Keeps real-time filters stable.

Latency

< 50 ms

Avoids stale obstacle data.

CPU load

< 1 %

Safe on embedded CPUs.

Implementation notes

  • Uses rospy.Rate(10) for timing.

  • Message fields are hard-coded for simplicity; adjust constants below to emulate other sensors.

Functions

publish()

Advertise /sonar and stream constant Range messages until shutdown.