2016-02-17 21:25:11 -04:00
|
|
|
#pragma once
|
2015-10-16 18:51:16 -03:00
|
|
|
|
2021-08-18 08:42:16 -03:00
|
|
|
#include <GCS_MAVLink/GCS.h>
|
2015-10-16 18:51:16 -03:00
|
|
|
#include "AccelCalibrator.h"
|
2018-12-27 07:57:30 -04:00
|
|
|
#include "AP_Vehicle/AP_Vehicle_Type.h"
|
2015-10-16 18:51:16 -03:00
|
|
|
|
2021-06-23 08:30:45 -03:00
|
|
|
#ifndef HAL_INS_ACCELCAL_ENABLED
|
2021-08-18 08:42:16 -03:00
|
|
|
#if HAL_GCS_ENABLED
|
2021-06-23 08:30:45 -03:00
|
|
|
#define HAL_INS_ACCELCAL_ENABLED 1
|
|
|
|
#else
|
|
|
|
#define HAL_INS_ACCELCAL_ENABLED 0
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2015-10-16 18:51:16 -03:00
|
|
|
#define AP_ACCELCAL_MAX_NUM_CLIENTS 4
|
|
|
|
class GCS_MAVLINK;
|
|
|
|
class AP_AccelCal_Client;
|
|
|
|
|
|
|
|
class AP_AccelCal {
|
|
|
|
public:
|
|
|
|
AP_AccelCal():
|
2016-11-12 05:49:08 -04:00
|
|
|
_use_gcs_snoop(true),
|
2015-10-16 18:51:16 -03:00
|
|
|
_started(false),
|
|
|
|
_saving(false)
|
|
|
|
{ update_status(); }
|
|
|
|
|
|
|
|
// start all the registered calibrations
|
|
|
|
void start(GCS_MAVLINK *gcs);
|
|
|
|
|
|
|
|
// called on calibration cancellation
|
|
|
|
void cancel();
|
|
|
|
|
|
|
|
// Run an iteration of all registered calibrations
|
|
|
|
void update();
|
|
|
|
|
|
|
|
// get the status of the calibrator server as a whole
|
|
|
|
accel_cal_status_t get_status() { return _status; }
|
2016-11-12 05:49:08 -04:00
|
|
|
|
|
|
|
// Set vehicle position sent by the GCS
|
|
|
|
bool gcs_vehicle_position(float position);
|
2015-10-16 18:51:16 -03:00
|
|
|
|
2016-01-04 18:39:15 -04:00
|
|
|
// interface to the clients for registration
|
|
|
|
static void register_client(AP_AccelCal_Client* client);
|
|
|
|
|
2021-08-18 08:42:16 -03:00
|
|
|
#if HAL_GCS_ENABLED
|
2022-05-24 19:57:36 -03:00
|
|
|
void handle_command_ack(const mavlink_command_ack_t &packet);
|
2021-08-18 08:42:16 -03:00
|
|
|
#endif
|
2018-03-17 03:56:57 -03:00
|
|
|
|
2021-01-07 20:45:27 -04:00
|
|
|
// true if we are in a calibration process
|
2021-01-20 00:06:58 -04:00
|
|
|
bool running(void) const;
|
2021-01-07 20:45:27 -04:00
|
|
|
|
2015-10-16 18:51:16 -03:00
|
|
|
private:
|
|
|
|
GCS_MAVLINK *_gcs;
|
2016-11-12 05:49:08 -04:00
|
|
|
bool _use_gcs_snoop;
|
2018-03-17 03:56:57 -03:00
|
|
|
bool _waiting_for_mavlink_ack = false;
|
2016-11-12 05:49:08 -04:00
|
|
|
uint32_t _last_position_request_ms;
|
2015-10-16 18:51:16 -03:00
|
|
|
uint8_t _step;
|
|
|
|
accel_cal_status_t _status;
|
2017-05-29 18:03:36 -03:00
|
|
|
accel_cal_status_t _last_result;
|
2016-01-04 18:39:15 -04:00
|
|
|
|
|
|
|
static uint8_t _num_clients;
|
|
|
|
static AP_AccelCal_Client* _clients[AP_ACCELCAL_MAX_NUM_CLIENTS];
|
2015-10-16 18:51:16 -03:00
|
|
|
|
|
|
|
// called on calibration success
|
|
|
|
void success();
|
|
|
|
|
|
|
|
// called on calibration failure
|
|
|
|
void fail();
|
|
|
|
|
|
|
|
// reset all the calibrators to there pre calibration stage so as to make them ready for next calibration request
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
// proceed through the collection step for each of the registered calibrators
|
|
|
|
void collect_sample();
|
|
|
|
|
|
|
|
// update the state of the Accel calibrator server
|
|
|
|
void update_status();
|
|
|
|
|
2016-05-12 13:58:14 -03:00
|
|
|
// checks if no new sample has been received for considerable amount of time
|
2015-10-16 18:51:16 -03:00
|
|
|
bool check_for_timeout();
|
|
|
|
|
|
|
|
// check if client's calibrator is active
|
|
|
|
bool client_active(uint8_t client_num);
|
|
|
|
|
|
|
|
bool _started;
|
|
|
|
bool _saving;
|
|
|
|
|
|
|
|
uint8_t _num_active_calibrators;
|
|
|
|
|
|
|
|
AccelCalibrator* get_calibrator(uint8_t i);
|
|
|
|
};
|
|
|
|
|
|
|
|
class AP_AccelCal_Client {
|
|
|
|
friend class AP_AccelCal;
|
|
|
|
private:
|
|
|
|
// getters
|
|
|
|
virtual bool _acal_get_saving() { return false; }
|
|
|
|
virtual bool _acal_get_ready_to_sample() { return true; }
|
|
|
|
virtual bool _acal_get_fail() { return false; }
|
|
|
|
virtual AccelCalibrator* _acal_get_calibrator(uint8_t instance) = 0;
|
|
|
|
|
|
|
|
// events
|
|
|
|
virtual void _acal_save_calibrations() = 0;
|
|
|
|
virtual void _acal_event_success() {};
|
|
|
|
virtual void _acal_event_cancellation() {};
|
|
|
|
virtual void _acal_event_failure() {};
|
|
|
|
};
|