Custom Gazebo PX4 Model in SITL - Compass Calibration Lost?

Hi There, I am in the process of creating a custom Gazebo model for use in SITL. At some point I was fiddling with things in QGroundControl and accidentally reset or otherwise broke a bunch of sensor calibrations in the Sensors section (see below). The calibrations for the Gryo and Accel seem to have returned by starting and restarting the simulation, but the Compass remains missing, which prevents arming. Sensor-wise, it’s basically a clone of the standard_vtol. I attempted a manual calibration (by manually modifying the pose in Gazebo) but doesn’t seem to work because it times out too quickly … and that doesn’t seem right anyway because this is all in SITL. Anyway, does calibration data persist across SITL runs? If so how can I reset it? Does this calibration data live in a QGroundControl setting or is it persisted in PX4 somehow? Thanks!

A clue – I was able to also break calibrations for another the standard_vtol by pressing “factory reset” on the sensors / calibration page. So, perhaps the question is – how do you “un-factory-reset” a SITL model?

Solved this by just digging through the code. TLDR - delete the PX4-Autopilot/build and build again with make px4_sitl gazebo_standard_vtol

Anyway –

  1. The Factory Reset button sends a mavlink command to reset the factory parameters in in QGroundControl:
                             true,  // showError
                             3,     // Reset factory parameters
                             -1);   // Don't do anything with mission storage
  1. The Commander.cpp in PX4 receives the command and dispatches a job to execute the command
				} else if (((int)(cmd.param1)) == 3) {
					answer_command(cmd, vehicle_command_s::VEHICLE_CMD_RESULT_ACCEPTED);
  1. The worker_thread.cpp in PX4 writes the changes to a parameters file kept in the aircraft’s eeprom
	case Request::ParamResetSensorFactory:
		const char *reset_cal[] = { "CAL_ACC*", "CAL_GYRO*", "CAL_MAG*" };
		param_reset_specific(reset_cal, sizeof(reset_cal) / sizeof(reset_cal[0]));
		_ret_value = param_save_default();
		px4_reboot_request(false, 400_ms);

It appears that for SITL, this eeprom record is persisted across builds. One can manually locate that file or, simply remove the PX4-Autopilot/build/ directory in PX4-Autopilot repo. Apparently a make clean is not sufficient. Then just build from scratch with make px4_sitl gazebo_standard_vtol.