Skip to content

LYNHQQ/AltitudeEstimation_components

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

162 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AltitudeEstimation

Pure C altitude estimation component for embedded targets such as STM32 and ESP32. The original Arduino/C++ library layout has been removed. The repository now exposes a portable struct + function API with no Arduino.h dependency, no dynamic memory, and no C++ runtime requirement.

The algorithm still uses two stages:

  • Kalman filter: estimate vertical acceleration from gyro and accelerometer data
  • Complementary filter: fuse barometer altitude with vertical acceleration to estimate altitude and vertical velocity

Layout

components/
  altitude_estimation/
    CMakeLists.txt
    include/
      altitude_estimation.h
    src/
      altitude_estimation.c
      altitude_estimation_filters.c
      altitude_estimation_math.c
examples/
  portable/
    altitude_estimation_example.c

Input Units

  • accel_g[3]: accelerometer data in g
  • gyro_rad_s[3]: gyroscope data in rad/s
  • baro_altitude_m: barometer altitude in m
  • timestamp_us: sample timestamp in us

Sensor drivers and pressure-to-altitude conversion stay outside this component.

ESP-IDF Integration

Copy components/altitude_estimation into your ESP-IDF project components/ directory. The component has no external dependencies.

Example:

#include "altitude_estimation.h"

static altitude_estimation_t estimator;

void app_main(void)
{
    altitude_estimation_config_t config = ALTITUDE_ESTIMATION_DEFAULT_CONFIG;

    altitude_estimation_init(&estimator, &config);
    altitude_estimation_reset(&estimator, 0.0f);
}

STM32 Integration

Add these files to your STM32 project:

Also make sure to:

  • add components/altitude_estimation/include to your include path
  • build as C99 or newer
  • link m for GCC/Clang toolchains

API

Initialization:

altitude_estimation_t estimator;
altitude_estimation_config_t config = ALTITUDE_ESTIMATION_DEFAULT_CONFIG;

altitude_estimation_init(&estimator, &config);
altitude_estimation_reset(&estimator, 0.0f);

Runtime update:

altitude_estimation_status_t status = altitude_estimation_update(
    &estimator,
    accel_g,
    gyro_rad_s,
    baro_altitude_m,
    timestamp_us);

Notes:

  • the first altitude_estimation_update() call only seeds history and returns ALTITUDE_ESTIMATION_STATUS_NEEDS_MORE_DATA
  • later successful calls return ALTITUDE_ESTIMATION_STATUS_OK
  • equal timestamps return ALTITUDE_ESTIMATION_STATUS_INVALID_DELTA_TIME
  • uint32_t microsecond timestamps can wrap naturally as long as the gap between consecutive samples is far below 71 minutes

Read results:

float altitude_m = altitude_estimation_get_altitude(&estimator);
float velocity_mps = altitude_estimation_get_vertical_velocity(&estimator);
float accel_mps2 = altitude_estimation_get_vertical_acceleration(&estimator);

Example

See altitude_estimation_example.c for a minimal portable example that does not depend on any board SDK.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors