Path: blob/master/libraries/AP_AccelCal/AP_AccelCal.h
9559 views
#pragma once12#include <AP_HAL/AP_HAL_Boards.h>3#include <GCS_MAVLink/GCS_config.h>45#ifndef HAL_INS_ACCELCAL_ENABLED6#if HAL_GCS_ENABLED7#include <AP_InertialSensor/AP_InertialSensor_config.h>8#define HAL_INS_ACCELCAL_ENABLED AP_INERTIALSENSOR_ENABLED9#else10#define HAL_INS_ACCELCAL_ENABLED 011#endif12#endif1314#include <GCS_MAVLink/GCS_MAVLink.h>15#include "AccelCalibrator.h"1617#define AP_ACCELCAL_MAX_NUM_CLIENTS 418class GCS_MAVLINK;19class AP_AccelCal_Client;2021class AP_AccelCal {22public:23AP_AccelCal():24_use_gcs_snoop(true),25_started(false),26_saving(false)27{ update_status(); }2829// start all the registered calibrations30void start(GCS_MAVLINK *gcs, uint8_t sysid, uint8_t compid);3132// called on calibration cancellation33void cancel();3435// Run an iteration of all registered calibrations36void update();3738// get the status of the calibrator server as a whole39accel_cal_status_t get_status() { return _status; }4041// Set vehicle position sent by the GCS42bool gcs_vehicle_position(float position);4344// interface to the clients for registration45static void register_client(AP_AccelCal_Client* client);4647#if HAL_GCS_ENABLED48void handle_command_ack(const mavlink_command_ack_t &packet, uint8_t src_sysid, uint8_t src_compid);49#endif5051// true if we are in a calibration process52bool running(void) const;5354private:55class GCS_MAVLINK *_gcs;56uint8_t _sysid;57uint8_t _compid;58bool _use_gcs_snoop;59bool _waiting_for_mavlink_ack = false;60uint32_t _last_position_request_ms;61uint8_t _step;62accel_cal_status_t _status;63accel_cal_status_t _last_result;6465static uint8_t _num_clients;66static AP_AccelCal_Client* _clients[AP_ACCELCAL_MAX_NUM_CLIENTS];6768// called on calibration success69void success();7071// called on calibration failure72void fail();7374// reset all the calibrators to there pre calibration stage so as to make them ready for next calibration request75void clear();7677// proceed through the collection step for each of the registered calibrators78void collect_sample();7980// update the state of the Accel calibrator server81void update_status();8283// checks if no new sample has been received for considerable amount of time84bool check_for_timeout();8586// check if client's calibrator is active87bool client_active(uint8_t client_num);8889bool _started;90bool _saving;9192uint8_t _num_active_calibrators;9394AccelCalibrator* get_calibrator(uint8_t i);95};9697class AP_AccelCal_Client {98friend class AP_AccelCal;99private:100// getters101virtual bool _acal_get_saving() { return false; }102virtual bool _acal_get_ready_to_sample() { return true; }103virtual bool _acal_get_fail() { return false; }104virtual AccelCalibrator* _acal_get_calibrator(uint8_t instance) = 0;105106// events107virtual void _acal_save_calibrations() = 0;108virtual void _acal_event_success() {};109virtual void _acal_event_cancellation() {};110virtual void _acal_event_failure() {};111};112113114