-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathP_Brake_StateMachine.lua
71 lines (57 loc) · 2.46 KB
/
P_Brake_StateMachine.lua
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
------------------------------------------------------------
-------- P_Brake_StateMachine ArduPilot Lua script ---------
-- --
-- Sets a parking brake servo based on arm/disarm and --
-- flight mode states. --
-- --
--------------------- Yuri -- Aug 2021 ---------------------
------------------------------------------------------------
-------- USER EDITABLE GLOBALS --------
local BRAKE_SERVO_FN = 95
local BRAKE_OFF_PWM = 1000
local BRAKE_ON_PWM = 2045
local ENGAGE_TIMEOUT = 2000 -- (ms) how long to wait before engaging parking brake
local FREQUENCY = 250 -- (ms) how often to run this script (100 to 250 works well)
local VERBOSE_MODE = 2 -- 0 to suppress all GCS messages, 1 for status updates, 2 for additional debug messages
-------- END USER EDITABLE GLOBALS --------
-------- "CONSTANTS" --------
local ROVER_MODE_HOLD = 4
-------- END "CONSTANTS" --------
function brake_off()
if not arming:is_armed() then
return brake_engage, ENGAGE_TIMEOUT
end
if vehicle:get_mode() == ROVER_MODE_HOLD then
return brake_engage, ENGAGE_TIMEOUT
end
return brake_off, FREQUENCY
end
function brake_on()
if arming:is_armed() and vehicle:get_mode() ~= ROVER_MODE_HOLD then
return brake_disengage, 0
end
return brake_on, FREQUENCY
end
function brake_engage()
if not arming:is_armed() then
SRV_Channels:set_output_pwm(BRAKE_SERVO_FN, BRAKE_ON_PWM)
if (VERBOSE_MODE > 0) then gcs:send_text(4, "Parking Brake: On") end
return brake_on, FREQUENCY
end
if vehicle:get_mode() == ROVER_MODE_HOLD then
SRV_Channels:set_output_pwm(BRAKE_SERVO_FN, BRAKE_ON_PWM)
if (VERBOSE_MODE > 0) then gcs:send_text(4, "Parking Brake: On") end
return brake_on, FREQUENCY
end
return brake_off, FREQUENCY
end
function brake_disengage()
if arming:is_armed() and vehicle:get_mode() ~= ROVER_MODE_HOLD then
SRV_Channels:set_output_pwm(BRAKE_SERVO_FN, BRAKE_OFF_PWM)
if (VERBOSE_MODE > 0) then gcs:send_text(4, "Parking Brake: Off") end
return brake_off, FREQUENCY
end
return brake_on, FREQUENCY
end
if (VERBOSE_MODE > 1) then gcs:send_text(6, "Parking Brake State Machine: Active") end
return brake_off, FREQUENCY