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/Blimp/Fins.h
Views: 1798
1
//This class converts horizontal acceleration commands to fin flapping commands.
2
#pragma once
3
#include <AP_Notify/AP_Notify.h>
4
5
extern const AP_HAL::HAL& hal;
6
7
#define NUM_FINS 4 //Current maximum number of fins that can be added.
8
#define RC_SCALE 1000
9
class Fins
10
{
11
public:
12
friend class Blimp;
13
friend class Loiter;
14
15
enum motor_frame_class {
16
MOTOR_FRAME_UNDEFINED = 0,
17
MOTOR_FRAME_AIRFISH = 1,
18
};
19
enum motor_frame_type {
20
MOTOR_FRAME_TYPE_AIRFISH = 1,
21
};
22
23
//constructor
24
Fins(uint16_t loop_rate);
25
26
// var_info for holding Parameter information
27
static const struct AP_Param::GroupInfo var_info[];
28
29
bool initialised_ok() const
30
{
31
return true;
32
}
33
34
void armed(bool arm)
35
{
36
if (arm != _armed) {
37
_armed = arm;
38
AP_Notify::flags.armed = arm;
39
}
40
41
}
42
bool armed() const
43
{
44
return _armed;
45
}
46
47
protected:
48
// internal variables
49
const uint16_t _loop_rate; // rate in Hz at which output() function is called (normally 400hz)
50
uint16_t _speed_hz; // speed in hz to send updates to motors
51
float _throttle_avg_max; // last throttle input from set_throttle_avg_max
52
53
float _time; // current timestamp
54
55
bool _armed; // 0 if disarmed, 1 if armed
56
57
float _amp[NUM_FINS]; //amplitudes
58
float _off[NUM_FINS]; //offsets
59
float _freq[NUM_FINS]; //frequency multiplier
60
float _pos[NUM_FINS]; //servo positions
61
62
float _right_amp_factor[NUM_FINS];
63
float _front_amp_factor[NUM_FINS];
64
float _down_amp_factor[NUM_FINS];
65
float _yaw_amp_factor[NUM_FINS];
66
67
float _right_off_factor[NUM_FINS];
68
float _front_off_factor[NUM_FINS];
69
float _down_off_factor[NUM_FINS];
70
float _yaw_off_factor[NUM_FINS];
71
72
int8_t _num_added;
73
74
//MIR This should probably become private in future.
75
public:
76
float right_out; //input right movement, negative for left, +1 to -1
77
float front_out; //input front/forwards movement, negative for backwards, +1 to -1
78
float yaw_out; //input yaw, +1 to -1
79
float down_out; //input height control, +1 to -1
80
81
AP_Float freq_hz;
82
AP_Int8 turbo_mode;
83
84
bool _interlock; // 1 if the motor interlock is enabled (i.e. motors run), 0 if disabled (motors don't run)
85
bool _initialised_ok; // 1 if initialisation was successful
86
87
void output_min();
88
89
void add_fin(int8_t fin_num, float right_amp_fac, float front_amp_fac, float yaw_amp_fac, float down_amp_fac,
90
float right_off_fac, float front_off_fac, float yaw_off_fac, float down_off_fac);
91
92
void setup_fins();
93
94
void output();
95
96
float get_throttle()
97
{
98
//Only for Mavlink - essentially just an indicator of how hard the fins are working.
99
//Note that this is the unconstrained version, so if the higher level control gives too high input,
100
//throttle will be displayed as more than 100.
101
return fmaxf(fmaxf(fabsf(down_out),fabsf(front_out)), fmaxf(fabsf(right_out),fabsf(yaw_out)));
102
}
103
104
void rc_write(uint8_t chan, uint16_t pwm);
105
};
106
107