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/Tools/simulink/arducopter/functions/ModeConfig.m
Views: 1799
1
% This class provides important setting information for the flight modes
2
% that have been chosen for the SID process.
3
%
4
% Fabian Bredemeier - IAV GmbH
5
% License: GPL v3
6
7
classdef ModeConfig
8
properties
9
name = '';
10
mode_num;
11
thr_man;
12
filter_msgs = {};
13
end
14
15
methods
16
% Constructor
17
function obj = ModeConfig(mode_num)
18
props = ModeConfig.getModeProps(mode_num);
19
obj.name = props.name;
20
obj.mode_num = mode_num;
21
obj.thr_man = props.thr_man;
22
obj.filter_msgs = props.filter_msgs;
23
end
24
25
% Function that returns index of mode properties that corresponds to
26
% the mode number
27
function modeIndex = getIndexFromModeNum(obj, modeNum)
28
for i=1:length(obj.names)
29
if (obj.mode_num_list(i) == modeNum)
30
modeIndex = i;
31
break;
32
end
33
end
34
end
35
36
function filter_msgs = get_filter_msgs(obj)
37
filter_msgs = obj.filter_msgs;
38
end
39
40
function thr_man = get_thr_man(obj)
41
thr_man = obj.thr_man;
42
end
43
44
function name = get_name(obj)
45
name = obj.name;
46
end
47
48
% Function to compare properties to another ModeConfig object
49
function identical = compare_to(obj, obj2)
50
% Name
51
if strcmp(obj.name, obj2.get_name()) ~= 1
52
identical = false;
53
return;
54
end
55
% Throttle Man
56
if obj.thr_man ~= obj2.get_thr_man
57
identical = false;
58
return;
59
end
60
% Filter message list
61
if numel(obj.filter_msgs) ~= numel(obj2.get_filter_msgs())
62
identical = false;
63
return;
64
end
65
for i=1:numel(obj.filter_msgs)
66
obj2_filter_msgs = obj2.get_filter_msgs();
67
if strcmp(obj.filter_msgs{i}, obj2_filter_msgs{i}) ~= 1
68
identical = false;
69
return;
70
end
71
end
72
identical = true;
73
end
74
end
75
76
methods (Static)
77
78
% Function that stores all mode properties
79
function propsStruct = getModeProps(modeNum)
80
% Define basic filter message cell array which is necessary for
81
% only the inner loop or the part that is used in SYSID
82
% respectively. Used for modes whose relevant msgs are not yet
83
% clear.
84
filter_msgs_sysid = {'FMT', 'UNIT', 'FMTU', 'MULT', 'PARM', 'MODE', 'SIDD', ...
85
'SIDS', 'ATT', 'CTRL', 'RATE', 'PIDR', 'PIDP', 'PIDY', 'CTUN', ...
86
'IMU','BAT', 'BARO', 'MOTB'};
87
% Filter message cell array which is necessary to run simulation
88
% in loiter mode
89
filter_msgs_loiter = {'FMT', 'UNIT', 'FMTU', 'MULT', 'PARM', 'MODE', ...
90
'ATT', 'CTRL', 'RATE', 'PIDR', 'PIDP', 'PIDY', 'PIDA', 'CTUN', ...
91
'IMU', 'BAT', 'BARO', 'MOTB', 'PSCD', 'PSCE', 'PSCN', 'RCIN'};
92
% Stabilize
93
filter_msgs_stabilize = {'FMT', 'UNIT', 'FMTU', 'MULT', 'PARM', 'MODE', ...
94
'ATT', 'CTRL', 'RATE', 'PIDR', 'PIDP', 'PIDY', 'PIDA', 'CTUN', ...
95
'IMU', 'BAT', 'BARO', 'MOTB', 'GYR', 'ACC', 'RCIN'};
96
% Acro
97
filter_msgs_acro = {'FMT', 'UNIT', 'FMTU', 'MULT', 'PARM', 'MODE', ...
98
'ATT', 'CTRL', 'RATE', 'PIDR', 'PIDP', 'PIDY', 'PIDA', 'CTUN', ...
99
'IMU', 'BAT', 'BARO', 'MOTB', 'GYR', 'ACC'};
100
% AltHold
101
filter_msgs_althold = {'FMT', 'UNIT', 'FMTU', 'MULT', 'PARM', 'MODE', ...
102
'ATT', 'CTRL', 'RATE', 'PIDR', 'PIDP', 'PIDY', 'PIDA', 'CTUN', ...
103
'IMU', 'BAT', 'BARO', 'MOTB', 'PSCD', 'GYR', 'ACC', 'RCIN'};
104
switch modeNum
105
case 0 % Stabilize
106
propsStruct.name = 'Stabilize';
107
propsStruct.thr_man = true;
108
propsStruct.filter_msgs = filter_msgs_stabilize;
109
case 1 % Acro
110
propsStruct.name = 'Acro';
111
propsStruct.thr_man = true;
112
propsStruct.filter_msgs = filter_msgs_acro;
113
case 2 % Alt_Hold
114
propsStruct.name = 'Alt_Hold';
115
propsStruct.thr_man = false;
116
propsStruct.filter_msgs = filter_msgs_althold;
117
case 3 % Auto
118
propsStruct.name = 'Auto';
119
propsStruct.thr_man = false;
120
propsStruct.filter_msgs = filter_msgs_loiter;
121
case 4 % Guided
122
propsStruct.name = 'Guided';
123
propsStruct.thr_man = false;
124
propsStruct.filter_msgs = filter_msgs_loiter;
125
case 5 % Loiter
126
propsStruct.name = 'Loiter';
127
propsStruct.thr_man = false;
128
propsStruct.filter_msgs = filter_msgs_loiter;
129
case 6 % RTL
130
propsStruct.name = 'RTL';
131
propsStruct.thr_man = false;
132
propsStruct.filter_msgs = filter_msgs_sysid;
133
case 7 % Circle
134
propsStruct.name = 'Circle';
135
propsStruct.thr_man = false;
136
propsStruct.filter_msgs = filter_msgs_sysid;
137
case 9 % Land
138
propsStruct.name = 'Land';
139
propsStruct.thr_man = false;
140
propsStruct.filter_msgs = filter_msgs_sysid;
141
case 11 % Drift
142
propsStruct.name = 'Drift';
143
propsStruct.thr_man = false;
144
propsStruct.filter_msgs = filter_msgs_sysid;
145
case 13 % Sport
146
propsStruct.name = 'Sport';
147
propsStruct.thr_man = false;
148
propsStruct.filter_msgs = filter_msgs_sysid;
149
case 14 % Flip
150
propsStruct.name = 'Flip';
151
propsStruct.thr_man = false;
152
propsStruct.filter_msgs = filter_msgs_sysid;
153
case 15 % Autotune
154
propsStruct.name = 'Autotune';
155
propsStruct.thr_man = false;
156
propsStruct.filter_msgs = filter_msgs_stabilize;
157
case 16 % Poshold
158
propsStruct.name = 'Poshold';
159
propsStruct.thr_man = false;
160
propsStruct.filter_msgs = filter_msgs_sysid;
161
case 17 % Brake
162
propsStruct.name = 'Brake';
163
propsStruct.thr_man = false;
164
propsStruct.filter_msgs = filter_msgs_sysid;
165
case 18 % Throw
166
propsStruct.name = 'Throw';
167
propsStruct.thr_man = false;
168
propsStruct.filter_msgs = filter_msgs_sysid;
169
case 19 % Avoid_ADSB
170
propsStruct.name = 'Avoid_ADSB';
171
propsStruct.thr_man = false;
172
propsStruct.filter_msgs = filter_msgs_sysid;
173
case 20 % Guided_NoGPS
174
propsStruct.name = 'Guided_NoGPS';
175
propsStruct.thr_man = false;
176
propsStruct.filter_msgs = filter_msgs_sysid;
177
case 21 % SmartRTL
178
propsStruct.name = 'SmartRTL';
179
propsStruct.thr_man = false;
180
propsStruct.filter_msgs = filter_msgs_sysid;
181
case 22 % Flowhold
182
propsStruct.name = 'Flowhold';
183
propsStruct.thr_man = false;
184
propsStruct.filter_msgs = filter_msgs_sysid;
185
case 23 % Follow
186
propsStruct.name = 'Follow';
187
propsStruct.thr_man = false;
188
propsStruct.filter_msgs = filter_msgs_sysid;
189
case 24 % Zigzag
190
propsStruct.name = 'Zigzag';
191
propsStruct.thr_man = false;
192
propsStruct.filter_msgs = filter_msgs_sysid;
193
case 25 % Systemid
194
propsStruct.name = 'Systemid';
195
propsStruct.thr_man = true;
196
propsStruct.filter_msgs = filter_msgs_sysid;
197
case 26 % Autorotate
198
propsStruct.name = 'Autorotate';
199
propsStruct.thr_man = false;
200
propsStruct.filter_msgs = filter_msgs_sysid;
201
end
202
end
203
end
204
end
205