-
Notifications
You must be signed in to change notification settings - Fork 7
/
StateMachine.m
55 lines (51 loc) · 1.59 KB
/
StateMachine.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
classdef StateMachine < handle
%StateMachine Class just to keep track of what state we're in, how long
%etc
% In ArduPilot
% CRUISING corresponds to AUTO
% THERMALLING corresponds to LOITER
% The other flight modes are not necessarily necessary
properties(Constant)
%state;
%---------------------%
%- State indicators---%
%global searching thermaling cruising investigating
searching = 1;
thermalling= 2;
cruising = 3;
investigating_straight=4;
investigating_curve=5;
end
properties(SetAccess=protected)
state_time=-10;
printfnct;
state=1;
end
methods
function obj=StateMachine(printfnct)
obj.printfnct=printfnct;
end
function set(obj,state,time)
obj.state_time=time;
obj.state=state;
switch state
case obj.thermalling
obj.print('State THERMALLING')
case obj.searching
obj.print('State SEARCHING')
case obj.cruising
obj.print('State CRUISING')
case obj.investigating_straight
obj.print('State INVESTIGATING - straight')
case obj.investigating_curve
obj.print('State INVESTIGATING - curve')
end
end
function t=elapsed_time(obj,currenttime)
t=currenttime-obj.state_time;
end
function print(obj,message)
obj.printfnct(message);
end
end
end