2016-02-17 21:25:11 -04:00
|
|
|
#pragma once
|
2015-10-16 18:51:16 -03:00
|
|
|
|
|
|
|
#include <GCS_MAVLink/GCS_MAVLink.h>
|
|
|
|
#include "AccelCalibrator.h"
|
|
|
|
|
|
|
|
#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);
|
|
|
|
|
2019-04-30 07:22:47 -03:00
|
|
|
void handleMessage(const mavlink_message_t &msg);
|
2018-03-17 03:56:57 -03: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);
|
|
|
|
void _printf(const char*, ...);
|
|
|
|
};
|
|
|
|
|
|
|
|
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() {};
|
|
|
|
};
|