CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_AccelCal/AP_AccelCal.h
Views: 1798
1
#pragma once
2
3
#include <AP_HAL/AP_HAL_Boards.h>
4
#include <GCS_MAVLink/GCS_config.h>
5
6
#ifndef HAL_INS_ACCELCAL_ENABLED
7
#if HAL_GCS_ENABLED
8
#include <AP_InertialSensor/AP_InertialSensor_config.h>
9
#define HAL_INS_ACCELCAL_ENABLED AP_INERTIALSENSOR_ENABLED
10
#else
11
#define HAL_INS_ACCELCAL_ENABLED 0
12
#endif
13
#endif
14
15
#include <GCS_MAVLink/GCS_MAVLink.h>
16
#include "AccelCalibrator.h"
17
18
#define AP_ACCELCAL_MAX_NUM_CLIENTS 4
19
class GCS_MAVLINK;
20
class AP_AccelCal_Client;
21
22
class AP_AccelCal {
23
public:
24
AP_AccelCal():
25
_use_gcs_snoop(true),
26
_started(false),
27
_saving(false)
28
{ update_status(); }
29
30
// start all the registered calibrations
31
void start(GCS_MAVLINK *gcs);
32
33
// called on calibration cancellation
34
void cancel();
35
36
// Run an iteration of all registered calibrations
37
void update();
38
39
// get the status of the calibrator server as a whole
40
accel_cal_status_t get_status() { return _status; }
41
42
// Set vehicle position sent by the GCS
43
bool gcs_vehicle_position(float position);
44
45
// interface to the clients for registration
46
static void register_client(AP_AccelCal_Client* client);
47
48
#if HAL_GCS_ENABLED
49
void handle_command_ack(const mavlink_command_ack_t &packet);
50
#endif
51
52
// true if we are in a calibration process
53
bool running(void) const;
54
55
private:
56
class GCS_MAVLINK *_gcs;
57
bool _use_gcs_snoop;
58
bool _waiting_for_mavlink_ack = false;
59
uint32_t _last_position_request_ms;
60
uint8_t _step;
61
accel_cal_status_t _status;
62
accel_cal_status_t _last_result;
63
64
static uint8_t _num_clients;
65
static AP_AccelCal_Client* _clients[AP_ACCELCAL_MAX_NUM_CLIENTS];
66
67
// called on calibration success
68
void success();
69
70
// called on calibration failure
71
void fail();
72
73
// reset all the calibrators to there pre calibration stage so as to make them ready for next calibration request
74
void clear();
75
76
// proceed through the collection step for each of the registered calibrators
77
void collect_sample();
78
79
// update the state of the Accel calibrator server
80
void update_status();
81
82
// checks if no new sample has been received for considerable amount of time
83
bool check_for_timeout();
84
85
// check if client's calibrator is active
86
bool client_active(uint8_t client_num);
87
88
bool _started;
89
bool _saving;
90
91
uint8_t _num_active_calibrators;
92
93
AccelCalibrator* get_calibrator(uint8_t i);
94
};
95
96
class AP_AccelCal_Client {
97
friend class AP_AccelCal;
98
private:
99
// getters
100
virtual bool _acal_get_saving() { return false; }
101
virtual bool _acal_get_ready_to_sample() { return true; }
102
virtual bool _acal_get_fail() { return false; }
103
virtual AccelCalibrator* _acal_get_calibrator(uint8_t instance) = 0;
104
105
// events
106
virtual void _acal_save_calibrations() = 0;
107
virtual void _acal_event_success() {};
108
virtual void _acal_event_cancellation() {};
109
virtual void _acal_event_failure() {};
110
};
111
112