QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
MockLinkPX4Calibration Class Reference

Simulates the PX4 commander magnetometer and accelerometer calibration protocols for MockLink. More...

#include <MockLinkPX4Calibration.h>

Public Types

enum class  Pose {
  None = -1 , TailDown = 0 , NoseDown , Left ,
  Right , UpsideDown , RightSideUp
}
 Vehicle poses. Order matches the PX4 detect_orientation_return enum. More...

Public Member Functions

 MockLinkPX4Calibration (MockLink *mockLink)
void startMagCalibration ()
void startAccelCalibration ()
void startBaroCalibration (bool fails)
void startLevelCalibration (bool fails)
void startGyroCalibration (bool fails)
void setInlineCalibrationStalls (bool stalls)
 Makes the simulated barometer, level horizon and gyroscope calibrations run until they are cancelled.
bool cancel ()
bool fail ()
bool calibrationActive () const
void setPose (Pose pose)
void run10HzTasks ()
 Called by MockLink::run10HzTasks on the worker thread.

Static Public Attributes

static constexpr int kSideCount = 6

Detailed Description

Simulates the PX4 commander magnetometer and accelerometer calibration protocols for MockLink.

Replays the [cal] STATUSTEXT protocol emitted by the PX4 firmware (src/modules/commander/mag_calibration.cpp, accelerometer_calibration.cpp and calibration_routines.cpp). Magnetometer:

[cal] calibration started: 2 mag
[cal] <side> orientation detected
[cal] <side> side calibration: progress <N>
[cal] <side> side done, rotate to a different side
[cal] progress <100>
[cal] calibration done: mag

Accelerometer:

[cal] calibration started: 2 accel
[cal] <side> orientation detected
[cal] Hold still, measuring <side> side
[cal] <side> side result: [x y z]
[cal] progress <17*doneCount>
[cal] <side> side done, rotate to a different side
[cal] calibration done: accel

The simulation is pose-driven: a unit test places the simulated vehicle into a pose with setPose(). On subsequent 10Hz ticks the state machine detects the orientation, simulates the rotation/sampling phase and completes the side. Setting a pose for an already completed side emits "[cal] <side> side already completed", matching firmware behavior.

All six sides are required, matching CAL_MAG_SIDES=63 in PX4MockLink.params.

An all-zero MAV_CMD_PREFLIGHT_CALIBRATION while a calibration is active cancels it with "[cal] calibration cancelled" (see PX4 calibrate_cancel_check()).

Definition at line 40 of file MockLinkPX4Calibration.h.

Member Enumeration Documentation

◆ Pose

enum class MockLinkPX4Calibration::Pose
strong

Vehicle poses. Order matches the PX4 detect_orientation_return enum.

Enumerator
None 
TailDown 

"back" accel [ g, 0, 0 ]

NoseDown 

"front" accel [ -g, 0, 0 ]

Left 

"left" accel [ 0, g, 0 ]

Right 

"right" accel [ 0, -g, 0 ]

UpsideDown 

"up" accel [ 0, 0, g ]

RightSideUp 

"down" accel [ 0, 0, -g ]

Definition at line 44 of file MockLinkPX4Calibration.h.

Constructor & Destructor Documentation

◆ MockLinkPX4Calibration()

MockLinkPX4Calibration::MockLinkPX4Calibration ( MockLink * mockLink)
explicit

Definition at line 36 of file MockLinkPX4Calibration.cc.

Member Function Documentation

◆ calibrationActive()

bool MockLinkPX4Calibration::calibrationActive ( ) const

Definition at line 154 of file MockLinkPX4Calibration.cc.

◆ cancel()

bool MockLinkPX4Calibration::cancel ( )

Handles an all-zero MAV_CMD_PREFLIGHT_CALIBRATION (cancel request).

Returns
true if a calibration was active and has been cancelled

Definition at line 119 of file MockLinkPX4Calibration.cc.

◆ fail()

bool MockLinkPX4Calibration::fail ( )

Ends the running calibration the way the firmware does when it fails: it reports the failure and stops.

Returns
true if a calibration was active

Definition at line 136 of file MockLinkPX4Calibration.cc.

◆ run10HzTasks()

void MockLinkPX4Calibration::run10HzTasks ( )

Called by MockLink::run10HzTasks on the worker thread.

Definition at line 166 of file MockLinkPX4Calibration.cc.

◆ setInlineCalibrationStalls()

void MockLinkPX4Calibration::setInlineCalibrationStalls ( bool stalls)

Makes the simulated barometer, level horizon and gyroscope calibrations run until they are cancelled.

Definition at line 78 of file MockLinkPX4Calibration.cc.

◆ setPose()

void MockLinkPX4Calibration::setPose ( Pose pose)

Test API: places the simulated vehicle into the given pose. The state machine advances on subsequent 10Hz ticks. Thread-safe.

Definition at line 160 of file MockLinkPX4Calibration.cc.

◆ startAccelCalibration()

void MockLinkPX4Calibration::startAccelCalibration ( )

Starts simulated accel calibration: sends "[cal] calibration started: 2 accel" and resets the side state machine.

Definition at line 46 of file MockLinkPX4Calibration.cc.

◆ startBaroCalibration()

void MockLinkPX4Calibration::startBaroCalibration ( bool fails)

Starts simulated barometer calibration: sends "[cal] calibration started: 2 baro", then after a short delay either stores the calibration and reports done, or reports that no GPS was available.

Definition at line 51 of file MockLinkPX4Calibration.cc.

◆ startGyroCalibration()

void MockLinkPX4Calibration::startGyroCalibration ( bool fails)

Starts simulated gyroscope calibration: sends "[cal] calibration started: 2 gyro", then after a short delay either stores the calibration and reports done, or reports that the vehicle moved.

Definition at line 69 of file MockLinkPX4Calibration.cc.

◆ startLevelCalibration()

void MockLinkPX4Calibration::startLevelCalibration ( bool fails)

Starts simulated level horizon calibration: sends "[cal] calibration started: 2 level", then after a short delay either stores the board offsets and reports done, or reports that the vehicle moved.

Definition at line 60 of file MockLinkPX4Calibration.cc.

◆ startMagCalibration()

void MockLinkPX4Calibration::startMagCalibration ( )

Starts simulated mag calibration: sends "[cal] calibration started: 2 mag" and resets the side state machine.

Definition at line 41 of file MockLinkPX4Calibration.cc.

Member Data Documentation

◆ kSideCount

int MockLinkPX4Calibration::kSideCount = 6
staticconstexpr

Definition at line 53 of file MockLinkPX4Calibration.h.


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