Sensors API¶
sensors
¶
Nectar SDK - Sensors module.
DistanceFilter
¶
Bases: Protocol
Stateful filter mapping a raw distance reading to a processed value.
A filter may suppress a reading entirely by returning None.
DistanceSensor
¶
Bases: Protocol
One-shot distance sensor.
Implementations should be non-blocking: read returns the latest
valid measurement available right now, or None if no fresh valid
reading is ready (e.g. partial frame, bad checksum, low signal).
TFLuna
¶
Benewake TF-Luna serial driver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
port
|
str
|
Serial device path (e.g. |
required |
baudrate
|
int
|
Default 115200 (TF-Luna factory setting). |
115200
|
timeout
|
float
|
Serial read timeout in seconds. Small non-zero value avoids
busy-polling while still keeping :meth: |
0.02
|
min_strength
|
int
|
Minimum signal strength to accept a frame. Frames below this or
equal to |
100
|
ObstacleMaskFilter
¶
ObstacleMaskFilter(obstacle_height_m: Optional[float] = None, *, max_change_m: float = 0.3, avg_window: int = 10, estimate_lock_s: float = 0.2, timeout_s: Optional[float] = 5.0)
Mask rangefinder samples while the beam is over an obstacle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obstacle_height_m
|
float
|
Vertical thickness of the obstacle in meters. |
None
|
max_change_m
|
float
|
Magnitude of sample-to-baseline drop that triggers entry, and the
magnitude of recovery above |
0.3
|
avg_window
|
int
|
Number of recent samples averaged for the entry baseline. Default 10. |
10
|
estimate_lock_s
|
float
|
Refinement window after entry during which |
0.2
|
timeout_s
|
float
|
Maximum time to remain in the masked state before forcing a reset.
|
5.0
|
Notes
The entry baseline is only updated outside the masked state, so a long masked period does not corrupt the average. While masked, raw samples are not pushed into the rolling window.
estimated_height_m
property
¶
Current obstacle-height estimate, or None outside the masked state.
process
¶
Apply the mask to a raw reading.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw_distance
|
float
|
Raw rangefinder reading in meters. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The filtered distance in meters. |
RangefinderPublisher
¶
RangefinderPublisher(sensor: DistanceSensor, connection: MavlinkConnection, *, sensor_id: int = 0, sensor_type: int = MAV_DISTANCE_SENSOR_LASER, orientation: int = MAV_SENSOR_ROTATION_PITCH_270, min_distance_m: float = 0.05, max_distance_m: float = 8.0, covariance_cm: int = 0, rate_hz: float = 50.0, filter: Optional[DistanceFilter] = None)
Bridge a :class:DistanceSensor to MAVLink DISTANCE_SENSOR.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sensor
|
DistanceSensor
|
Source of raw distance readings in meters. |
required |
connection
|
MavlinkConnection
|
Open MAVLink endpoint to the FCU. |
required |
sensor_id
|
int
|
MAVLink sensor id (0-7). ArduPilot maps this to |
0
|
sensor_type
|
int
|
MAVLink |
MAV_DISTANCE_SENSOR_LASER
|
orientation
|
int
|
MAVLink |
MAV_SENSOR_ROTATION_PITCH_270
|
min_distance_m
|
float
|
Minimum range the sensor can report, in meters. Default 0.05. |
0.05
|
max_distance_m
|
float
|
Maximum range the sensor can report, in meters. Default 8.0. |
8.0
|
covariance_cm
|
int
|
Measurement covariance hint in centimeters (0-254). 0 means "unknown / use ArduPilot defaults". Default 0. |
0
|
rate_hz
|
float
|
Publishing rate. Default 50. |
50.0
|
filter
|
DistanceFilter
|
Pre-publish filter. |
None
|
Notes
A background thread is created on :meth:start. The thread sleeps on
a :class:threading.Event, so :meth:stop is responsive.