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/AC_CustomControl/AC_CustomControl.h
Views: 1798
1
#pragma once
2
3
/// @file AC_CustomControl.h
4
/// @brief ArduCopter custom control library
5
6
#include "AC_CustomControl_config.h"
7
8
#if AP_CUSTOMCONTROL_ENABLED
9
10
#include <AP_Common/AP_Common.h>
11
#include <AP_Param/AP_Param.h>
12
#include <AP_AHRS/AP_AHRS_View.h>
13
#include <AC_AttitudeControl/AC_AttitudeControl.h>
14
#include <AP_Motors/AP_MotorsMulticopter.h>
15
16
#ifndef CUSTOMCONTROL_MAX_TYPES
17
#define CUSTOMCONTROL_MAX_TYPES 2
18
#endif
19
20
class AC_CustomControl_Backend;
21
22
class AC_CustomControl {
23
public:
24
AC_CustomControl(AP_AHRS_View*& ahrs, AC_AttitudeControl*& _att_control, AP_MotorsMulticopter*& motors, float dt);
25
26
CLASS_NO_COPY(AC_CustomControl); /* Do not allow copies */
27
28
void init(void);
29
void update(void);
30
void motor_set(Vector3f motor_out);
31
void set_custom_controller(bool enabled);
32
void reset_main_att_controller(void);
33
bool is_safe_to_run(void);
34
void log_switch(void);
35
36
// set the PID notch sample rates
37
void set_notch_sample_rate(float sample_rate);
38
39
// zero index controller type param, only use it to access _backend or _backend_var_info array
40
uint8_t get_type() { return _controller_type > 0 ? (_controller_type - 1) : 0; };
41
42
// User settable parameters
43
static const struct AP_Param::GroupInfo var_info[];
44
static const struct AP_Param::GroupInfo *_backend_var_info[CUSTOMCONTROL_MAX_TYPES];
45
46
protected:
47
// add custom controller here
48
enum class CustomControlType : uint8_t {
49
CONT_NONE = 0,
50
CONT_EMPTY = 1,
51
CONT_PID = 2,
52
}; // controller that should be used
53
54
enum class CustomControlOption {
55
ROLL = 1 << 0,
56
PITCH = 1 << 1,
57
YAW = 1 << 2,
58
};
59
60
// Intersampling period in seconds
61
float _dt;
62
bool _custom_controller_active;
63
64
// References to external libraries
65
AP_AHRS_View*& _ahrs;
66
AC_AttitudeControl*& _att_control;
67
AP_MotorsMulticopter*& _motors;
68
69
AP_Enum<CustomControlType> _controller_type;
70
AP_Int8 _custom_controller_mask;
71
72
private:
73
AC_CustomControl_Backend *_backend;
74
};
75
76
#endif // AP_CUSTOMCONTROL_ENABLED
77
78