The MAV_CMD_ACCELCAL_VEHICLE_POS 2 command says it’s “Used when doing accelerometer calibration.” That’s a bit ambiguous, but given it’s not working for you then the “when doing” likely implies the calibration has to be started with a different message, and the vehicle pos command is just for stepping through the positions during the calibration.
From the QGC source file that was linked to in the other post,
the APMSensorsComponentController.cc sets up the accelerometer calibration,
then delegates it to the vehicle (_vehicle->startCalibration()).
Looking in Vehicle.cc (where vehicle functionality is defined),
the calibration is started using the MAV_CMD_PREFLIGHT_CALIBRATION 6 command.
Compass Calibration
For the compass calibration, the definition in APMSensorsComponentController.cc 1 uses MAV_CMD_DO_CANCEL_MAG_CAL 1 to determine whether the flight computer supports onboard compass calibration.
Looking at the nearby commands in the message set comes up with the MAV_CMD_DO_START_MAG_CAL 3, which is presumably used to start magnetometer (compass) calibration (so we have something to look for).
The calibrateCompass method (from step 1) hands off logic to the _mavCommandResult 4 method in the same file,
where you can see that MAV_CMD_DO_START_MAG_CAL 3 is indeed used if onboard calibration is supported,
which from a search of MAG_CAL in the ArduPilot codebase 2
seems to be the case as of at least ArduSub 4.0 2 (probably can stop here, and just use that message).
Where onboard calibration isn’t supported, it instead uses _compassCal.startCalibration().
I wasn’t sure where that was defined, but it wasn’t in that file so
I checked the corresponding header file, which #includes APMCompassCal.h.
Looking in the corresponding source file,
APMCompassCal.cc 1 defines the function we’re after, as well as the various calculations that are used to perform a compass calibration externally.
The code there is quite convoluted, so I’m not certain how it tracks the calibration state (if it even does - it seems like it might just communicate via string/text messages).
Focusing back on the more promising approach, to confirm whether the MAG_CAL messages work I tried following the QGC approach from step 3. - sending a CANCEL_MAG_CAL command and seeing what kind of MAV_RESULT 1 the command is acknowledged with (as per the Command Protocol 1):