From 203cb6b8feb9ba8e695a1dec4f3e85d07d3fe68f Mon Sep 17 00:00:00 2001 From: knmcguire Date: Thu, 11 Aug 2022 16:19:49 +0200 Subject: [PATCH 1/6] hide labels based on basestation availability param --- .../dialogs/lighthouse_system_type_dialog.py | 12 +++++-- src/cfclient/ui/tabs/lighthouse_tab.py | 31 ++++++++++++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/cfclient/ui/dialogs/lighthouse_system_type_dialog.py b/src/cfclient/ui/dialogs/lighthouse_system_type_dialog.py index 2e3be0bee7..9a56630255 100644 --- a/src/cfclient/ui/dialogs/lighthouse_system_type_dialog.py +++ b/src/cfclient/ui/dialogs/lighthouse_system_type_dialog.py @@ -50,19 +50,24 @@ class LighthouseSystemTypeDialog(QtWidgets.QWidget, lighthouse_system_widget_cla VALUE_V1 = 1 VALUE_V2 = 2 - def __init__(self, helper, *args): + def __init__(self, helper, ready_cb, *args): super(LighthouseSystemTypeDialog, self).__init__(*args) self.setupUi(self) + self.ready_cb = ready_cb self._helper = helper - self._close_button.clicked.connect(self.close) + self._close_button.clicked.connect(self.close_button_clicked) self._radio_btn_v1.toggled.connect(self._type_toggled) self._radio_btn_v2.toggled.connect(self._type_toggled) self._curr_type = 0 + def close_button_clicked(self): + self.ready_cb(True) + self.close() + def get_system_type(self): system_type = self.VALUE_V2 @@ -91,3 +96,6 @@ def _type_toggled(self, *args): if new_type != self._curr_type: self._curr_type = new_type self._helper.cf.param.set_value(self.PARAM_GROUP + '.' + self.PARAM_NAME, self._curr_type) + + + diff --git a/src/cfclient/ui/tabs/lighthouse_tab.py b/src/cfclient/ui/tabs/lighthouse_tab.py index 296a56c0c3..01872d3191 100644 --- a/src/cfclient/ui/tabs/lighthouse_tab.py +++ b/src/cfclient/ui/tabs/lighthouse_tab.py @@ -288,6 +288,8 @@ class LighthouseTab(TabToolbox, lighthouse_tab_class): _new_system_config_written_to_cf_signal = pyqtSignal(bool) _geometry_read_signal = pyqtSignal(object) _calibration_read_signal = pyqtSignal(object) + _system_type_changed_signal = pyqtSignal(object) + def __init__(self, helper): super(LighthouseTab, self).__init__(helper, 'Lighthouse Positioning') @@ -302,6 +304,7 @@ def __init__(self, helper): self._new_system_config_written_to_cf_signal.connect(self._new_system_config_written_to_cf) self._geometry_read_signal.connect(self._geometry_read_cb) self._calibration_read_signal.connect(self._calibration_read_cb) + self._system_type_changed_signal.connect(self._system_type_changed_cb) # Connect the Crazyflie API callbacks to the signals self._helper.cf.connected.add_callback(self._connected_signal.emit) @@ -342,7 +345,7 @@ def __init__(self, helper): self._basestation_geometry_dialog = LighthouseBsGeometryDialog(self) self._basestation_mode_dialog = LighthouseBsModeDialog(self) - self._system_type_dialog = LighthouseSystemTypeDialog(helper) + self._system_type_dialog = LighthouseSystemTypeDialog(helper, self._system_type_changed_signal.emit) self._manage_estimate_geometry_button.clicked.connect(self._show_basestation_geometry_dialog) self._change_system_type_button.clicked.connect(lambda: self._system_type_dialog.show()) @@ -432,6 +435,9 @@ def _geometry_read_cb(self, geometries): self._basestation_geometry_dialog.geometry_updated(self._lh_geos) self._is_geometry_read_ongoing = False + def _system_type_changed_cb(self): + self._update_basestation_status_indicators() + def _is_matching_current_geo_data(self, geometries): return geometries == self._lh_geos.keys() @@ -445,6 +451,8 @@ def _adjust_bitmask(self, bit_mask, bs_list): def _status_report_received(self, timestamp, data, logconf): """Callback from the logging system when the status is updated.""" + bs_available_mask = int(self._helper.cf.param.get_value('lighthouse.bsAvailable')) + self._mask_status_matrix(bs_available_mask) if self.LOG_RECEIVE in data: bit_mask = data[self.LOG_RECEIVE] @@ -608,6 +616,24 @@ def _populate_status_matrix(self, bs_available_mask): for i in range(1, 5): container.addWidget(self._create_label(), i, bs + 1) + + def _mask_status_matrix(self, bs_available_mask): + container = self._basestation_stats_container + + # Find the nr of base stations by looking for the highest bit that is set + # Assume all bs up to that bit are available + for bs in range(0, 16): + bs_available = bs_available_mask & (1 << bs) + bs_indicator_id = bs + 1 + for stats_indicator_id in range(1, 5): + item = container.itemAtPosition(stats_indicator_id, bs_indicator_id) + if item is not None: + label = item.widget() + if bs_available: + label.setHidden(False) + else: + label.setHidden(True) + def _create_label(self, text=None): label = QLabel() label.setMinimumSize(30, 0) @@ -625,6 +651,9 @@ def _update_basestation_status_indicators(self): """Handling the basestation status label handles to indicate the state of received data per basestation""" container = self._basestation_stats_container + + bs_available_mask = int(self._helper.cf.param.get_value('lighthouse.bsAvailable')) + self._mask_status_matrix(bs_available_mask) # Ports the label number to the first index of the statistic id stats_id_port = {1: 0, 2: 1, 3: 4, 4: 5} From 0df1f7fd524189578ead10e7a88b6d1024420eee Mon Sep 17 00:00:00 2001 From: knmcguire Date: Mon, 15 Aug 2022 11:08:48 +0200 Subject: [PATCH 2/6] mask indicators based on available basestations --- src/cfclient/ui/tabs/lighthouse_tab.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/cfclient/ui/tabs/lighthouse_tab.py b/src/cfclient/ui/tabs/lighthouse_tab.py index 01872d3191..6ebebf0e03 100644 --- a/src/cfclient/ui/tabs/lighthouse_tab.py +++ b/src/cfclient/ui/tabs/lighthouse_tab.py @@ -280,6 +280,7 @@ class LighthouseTab(TabToolbox, lighthouse_tab_class): LOG_CALIBRATION_UPDATED = "lighthouse.bsCalUd" LOG_GEOMETERY_EXISTS = "lighthouse.bsGeoVal" LOG_ACTIVE = "lighthouse.bsActive" + LOG_AVAILABLE = "lighthouse.bsAvailable" _connected_signal = pyqtSignal(str) _disconnected_signal = pyqtSignal(str) @@ -325,6 +326,7 @@ def __init__(self, helper): self._bs_calibration_data_updated = set() self._bs_geometry_data_exists = set() self._bs_data_to_estimator = set() + self._bs_available = set() self._clear_state_indicator() @@ -334,7 +336,8 @@ def __init__(self, helper): self._bs_calibration_data_confirmed, self._bs_calibration_data_updated, self._bs_geometry_data_exists, - self._bs_data_to_estimator] + self._bs_data_to_estimator, + self._bs_available] self._lh_status = self.STATUS_NOT_RECEIVING @@ -403,7 +406,7 @@ def _lighthouse_deck_detected(self): self._register_logblock( "lhStatus", [self.LOG_STATUS, self.LOG_RECEIVE, self.LOG_CALIBRATION_EXISTS, self.LOG_CALIBRATION_CONFIRMED, - self.LOG_CALIBRATION_UPDATED, self.LOG_GEOMETERY_EXISTS, self.LOG_ACTIVE], + self.LOG_CALIBRATION_UPDATED, self.LOG_GEOMETERY_EXISTS, self.LOG_ACTIVE, self.LOG_AVAILABLE], self._status_report_signal.emit, self._log_error_signal.emit) except KeyError as e: @@ -451,8 +454,6 @@ def _adjust_bitmask(self, bit_mask, bs_list): def _status_report_received(self, timestamp, data, logconf): """Callback from the logging system when the status is updated.""" - bs_available_mask = int(self._helper.cf.param.get_value('lighthouse.bsAvailable')) - self._mask_status_matrix(bs_available_mask) if self.LOG_RECEIVE in data: bit_mask = data[self.LOG_RECEIVE] @@ -479,6 +480,10 @@ def _status_report_received(self, timestamp, data, logconf): if self.LOG_STATUS in data: self._lh_status = data[self.LOG_STATUS] + if self.LOG_AVAILABLE in data: + bit_mask = data[self.LOG_AVAILABLE] + self._adjust_bitmask(bit_mask, self._bs_available) + self._update_basestation_status_indicators() def _disconnected(self, link_uri): @@ -530,6 +535,7 @@ def _update_graphics(self): self._plot_3d.update_base_station_visibility(self._bs_data_to_estimator) self._update_position_label(self._helper.pose_logger.position) self._update_status_label(self._lh_status) + self._mask_status_matrix(self._bs_available) def _update_ui(self): enabled = self._is_connected and self.is_lighthouse_deck_active @@ -623,13 +629,12 @@ def _mask_status_matrix(self, bs_available_mask): # Find the nr of base stations by looking for the highest bit that is set # Assume all bs up to that bit are available for bs in range(0, 16): - bs_available = bs_available_mask & (1 << bs) bs_indicator_id = bs + 1 - for stats_indicator_id in range(1, 5): + for stats_indicator_id in range(0, 5): item = container.itemAtPosition(stats_indicator_id, bs_indicator_id) if item is not None: label = item.widget() - if bs_available: + if bs_indicator_id - 1 in bs_available_mask: label.setHidden(False) else: label.setHidden(True) @@ -651,9 +656,6 @@ def _update_basestation_status_indicators(self): """Handling the basestation status label handles to indicate the state of received data per basestation""" container = self._basestation_stats_container - - bs_available_mask = int(self._helper.cf.param.get_value('lighthouse.bsAvailable')) - self._mask_status_matrix(bs_available_mask) # Ports the label number to the first index of the statistic id stats_id_port = {1: 0, 2: 1, 3: 4, 4: 5} From 8e53842746eaf77cb1ba21bbb69f9723ec94ff85 Mon Sep 17 00:00:00 2001 From: knmcguire Date: Mon, 15 Aug 2022 11:12:33 +0200 Subject: [PATCH 3/6] remove initial indicater population --- src/cfclient/ui/tabs/lighthouse_tab.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/cfclient/ui/tabs/lighthouse_tab.py b/src/cfclient/ui/tabs/lighthouse_tab.py index 6ebebf0e03..abe01f4a0f 100644 --- a/src/cfclient/ui/tabs/lighthouse_tab.py +++ b/src/cfclient/ui/tabs/lighthouse_tab.py @@ -414,14 +414,7 @@ def _lighthouse_deck_detected(self): except AttributeError as e: logger.warning(str(e)) - try: - bs_available_mask = int(self._helper.cf.param.get_value('lighthouse.bsAvailable')) - except KeyError as e: - # Old firmware that does not support lighthouse.bsAvailable, set to bs 1 and 2 for backwards - # compatibility - bs_available_mask = 0x3 - logger.warning(str(e)) - self._populate_status_matrix(bs_available_mask) + self._populate_status_matrix() # Now that we know we have a lighthouse deck, setup the memory helper and config writer self._lh_memory_helper = LighthouseMemHelper(self._helper.cf) @@ -609,15 +602,12 @@ def _rpy_to_rot(self, rpy): return np.array(r) - def _populate_status_matrix(self, bs_available_mask): + def _populate_status_matrix(self): container = self._basestation_stats_container # Find the nr of base stations by looking for the highest bit that is set # Assume all bs up to that bit are available for bs in range(0, 16): - if bs_available_mask & (1 << bs) == 0: - break - container.addWidget(self._create_label(str(bs + 1)), 0, bs + 1) for i in range(1, 5): container.addWidget(self._create_label(), i, bs + 1) From ead30f432a0ed449608062319af9bf3d491a978a Mon Sep 17 00:00:00 2001 From: knmcguire Date: Mon, 15 Aug 2022 11:13:54 +0200 Subject: [PATCH 4/6] flake8 --- src/cfclient/ui/tabs/lighthouse_tab.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/cfclient/ui/tabs/lighthouse_tab.py b/src/cfclient/ui/tabs/lighthouse_tab.py index abe01f4a0f..063b124003 100644 --- a/src/cfclient/ui/tabs/lighthouse_tab.py +++ b/src/cfclient/ui/tabs/lighthouse_tab.py @@ -291,7 +291,6 @@ class LighthouseTab(TabToolbox, lighthouse_tab_class): _calibration_read_signal = pyqtSignal(object) _system_type_changed_signal = pyqtSignal(object) - def __init__(self, helper): super(LighthouseTab, self).__init__(helper, 'Lighthouse Positioning') self.setupUi(self) @@ -612,7 +611,6 @@ def _populate_status_matrix(self): for i in range(1, 5): container.addWidget(self._create_label(), i, bs + 1) - def _mask_status_matrix(self, bs_available_mask): container = self._basestation_stats_container From 2cf59c3d77706dde697a943f01c951da43df29be Mon Sep 17 00:00:00 2001 From: knmcguire Date: Mon, 15 Aug 2022 12:01:36 +0200 Subject: [PATCH 5/6] flake8 --- src/cfclient/ui/dialogs/lighthouse_system_type_dialog.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/cfclient/ui/dialogs/lighthouse_system_type_dialog.py b/src/cfclient/ui/dialogs/lighthouse_system_type_dialog.py index 9a56630255..61098ddcc5 100644 --- a/src/cfclient/ui/dialogs/lighthouse_system_type_dialog.py +++ b/src/cfclient/ui/dialogs/lighthouse_system_type_dialog.py @@ -96,6 +96,3 @@ def _type_toggled(self, *args): if new_type != self._curr_type: self._curr_type = new_type self._helper.cf.param.set_value(self.PARAM_GROUP + '.' + self.PARAM_NAME, self._curr_type) - - - From 3bc8b813cfebe01be47b49ec82122c63342775e0 Mon Sep 17 00:00:00 2001 From: knmcguire Date: Mon, 15 Aug 2022 13:28:48 +0200 Subject: [PATCH 6/6] removed old systemtype close response --- src/cfclient/ui/dialogs/lighthouse_system_type_dialog.py | 9 ++------- src/cfclient/ui/tabs/lighthouse_tab.py | 7 +------ 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/cfclient/ui/dialogs/lighthouse_system_type_dialog.py b/src/cfclient/ui/dialogs/lighthouse_system_type_dialog.py index 61098ddcc5..2e3be0bee7 100644 --- a/src/cfclient/ui/dialogs/lighthouse_system_type_dialog.py +++ b/src/cfclient/ui/dialogs/lighthouse_system_type_dialog.py @@ -50,24 +50,19 @@ class LighthouseSystemTypeDialog(QtWidgets.QWidget, lighthouse_system_widget_cla VALUE_V1 = 1 VALUE_V2 = 2 - def __init__(self, helper, ready_cb, *args): + def __init__(self, helper, *args): super(LighthouseSystemTypeDialog, self).__init__(*args) self.setupUi(self) - self.ready_cb = ready_cb self._helper = helper - self._close_button.clicked.connect(self.close_button_clicked) + self._close_button.clicked.connect(self.close) self._radio_btn_v1.toggled.connect(self._type_toggled) self._radio_btn_v2.toggled.connect(self._type_toggled) self._curr_type = 0 - def close_button_clicked(self): - self.ready_cb(True) - self.close() - def get_system_type(self): system_type = self.VALUE_V2 diff --git a/src/cfclient/ui/tabs/lighthouse_tab.py b/src/cfclient/ui/tabs/lighthouse_tab.py index 063b124003..b39c682885 100644 --- a/src/cfclient/ui/tabs/lighthouse_tab.py +++ b/src/cfclient/ui/tabs/lighthouse_tab.py @@ -289,7 +289,6 @@ class LighthouseTab(TabToolbox, lighthouse_tab_class): _new_system_config_written_to_cf_signal = pyqtSignal(bool) _geometry_read_signal = pyqtSignal(object) _calibration_read_signal = pyqtSignal(object) - _system_type_changed_signal = pyqtSignal(object) def __init__(self, helper): super(LighthouseTab, self).__init__(helper, 'Lighthouse Positioning') @@ -304,7 +303,6 @@ def __init__(self, helper): self._new_system_config_written_to_cf_signal.connect(self._new_system_config_written_to_cf) self._geometry_read_signal.connect(self._geometry_read_cb) self._calibration_read_signal.connect(self._calibration_read_cb) - self._system_type_changed_signal.connect(self._system_type_changed_cb) # Connect the Crazyflie API callbacks to the signals self._helper.cf.connected.add_callback(self._connected_signal.emit) @@ -347,7 +345,7 @@ def __init__(self, helper): self._basestation_geometry_dialog = LighthouseBsGeometryDialog(self) self._basestation_mode_dialog = LighthouseBsModeDialog(self) - self._system_type_dialog = LighthouseSystemTypeDialog(helper, self._system_type_changed_signal.emit) + self._system_type_dialog = LighthouseSystemTypeDialog(helper) self._manage_estimate_geometry_button.clicked.connect(self._show_basestation_geometry_dialog) self._change_system_type_button.clicked.connect(lambda: self._system_type_dialog.show()) @@ -430,9 +428,6 @@ def _geometry_read_cb(self, geometries): self._basestation_geometry_dialog.geometry_updated(self._lh_geos) self._is_geometry_read_ongoing = False - def _system_type_changed_cb(self): - self._update_basestation_status_indicators() - def _is_matching_current_geo_data(self, geometries): return geometries == self._lh_geos.keys()