diff --git a/src/rqt_gauges/speedometer_gauge.py b/src/rqt_gauges/speedometer_gauge.py index c7585ab..21f64de 100644 --- a/src/rqt_gauges/speedometer_gauge.py +++ b/src/rqt_gauges/speedometer_gauge.py @@ -34,6 +34,7 @@ def __init__(self, parent=None): self.minValue = 0 self.maxValue = 180 + self.raw_value = self.minValue self.value = self.minValue self.value_offset = 0 self.valueNeedleSnapzone = 0.05 @@ -137,6 +138,8 @@ def updateValue(self, value): # Args: # value: Value to update the gauge with. + self.raw_value = value + if value <= self.minValue: self.value = self.minValue elif value >= self.maxValue: @@ -309,7 +312,7 @@ def create_value_text(self): painter.setPen(pen_shadow) text_radius = self.widget_diameter / 2 * self.text_radius_factor - text = str(int(self.value)) + text = str(int(self.raw_value)) w = fm.width(text) + 1 h = fm.height() painter.setFont(QFont(self.value_fontname, self.value_fontsize, QFont.Bold)) diff --git a/src/rqt_gauges/steering_wheel_gauge.py b/src/rqt_gauges/steering_wheel_gauge.py index 76fe4d1..519bd43 100644 --- a/src/rqt_gauges/steering_wheel_gauge.py +++ b/src/rqt_gauges/steering_wheel_gauge.py @@ -21,6 +21,7 @@ def __init__(self, parent=None): super().__init__(parent) + self.raw_value = 0 self.value = 0 self.width = 400 self.height = 400 @@ -97,6 +98,7 @@ def updateValue(self, value: float): # Updates the value that the gauge is indicating. # Args: # value: Value to update the gauge with. + self.raw_value = value value = max(value, self.minValue) value = min(value, self.maxValue) self.value = value @@ -161,7 +163,7 @@ def paintEvent(self, event): # Create Gauge Text pen.setColor(QColor(self.text_color)) painter.setPen(pen) - painter.drawText(rect, Qt.AlignCenter, f'{self.value:.2f}{self.suffix}') + painter.drawText(rect, Qt.AlignCenter, f'{self.raw_value:.2f}{self.suffix}') # End Painter painter.end() diff --git a/src/rqt_gauges/throttle_brake_pedals_widget.py b/src/rqt_gauges/throttle_brake_pedals_widget.py index 619730f..c12827c 100644 --- a/src/rqt_gauges/throttle_brake_pedals_widget.py +++ b/src/rqt_gauges/throttle_brake_pedals_widget.py @@ -12,8 +12,8 @@ class ThrottleBrakePedalsWidget(QWidget): - updateThrottleValueSignal = pyqtSignal(int) - updateBrakeValueSignal = pyqtSignal(int) + updateThrottleValueSignal = pyqtSignal(int, int) + updateBrakeValueSignal = pyqtSignal(int, int) def __init__(self, node): super().__init__() @@ -82,15 +82,15 @@ def throttleUpdateSubscription(self): self.throttle_callback, 10) - @pyqtSlot(int) - def updateThrottle(self, value): + @pyqtSlot(int, int) + def updateThrottle(self, value, raw_value): self.throttle_pedal.setValue(value) - self.throttle_label.setText(str(value / 100.0)) + self.throttle_label.setText(str(raw_value / 100.0)) - @pyqtSlot(int) - def updateBrake(self, value): + @pyqtSlot(int, int) + def updateBrake(self, value, raw_value): self.brake_pedal.setValue(value) - self.brake_label.setText(str(value / 100.0)) + self.brake_label.setText(str(raw_value / 100.0)) @pyqtSlot() def brakeUpdateSubscription(self): @@ -116,10 +116,15 @@ def throttle_callback(self, msg): value = f(value) if value is not None and (type(value) == int or type(value) == float or type(value) == str): - if value <= 1 and value >= 0: - self.updateThrottleValueSignal.emit(int(value*100)) - else: + raw_value = int(value*100) + if value < 0: + value = 0 print('The throttle pedal value is not between 0 and 1') + elif value > 1: + value = 1 + print('The throttle pedal value is not between 0 and 1') + + self.updateThrottleValueSignal.emit(int(value*100), raw_value) else: print('The throttle pedal value is not valid') @@ -129,9 +134,14 @@ def brake_callback(self, msg): value = f(value) if value is not None and (type(value) == int or type(value) == float or type(value) == str): - if value <= 1 and value >= 0: - self.updateBrakeValueSignal.emit(int(value*100)) - else: + raw_value = int(value*100) + if value < 0: + value = 0 print('The brake pedal value is not between 0 and 1') + elif value > 1: + value = 1 + print('The brake pedal value is not between 0 and 1') + + self.updateBrakeValueSignal.emit(int(value*100), raw_value) else: print('The brake pedal value is not valid')