Skip to content
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

Show supervisor info #682

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions src/cfclient/ui/tabs/FlightTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
import cfclient
from cfclient.ui.widgets.ai import AttitudeIndicator

from cfclient.utils.config import Config
from cflib.crazyflie.log import LogConfig

from cfclient.utils.config import Config
from cfclient.utils.input import JoystickReader

from cfclient.ui.tab_toolbox import TabToolbox
Expand Down Expand Up @@ -191,7 +191,7 @@ def __init__(self, helper):
# Supervisor
self._supervisor_info_bitfield = 0
self.armButton.clicked.connect(self.updateArm)
self._update_arm_button(False)
self._update_supervisor_and_arming(False)

self.uiSetupReady()

Expand Down Expand Up @@ -301,7 +301,7 @@ def _log_data_received(self, timestamp, data, logconf):
if self.LOG_NAME_SUPERVISOR_INFO in data:
self._supervisor_info_bitfield = data[self.LOG_NAME_SUPERVISOR_INFO]

self._update_arm_button(True)
self._update_supervisor_and_arming(True)

def _pose_data_received(self, pose_logger, pose):
if self.isVisible():
Expand Down Expand Up @@ -355,17 +355,30 @@ def _change_input_labels(self, using_hover_assist):
self.inputRollLabel.setText(roll)
self.inputYawLabel.setText(yaw)

def _update_arm_button(self, connected):
def _update_supervisor_and_arming(self, connected):
if not connected:
self.armButton.setStyleSheet("")
self.armButton.setText("Arm")
self.armButton.setEnabled(False)
self._supervisor_state.setText("")
self._supervisor_state.setStyleSheet("")
return

self._supervisor_state.setText("")
if self._is_tumbled():
self._supervisor_state.setText("Tumbled")

if self._is_locked():
self._supervisor_state.setText("Locked-please reboot")
self._supervisor_state.setStyleSheet("background-color: red")
else:
self._supervisor_state.setStyleSheet("")

if self._is_flying():
self.armButton.setEnabled(True)
self.armButton.setText("Emergency stop")
self.armButton.setStyleSheet("background-color: red")
self._supervisor_state.setText("Flying")
return

if self._is_armed():
Expand Down Expand Up @@ -434,6 +447,11 @@ def connected(self, linkURI):
# Add supervisor info if it exists to keep backwards compatibility
if self._helper.cf.log.toc.get_element_by_complete_name(self.LOG_NAME_SUPERVISOR_INFO):
lg.add_variable(self.LOG_NAME_SUPERVISOR_INFO)
# Full supervisor info available after V7, hide supervisor info for earlier versions
update_supervisor_info = self._helper.cf.platform.get_protocol_version() >= 7
self._supervisor_state.setVisible(update_supervisor_info)
self._supervisor_label1.setVisible(update_supervisor_info)
self._supervisor_label2.setVisible(update_supervisor_info)

try:
self._helper.cf.log.add_config(lg)
Expand Down Expand Up @@ -503,7 +521,7 @@ def disconnected(self, linkURI):
self._update_flight_commander(False)

self._supervisor_info_bitfield = 0
self._update_arm_button(False)
self._update_supervisor_and_arming(False)

def _can_arm(self):
return bool(self._supervisor_info_bitfield & 0x0001)
Expand All @@ -523,6 +541,9 @@ def _is_flying(self):
def _is_tumbled(self):
return bool(self._supervisor_info_bitfield & 0x0020)

def _is_locked(self):
return bool(self._supervisor_info_bitfield & 0x0040)

def minMaxThrustChanged(self):
self._helper.inputDeviceReader.min_thrust = self.minThrust.value()
self._helper.inputDeviceReader.max_thrust = self.maxThrust.value()
Expand Down Expand Up @@ -685,7 +706,7 @@ def _all_params_updated(self):
self._ring_populate_dropdown()
self._populate_assisted_mode_dropdown()
self._update_flight_commander(True)
self._update_arm_button(True)
self._update_supervisor_and_arming(True)

def _ring_populate_dropdown(self):
try:
Expand Down
Loading