pub struct Session {
pub(crate) ptr: NonNull<TcsSession>,
}Expand description
One live calibration: the sample buffer, the solver, retention, the accelerometer fit, the quality figures and the filtered compass.
Fields§
§ptr: NonNull<TcsSession>The C handle; never null, freed in Drop.
Implementations§
Source§impl Session
impl Session
Sourcepub fn new() -> Result<Session, SessionError>
pub fn new() -> Result<Session, SessionError>
Creates an empty session.
§Errors
SessionError::AbiMismatch when the linked library was built from
another version of the header; SessionError::OutOfMemory when it
cannot allocate.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Discards every sample, the fit, the accelerometer fit and any loaded offset; the field returns to 50 µT. The live compass filter is kept.
Sourcepub fn add_sample(&mut self, mag: [f32; 3], accel: Option<[f32; 3]>) -> bool
pub fn add_sample(&mut self, mag: [f32; 3], accel: Option<[f32; 3]>) -> bool
Feeds one calibration sample: raw magnetometer, µT, and the accelerometer reading, mg, when the sample has one.
Returns true when the solver accepted a new fit on this sample.
Sourcepub fn has_calibration(&self) -> bool
pub fn has_calibration(&self) -> bool
Whether a magnetometer calibration exists (fitted or loaded).
Sourcepub fn calibrate(&self, mag: [f32; 3]) -> [f32; 3]
pub fn calibrate(&self, mag: [f32; 3]) -> [f32; 3]
Applies the current magnetometer calibration, A (mag - V); the
identity before a fit.
Sourcepub fn points(&self) -> Vec<[f32; 3]>
pub fn points(&self) -> Vec<[f32; 3]>
Every buffered reading, calibrated, in slot order; at most SLOTS.
Sourcepub fn set_constants(&mut self, offset: [f32; 3], mapping: [[f32; 3]; 3])
pub fn set_constants(&mut self, offset: [f32; 3], mapping: [[f32; 3]; 3])
Installs magnetometer constants read back from a tag. The field is recomputed from the buffered readings, or kept when there are none.
Sourcepub fn set_accel_offset(&mut self, offset: [f32; 3])
pub fn set_accel_offset(&mut self, offset: [f32; 3])
Installs an accelerometer offset read back from a tag, mg. It stands until a live fit is valid or the session is cleared.
Sourcepub fn update_quality(&mut self)
pub fn update_quality(&mut self)
Recomputes the quality figures and the accelerometer fit. A valid fit also tightens the accelerometer’s intake gate, so how often this runs affects later samples: qtcalibrate’s replay runs it every second sample.
Sourcepub fn quality(&self) -> Quality
pub fn quality(&self) -> Quality
The quality figures as of the last Session::update_quality.
Sourcepub fn orientation(
&mut self,
mag: [f32; 3],
accel: [f32; 3],
) -> Option<Orientation>
pub fn orientation( &mut self, mag: [f32; 3], accel: [f32; 3], ) -> Option<Orientation>
Solves the live compass from one raw sample, through the session’s low-pass filter, which this advances.
Returns None when the filtered pair admits no orientation.