Skip to content

Commit

Permalink
add esc status monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
Huibean authored and tridge committed Sep 11, 2024
1 parent 5ecc5a2 commit 9c1c9df
Showing 1 changed file with 49 additions and 12 deletions.
61 changes: 49 additions & 12 deletions dronecan_gui_tool/panels/esc_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@


class PercentSlider(QWidget):
def __init__(self, parent):
def __init__(self, esc_index, parent):
super(PercentSlider, self).__init__(parent)

self._index = esc_index

self._slider = QSlider(Qt.Vertical, self)
self._slider.setMinimum(-100)
self._slider.setMaximum(100)
Expand All @@ -44,23 +46,51 @@ def __init__(self, parent):

self._zero_button = make_icon_button('hand-stop-o', 'Zero setpoint', self, on_clicked=self.zero)

layout = QVBoxLayout(self)
sub_layout = QHBoxLayout(self)
sub_layout.addStretch()
sub_layout.addWidget(self._slider)
sub_layout.addStretch()
layout.addLayout(sub_layout)
layout.addWidget(self._spinbox)
layout.addWidget(self._zero_button)
self._index_label = QLabel(f'Index: {self._index}', self)
self._error_count_label = QLabel('Err: NC', self)
self._voltage_label = QLabel('Volt: NC', self)
self._current_label = QLabel('Curr: NC', self)
self._temperature_label = QLabel('Temp: NC', self)
self._rpm_label = QLabel('RPM: NC', self)
self._power_rating_pct_label = QLabel('RAT: NC', self)

layout = QHBoxLayout(self)

status_layout = QVBoxLayout(self)
status_layout.addWidget(self._index_label)
status_layout.addWidget(self._error_count_label)
status_layout.addWidget(self._voltage_label)
status_layout.addWidget(self._current_label)
status_layout.addWidget(self._temperature_label)
status_layout.addWidget(self._rpm_label)
status_layout.addWidget(self._power_rating_pct_label)
status_layout.addStretch()
status_layout.addWidget(self._spinbox)
status_layout.addWidget(self._zero_button)

layout.addLayout(status_layout)
layout.addWidget(self._slider)

self.setLayout(layout)

self.setMinimumHeight(400)
self.setMinimumHeight(300)

def zero(self):
self._slider.setValue(0)

def get_value(self):
return self._slider.value()

def update_status(self, msg):
status = msg.message
if status.esc_index == self._index:
self._error_count_label.setText(f'Err: {status.error_count}')
self._voltage_label.setText(f'Volt: {status.voltage:.1f} V')
self._current_label.setText(f'Curr: {status.current:.1f} A')
temperature_celsius = status.temperature - 273.15
self._temperature_label.setText(f'Temp: {temperature_celsius:.1f} °C')
self._rpm_label.setText(f'RPM: {status.rpm}')
self._power_rating_pct_label.setText(f'RAT: {status.power_rating_pct} %')


class ESCPanel(QDialog):
Expand All @@ -77,7 +107,7 @@ def __init__(self, parent, node):

self._node = node

self._sliders = [PercentSlider(self) for _ in range(4)]
self._sliders = [PercentSlider(index, self) for index in range(4)]

self._num_sliders = QSpinBox(self)
self._num_sliders.setMinimum(len(self._sliders))
Expand Down Expand Up @@ -141,6 +171,13 @@ def __init__(self, parent, node):
self.setLayout(layout)
self.resize(self.minimumWidth(), self.minimumHeight())

self._node.add_handler(dronecan.uavcan.equipment.esc.Status, self._on_esc_status)

def _on_esc_status(self, msg):
if msg.message.esc_index < len(self._sliders):
sl = self._sliders[msg.message.esc_index]
sl.update_status(msg)

def _do_broadcast(self):
try:
if not self._pause.isChecked():
Expand Down Expand Up @@ -180,7 +217,7 @@ def _update_number_of_sliders(self):
removee.deleteLater()

while len(self._sliders) < num_sliders:
new = PercentSlider(self)
new = PercentSlider(len(self._sliders), self)
self._slider_layout.addWidget(new)
self._sliders.append(new)

Expand Down

0 comments on commit 9c1c9df

Please sign in to comment.