Skip to content

Commit

Permalink
Show raw values. (#31)
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Agüero <[email protected]>
  • Loading branch information
caguero authored Feb 19, 2024
1 parent 8e11aca commit 7947212
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
5 changes: 4 additions & 1 deletion src/rqt_gauges/speedometer_gauge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 3 additions & 1 deletion src/rqt_gauges/steering_wheel_gauge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down
38 changes: 24 additions & 14 deletions src/rqt_gauges/throttle_brake_pedals_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__()
Expand Down Expand Up @@ -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):
Expand All @@ -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')

Expand All @@ -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')

0 comments on commit 7947212

Please sign in to comment.