-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathfailsafeController.py
More file actions
81 lines (64 loc) · 2.17 KB
/
failsafeController.py
File metadata and controls
81 lines (64 loc) · 2.17 KB
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
72
73
74
75
76
77
78
79
80
81
from __future__ import annotations
from typing import TYPE_CHECKING
from app.customTypes import Number, VehicleType
if TYPE_CHECKING:
from app.drone import Drone
COMMON_FAILSAFE_PARAMS = [
"BATT_LOW_VOLT",
"BATT_LOW_MAH",
"BATT_FS_LOW_ACT",
"BATT_CRT_VOLT",
"BATT_CRT_MAH",
"BATT_FS_CRT_ACT",
]
COPTER_FS_PARAMS = [
"FS_THR_ENABLE",
"RC_FS_TIMEOUT",
"FS_GCS_TIMEOUT",
"FS_GCS_ENABLE",
"FS_EKF_THRESH",
"FS_EKF_ACTION",
]
PLANE_FS_PARAMS = [
"THR_FS_VALUE",
"THR_FAILSAFE",
"FS_GCS_ENABL",
"FS_SHORT_ACTN",
"FS_LONG_ACTN",
"FS_SHORT_TIMEOUT",
"FS_LONG_TIMEOUT",
]
class FailsafeController:
def __init__(self, drone: Drone) -> None:
self.drone = drone
self.params: dict = {}
self.valid_params = []
if self.drone.aircraft_type == VehicleType.FIXED_WING.value:
self.valid_params = COMMON_FAILSAFE_PARAMS + PLANE_FS_PARAMS
if self.drone.aircraft_type == VehicleType.MULTIROTOR.value:
self.valid_params = COMMON_FAILSAFE_PARAMS + COPTER_FS_PARAMS
self.getFailsafeParams()
def getConfig(self):
config = {}
for param in self.valid_params:
self.params[param] = self.drone.paramsController.getSingleParam(param)
config[param] = self.params[param].get("param_value", "UNKNOWN")
return config
def setFailsafeParam(self, param_id: str, value: Number) -> bool:
"""
Sets a failsafe related parameter on the drone.
"""
if param_id not in self.valid_params:
self.drone.logger.error(
f"Parameter {param_id} is not a valid failsafe parameter"
)
return False
param_type = self.params.get(param_id, {}).get("param_type", None)
return self.drone.paramsController.setParam(param_id, value, param_type)
def getFailsafeParams(self) -> None:
"""
Gets the gripper related parameters from the drone.
"""
self.drone.logger.debug("Fetching gripper parameters")
for param in self.valid_params:
self.params[param] = self.drone.paramsController.getSingleParam(param)