OpenRoadCode
Public API reference for OpenRoadCode
Loading...
Searching...
No Matches
environmental.barometric_controller.BarometricController Class Reference

Read and process measurements from a barometric source. More...

Inheritance diagram for environmental.barometric_controller.BarometricController:
environmental.barometric_controller_if.BarometricControllerIf

Public Member Functions

None __init__ (self, BarometricSourceIf sensor, *float sea_level_pressure_pa=STANDARD_SEA_LEVEL_PRESSURE_PA, int vertical_speed_window_size=8, Callable[[], float] monotonic_clock=time.monotonic)
 Create a barometric controller.
 
bool is_started (self)
 Return whether the controller and sensor are started.
 
bool is_available (self)
 Return whether the configured barometric source is available.
 
str|None status_message (self)
 Return an availability status message.
 
float sea_level_pressure_pa (self)
 Return the current sea-level pressure reference.
 
BarometricState|None latest_state (self)
 Return the most recently calculated state.
 
None start (self)
 Start the barometric source and reset calculated state.
 
None stop (self)
 Stop the barometric source.
 
BarometricState read_state (self)
 Read the source and calculate barometric state.
 
None set_sea_level_pressure_pa (self, float pressure_pa)
 Set the reference pressure used for absolute altitude.
 
float calibrate_altitude (self, float known_altitude_m, *float|None pressure_pa=None)
 Calibrate sea-level pressure using a known current altitude.
 
None reset_relative_altitude (self)
 Set the current altitude as the relative-altitude zero point.
 

Static Public Member Functions

float calculate_altitude_m (*float pressure_pa, float sea_level_pressure_pa)
 Calculate barometric altitude in meters.
 

Detailed Description

Read and process measurements from a barometric source.

The controller calculates barometric altitude, relative altitude, and filtered vertical speed from pressure measurements.

The hardware sensor remains responsible only for providing pressure and temperature values.

Constructor & Destructor Documentation

◆ __init__()

None environmental.barometric_controller.BarometricController.__init__ (   self,
BarometricSourceIf  sensor,
*float   sea_level_pressure_pa = STANDARD_SEA_LEVEL_PRESSURE_PA,
int   vertical_speed_window_size = 8,
Callable[[], float]   monotonic_clock = time.monotonic 
)

Create a barometric controller.

Args: sensor: Controller-facing environmental sensor adapter. sea_level_pressure_pa: Reference sea-level pressure used for absolute altitude calculations. vertical_speed_window_size: Number of altitude samples used to smooth vertical-speed calculations. monotonic_clock: Clock used for elapsed-time calculations.

Member Function Documentation

◆ calculate_altitude_m()

float environmental.barometric_controller.BarometricController.calculate_altitude_m ( *float  pressure_pa,
float  sea_level_pressure_pa 
)
static

Calculate barometric altitude in meters.

This uses the standard atmosphere approximation and assumes a tropospheric temperature lapse rate.

Parameters
pressure_paMeasured atmospheric pressure in pascals.
sea_level_pressure_paSea-level reference pressure in pascals.
Returns
Estimated altitude above mean sea level in meters.
Exceptions
ValueErrorif either pressure is not positive.

◆ calibrate_altitude()

float environmental.barometric_controller.BarometricController.calibrate_altitude (   self,
float  known_altitude_m,
*float | None   pressure_pa = None 
)

Calibrate sea-level pressure using a known current altitude.

Parameters
known_altitude_mKnown altitude above mean sea level in meters.
pressure_paCurrent pressure in pascals; when None, read it from the configured sensor.
Returns
Calculated sea-level pressure reference in pascals.
Exceptions
RuntimeErrorif the controller has not been started.
ValueErrorif the selected pressure is not positive.

Reimplemented from environmental.barometric_controller_if.BarometricControllerIf.

◆ latest_state()

BarometricState | None environmental.barometric_controller.BarometricController.latest_state (   self)

Return the most recently calculated state.

Returns
Latest snapshot, or None before the first successful read.

Reimplemented from environmental.barometric_controller_if.BarometricControllerIf.

◆ read_state()

BarometricState environmental.barometric_controller.BarometricController.read_state (   self)

Read the source and calculate barometric state.

Returns
Pressure, temperature, altitude, and vertical-speed snapshot.
Exceptions
RuntimeErrorif the controller has not been started.

Reimplemented from environmental.barometric_controller_if.BarometricControllerIf.

◆ sea_level_pressure_pa()

float environmental.barometric_controller.BarometricController.sea_level_pressure_pa (   self)

Return the current sea-level pressure reference.

Returns
Reference pressure in pascals.

Reimplemented from environmental.barometric_controller_if.BarometricControllerIf.

◆ set_sea_level_pressure_pa()

None environmental.barometric_controller.BarometricController.set_sea_level_pressure_pa (   self,
float  pressure_pa 
)

Set the reference pressure used for absolute altitude.

Parameters
pressure_paPositive sea-level reference pressure in pascals.
Exceptions
ValueErrorif ``pressure_pa`` is not positive.

Reimplemented from environmental.barometric_controller_if.BarometricControllerIf.


The documentation for this class was generated from the following file: