dwb_widget.py
Go to the documentation of this file.
1 # Software License Agreement (BSD License)
2 #
3 # Copyright (c) 2018-2019, Locus Robotics
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 #
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following
14 # disclaimer in the documentation and/or other materials provided
15 # with the distribution.
16 # * Neither the name of the copyright holder nor the names of its
17 # contributors may be used to endorse or promote products derived
18 # from this software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 # POSSIBILITY OF SUCH DAMAGE.
32 
33 import collections
34 
35 from python_qt_binding.QtCore import Qt
36 from python_qt_binding.QtWidgets import QSizePolicy, QSplitter, QVBoxLayout, QWidget
37 
38 from .score_widget import ScoreWidget
39 from .sorted_twists_widget import SortedTwistsWidget
40 from .trajectory_widget import TrajectoryWidget
41 from .util import PALETTE
42 from .velocity_space_widget import VelocitySpaceWidget
43 
44 
45 class DWBWidget(QWidget):
46  """Interface for viewing LocalPlanEvaluation messages one at a time.
47 
48  Within the individual messages, there is also the capability for highlighting/selecting a
49  subset of the trajectories.
50 
51  The panel is composed of four sub-widgets. When a message is selected through the message_viewed method,
52  this class sets the data for all the sub-widgets and highlights the best trajectory.
53 
54  Users can select additional trajectories through two of the widgets and update the trajectory subset
55  with the setSelected method. Each of those trajectories is mapped to a different color. This class
56  manages that mapping too.
57  """
58 
59  def __init__(self, parent, bounds=None):
60  super(DWBWidget, self).__init__(parent)
61  self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
62  self.widgets = []
63 
64  full_layout = QVBoxLayout(self)
65  vsplitter = QSplitter(Qt.Vertical, self)
66  full_layout.addWidget(vsplitter)
67 
68  widget0 = self.getTopWidget(bounds)
69  vsplitter.addWidget(widget0)
70  self.widgets.append(widget0)
71 
72  hsplitter = QSplitter(Qt.Horizontal, vsplitter)
73  widget1 = self.getLeftWidget(bounds)
74  hsplitter.addWidget(widget1)
75  self.widgets.append(widget1)
76 
77  widget2 = self.getRightWidget(bounds)
78  hsplitter.addWidget(widget2)
79  self.widgets.append(widget2)
80 
81  hsplitter.setSizes([10] * 2) # Makes them equally sized
82  vsplitter.addWidget(hsplitter)
83 
84  widget3 = self.getBottomWidget(bounds)
85  vsplitter.addWidget(widget3)
86  self.widgets.append(widget3)
87 
88  vsplitter.setSizes([10] * 3)
89 
90  self.color_map = {}
91 
92  def getTopWidget(self, bounds):
93  return TrajectoryWidget(self, bounds)
94 
95  def getLeftWidget(self, bounds):
96  return VelocitySpaceWidget(self, self.setSelected)
97 
98  def getRightWidget(self, bounds):
99  return SortedTwistsWidget(self, self.setSelected)
100 
101  def getBottomWidget(self, bounds):
102  return ScoreWidget(self)
103 
104  def setEvaluation(self, msg):
105  for widget in self.widgets:
106  widget.setEvaluation(msg)
107  self.setSelected([msg.best_index])
108 
109  def setPlan(self, plan):
110  for widget in self.widgets:
111  if hasattr(widget, 'setPlan'):
112  widget.setPlan(plan)
113 
114  def setVelocity(self, vel):
115  for widget in self.widgets:
116  if hasattr(widget, 'setVelocity'):
117  widget.setVelocity(vel)
118 
119  def setSelected(self, selected=[]):
120  selected = self.updateColorMap(selected)
121  for widget in self.widgets:
122  widget.setSelected(selected)
123 
124  def updateColorMap(self, selected):
125  new_color_map = collections.OrderedDict()
126  used_colors = set()
127 
128  def qcolor_hash(c):
129  return c.red, c.green, c.blue
130 
131  # Keep existing colors the same
132  for index in selected:
133  if index in self.color_map:
134  new_color_map[index] = self.color_map[index]
135  used_colors.add(qcolor_hash(new_color_map[index]))
136 
137  # Get New Colors
138  color_index = 0
139  for index in selected:
140  if index in self.color_map:
141  continue
142  while qcolor_hash(PALETTE[color_index]) in used_colors:
143  color_index += 1
144  new_color_map[index] = PALETTE[color_index]
145  color_index += 1
146 
147  self.color_map = new_color_map
148  return new_color_map
rqt_dwb_plugin.trajectory_widget.TrajectoryWidget
Definition: trajectory_widget.py:48
rqt_dwb_plugin.score_widget.ScoreWidget
Definition: score_widget.py:38
rqt_dwb_plugin.dwb_widget.DWBWidget.updateColorMap
def updateColorMap(self, selected)
Definition: dwb_widget.py:124
rqt_dwb_plugin.dwb_widget.DWBWidget.getLeftWidget
def getLeftWidget(self, bounds)
Definition: dwb_widget.py:95
rqt_dwb_plugin.sorted_twists_widget.SortedTwistsWidget
Definition: sorted_twists_widget.py:40
rqt_dwb_plugin.dwb_widget.DWBWidget.setVelocity
def setVelocity(self, vel)
Definition: dwb_widget.py:114
rqt_dwb_plugin.dwb_widget.DWBWidget.setSelected
def setSelected(self, selected=[])
Definition: dwb_widget.py:119
rqt_dwb_plugin.dwb_widget.DWBWidget.getRightWidget
def getRightWidget(self, bounds)
Definition: dwb_widget.py:98
rqt_dwb_plugin.dwb_widget.DWBWidget.getTopWidget
def getTopWidget(self, bounds)
Definition: dwb_widget.py:92
rqt_dwb_plugin.dwb_widget.DWBWidget.__init__
def __init__(self, parent, bounds=None)
Definition: dwb_widget.py:59
rqt_dwb_plugin.dwb_widget.DWBWidget.widgets
widgets
Definition: dwb_widget.py:62
rqt_dwb_plugin.dwb_widget.DWBWidget.color_map
color_map
Definition: dwb_widget.py:90
rqt_dwb_plugin.dwb_widget.DWBWidget.setPlan
def setPlan(self, plan)
Definition: dwb_widget.py:109
rqt_dwb_plugin.dwb_widget.DWBWidget.getBottomWidget
def getBottomWidget(self, bounds)
Definition: dwb_widget.py:101
rqt_dwb_plugin.dwb_widget.DWBWidget
Definition: dwb_widget.py:45
rqt_dwb_plugin.velocity_space_widget.VelocitySpaceWidget
Definition: velocity_space_widget.py:40
rqt_dwb_plugin.dwb_widget.DWBWidget.setEvaluation
def setEvaluation(self, msg)
Definition: dwb_widget.py:104


rqt_dwb_plugin
Author(s):
autogenerated on Sun May 18 2025 02:47:58