timeline_plotter.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 from python_qt_binding.QtCore import Qt
34 from python_qt_binding.QtGui import QBrush, QPen
35 
36 import rospy
37 
38 from rqt_bag import TimelineRenderer
39 
40 from .evaluation_cache import get_cache
41 from .util import FIELDS
42 
43 
44 class TimelinePlotter(TimelineRenderer):
45  """This class displays the velocity of the best trajectories in the timeline view."""
46 
47  def __init__(self, timeline, height=240):
48  TimelineRenderer.__init__(self, timeline, msg_combine_px=height)
49  self.height = height
50  self.cache = get_cache()
51 
52  def get_segment_height(self, topic):
53  return self.height
54 
55  def scaleValue(self, value):
56  return 1.0 - (value - self.cache.v_min) / (self.cache.v_max - self.cache.v_min)
57 
58  def draw_timeline_segment(self, painter, topic, stamp_start, stamp_end, x, y, width, height):
59  painter.setBrush(QBrush(Qt.white))
60  painter.drawRect(x, y, width, height)
61 
62  messages = self.cache.getMessages(self.timeline.scene(), topic, rospy.Time(stamp_start), rospy.Time(stamp_end))
63  if self.cache.v_min is None:
64  return
65  painter.setBrush(QBrush(Qt.black))
66  z_val = y + height * self.scaleValue(0.0)
67  painter.drawLine(x, z_val, x + width, z_val)
68  RADIUS = 2
69 
70  for field, color in FIELDS.iteritems():
71  if field == 'y':
72  continue
73  color = getattr(Qt, color)
74 
75  last = None
76  for t, msg in sorted(messages):
77  best = msg.twists[msg.best_index]
78  best_vel = best.traj.velocity
79  p_x = self.timeline.map_stamp_to_x(t)
80  if best.total >= 0.0:
81  painter.setBrush(QBrush(color))
82  painter.setPen(QPen(color, 1))
83  value = getattr(best_vel, field)
84  else:
85  painter.setBrush(QBrush(Qt.red))
86  painter.setPen(QPen(Qt.red, 1))
87  value = 0.0
88  p_y = y + height * self.scaleValue(value)
89  if last is not None:
90  painter.drawLine(last[0], last[1], p_x, p_y)
91  painter.drawEllipse(p_x - RADIUS, p_y - RADIUS, 2 * RADIUS, 2 * RADIUS)
92  last = p_x, p_y
def __init__(self, timeline, height=240)
def draw_timeline_segment(self, painter, topic, stamp_start, stamp_end, x, y, width, height)


rqt_dwb_plugin
Author(s):
autogenerated on Mon Feb 28 2022 23:33:43