Skip to main content

Module params

Module params 

Source
Expand description

A flat name → f32 view over the config tree, for live tuning from a ground station.

The config is the only store: Params::param reads a field of the component’s config, and Params::set_param writes a copy and commits it through Configurable::set_config, which validates it (an invalid value is rejected and the config unchanged) and applies the integrator policy. Any Configurable whose config implements ParamTable gets Params; FlightLoop combines its guidance’s and stabilizer’s.

Names are uppercase ASCII of at most MAX_NAME_LEN bytes (MAVLink’s param_id), prefixed by component (STAB_, GUID_) and loop. Vector components end in _X/_Y/_Z (roll/pitch/yaw for angles and rates). Angles and angular rates are in degrees and deg/s, as ground stations show them, and convert to the config’s radians at this boundary; everything else is in the config field’s own unit.

Params are addressed by index, 0..param_count(), in a stable table order; name lookup scans the names. Index access is what paced output uses (a cursor that sends a few params per tick).

Units, descriptions, groups, and valid ranges are in the metadata module (feature param-metadata), one table per config next to its ParamTable. The tables below map names to config fields.

§Copter stabilizer (CopterStabilizerConfig)

NameField
STAB_RATE_P, _I, _Dbody_rate.gains
STAB_RATE_YAW_P, _I, _Dbody_rate.yaw_gains
STAB_RATE_IMAXbody_rate.max_integral
STAB_ATT_P, _I, _Dattitude.gains
STAB_ATT_AMAX_X, _Yattitude.max_angles_rad
STAB_ATT_IMAXattitude.max_integral
STAB_ATT_RMAX_X, _Yattitude.max_rate_radps
STAB_YAW_P, _I, _Dyaw.gains
STAB_YAW_IMAXyaw.max_integral
STAB_YAW_RMAXyaw.max_rate_radps
STAB_FS_RATE_X, _Y, _Zfull_scale_rates_radps
STAB_THR_EXPOthrust_curve_exponent

§Copter guidance (CopterGuidanceConfig)

NameField
GUID_ALT_P, _I, _Daltitude.gains
GUID_ALT_IMAXaltitude.max_integral
GUID_ALT_HOVERaltitude.hover_thrust
GUID_LAT_POS_Plateral.position_p
GUID_LAT_VEL_P, _I, _Dlateral.velocity
GUID_LAT_IMAXlateral.max_integral
GUID_NAV_PERIODnavigation_period_s
GUID_TILT_MAXmax_tilt_rad
GUID_DESC_MAXmax_descent_mps
GUID_LAND_SPDland_speed_mps
GUID_STICK_X, _Ymax_stick_angles_rad

§Examples

use stable_flight::params::Params;
use stable_flight::stabilizers::copter::{CopterStabilizer, CopterStabilizerConfig};
use stable_flight::Configurable;

let mut stabilizer = CopterStabilizer::new(CopterStabilizerConfig::default());

stabilizer.set_param("STAB_RATE_P", 0.2).expect("valid value");
assert_eq!(stabilizer.param("STAB_RATE_P"), Some(0.2));
assert_eq!(stabilizer.config().body_rate.gains.p, 0.2);

stabilizer.set_param("STAB_ATT_AMAX_X", 30.0).expect("valid value"); // degrees
assert!((stabilizer.config().attitude.max_angles_rad.x - 30f32.to_radians()).abs() < 1e-6);

assert!(stabilizer.set_param("STAB_RATE_IMAX", -1.0).is_err()); // fails validation
assert!(stabilizer.set_param("NO_SUCH_PARAM", 1.0).is_err());

let mut count = 0;
stabilizer.visit_params(&mut |_name, _value| count += 1);
assert_eq!(count, 24);

Modules§

metadata
Descriptions, units, grouping, and valid ranges for params, for ground stations (param-metadata feature): a host-side companion to each ParamTable, so flight-controller firmware, which never enables the feature, carries none of it.

Structs§

Param
One named f32 field of a config C: how to read it and how to write it, unvalidated.

Enums§

ParamError
Why a param write (Params::set_param, Params::set_param_at) was rejected.

Constants§

MAX_NAME_LEN
Longest param name in bytes: MAVLink’s param_id field.

Traits§

ParamTable
A config that exposes its fields as named params.
Params
Read, write, and list a component’s tunable values by index or by name.