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 ()
 
bool cancel ()
 
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 32 of file MockLinkPX4Calibration.cc.

Member Function Documentation

◆ calibrationActive()

bool MockLinkPX4Calibration::calibrationActive ( ) const

Definition at line 79 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 62 of file MockLinkPX4Calibration.cc.

References MockLink::sendStatusTextMessage().

◆ run10HzTasks()

void MockLinkPX4Calibration::run10HzTasks ( )

◆ 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 85 of file MockLinkPX4Calibration.cc.

Referenced by MockLink::setCalibrationPose().

◆ startAccelCalibration()

void MockLinkPX4Calibration::startAccelCalibration ( )

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

Definition at line 42 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 37 of file MockLinkPX4Calibration.cc.

Member Data Documentation

◆ kSideCount

constexpr int MockLinkPX4Calibration::kSideCount = 6
staticconstexpr

Definition at line 53 of file MockLinkPX4Calibration.h.


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