-
Notifications
You must be signed in to change notification settings - Fork 13
899 add a failsafes config page #1021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1cdd4ba
e6cf58e
e03fb8c
fdfb183
d32cc93
e1ef764
36ae6aa
ccd4a31
000e88a
d179ee0
821d5bc
5798482
5ed383e
ec83fec
456e95a
bec0a23
620bc68
f924101
ef4223e
dfd61af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,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: | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the difference between getFailsafeParams and getConfig? They look like they do the same thing? |
||||||||||||||
| """ | ||||||||||||||
| Gets the gripper related parameters from the drone. | ||||||||||||||
| """ | ||||||||||||||
| self.drone.logger.debug("Fetching gripper parameters") | ||||||||||||||
|
Comment on lines
+77
to
+79
|
||||||||||||||
| Gets the gripper related parameters from the drone. | |
| """ | |
| self.drone.logger.debug("Fetching gripper parameters") | |
| Loads the failsafe-related parameters via the cached params controller. | |
| """ | |
| self.drone.logger.debug("Refreshing cached failsafe parameters") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gripper?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also update the params dict in redux when a param is set successfully so it updates on the params page as well; look at the flight modes config to see how that's done.