Skip to content

Commit

Permalink
Fixed steering wheel range (#24)
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Hernandez Cordero <[email protected]>
  • Loading branch information
ahcorde authored Dec 27, 2023
1 parent 180bd48 commit f6d2055
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 48 deletions.
Binary file modified img/steering_wheel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 4 additions & 45 deletions resource/steering_wheel.ui
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
</property>
<widget class="QTextEdit" name="max_value">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>330</x>
<x>230</x>
<y>460</y>
<width>51</width>
<height>31</height>
Expand Down Expand Up @@ -88,51 +88,10 @@ p, li { white-space: pre-wrap; }
<string>Topic:</string>
</property>
</widget>
<widget class="QTextEdit" name="min_value">
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>140</x>
<y>460</y>
<width>51</width>
<height>31</height>
</rect>
</property>
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;-45&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="placeholderText">
<string/>
</property>
</widget>
<widget class="QLabel" name="min_value_label">
<property name="geometry">
<rect>
<x>60</x>
<y>460</y>
<width>81</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Min Angle:</string>
</property>
</widget>
<widget class="QLabel" name="max_value_label">
<property name="geometry">
<rect>
<x>240</x>
<x>140</x>
<y>466</y>
<width>81</width>
<height>21</height>
Expand All @@ -144,7 +103,7 @@ p, li { white-space: pre-wrap; }
</font>
</property>
<property name="text">
<string>Max Angle:</string>
<string>Angle:</string>
</property>
</widget>
<widget class="TopicQLineEdit" name="topic_to_subscribe">
Expand Down
18 changes: 16 additions & 2 deletions src/rqt_gauges_2/steering_wheel_gauge.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def __init__(self, parent=None):
self.progress_width = 25
self.progress_rounded_cap = True
self.progress_color = 0x39F030
self.max_value = 45
self.circle_max_angle = 135
self.font_size = 40
self.scale_font_size = 15
Expand Down Expand Up @@ -101,6 +100,21 @@ def updateValue(self, value: float):
self.value = value
self.repaint()

def setMaxValue(self, max_value):
# Modifies the maximum value of the gauge
# Args:
# max: Value to update the maximum value of the gauge.
if self.value > max_value:
self.value = max_value
if max_value <= self.minValue:
self.maxValue = self.minValue + 1
self.minValue = -self.maxValue + 1
else:
self.maxValue = max_value
self.minValue = -max_value

self.update()

def draw_background_circle(self):
painter = QPainter()
painter.begin(self)
Expand All @@ -115,7 +129,7 @@ def paintEvent(self, event):
width = self.width - self.progress_width
height = self.height - self.progress_width
margin = int(self.progress_width / 2)
value = int(self.value * self.circle_max_angle / self.max_value)
value = int(self.value * self.circle_max_angle / self.maxValue)

# Draw Circle
self.draw_background_circle()
Expand Down
16 changes: 15 additions & 1 deletion src/rqt_gauges_2/steering_wheel_widget.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

from ament_index_python.resources import get_resource
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtCore import pyqtSlot, Qt
from PyQt5.QtWidgets import QWidget
from python_qt_binding import loadUi
from rosidl_runtime_py.utilities import get_message
Expand Down Expand Up @@ -30,8 +30,22 @@ def __init__(self, node):
self._topic_completer.update_topics(self.node)
self.topic_to_subscribe.setCompleter(self._topic_completer)

# Objects Properties
self.max_value.setAlignment(Qt.AlignCenter)

self.max_value.setPlaceholderText(str(self.steering_wheel_gauge.maxValue))

self.max_value.textChanged.connect(self.updateMaxValue)
self.subscribe_button.pressed.connect(self.updateSubscription)

@pyqtSlot()
def updateMaxValue(self):
new_max_value = self.max_value.toPlainText()
if new_max_value.isnumeric():
self.steering_wheel_gauge.setMaxValue(int(new_max_value))
else:
self.steering_wheel_gauge.setMaxValue(45)

@pyqtSlot()
def updateSubscription(self):
if self.node.destroy_subscription(self.sub):
Expand Down

0 comments on commit f6d2055

Please sign in to comment.