7 from python_qt_binding
import loadUi
8 from python_qt_binding.QtWidgets
import QWidget, QTreeWidgetItem, QFileDialog, QHBoxLayout
10 from python_qt_binding.QtCore
import Qt, QTimer, Signal, Slot, QRegExp, pyqtSignal, QSize
12 from python_qt_binding.QtGui
import QIcon, QFont, QFontMetrics, QPalette, QBrush
13 from python_qt_binding.QtGui
import QIcon, QFont, QFontMetrics, QTextDocument, QTextOption, QPen, QPainter, QColor, QTextCursor
17 from dyn_tune.msg
import Experiment
20 from rqt_bag.bag_widget
import BagWidget
21 from .func_widget
import StyledLabel
27 from rqt_bag.player
import Player
28 from rosgraph_msgs.msg
import Log
30 from dyn_tune
import function
32 python_pkg_path = os.path.join(rospkg.RosPack().get_path(
'dyn_tune'),
'src',
'dyn_tune')
34 if python_pkg_path
not in sys.path:
35 sys.path.insert(0, python_pkg_path)
43 self._publishers[topic] = rospy.Publisher(prefix + topic, type(msg), queue_size=100)
45 self._publishers[topic] = rospy.Publisher(prefix + topic, type(msg))
47 except Exception
as ex:
49 rospy.logerr(
'Error creating publisher on topic %s for type %s. \nError text: %s' % (prefix + topic, str(type(msg)), str(ex)))
50 if topic != CLOCK_TOPIC:
51 self.stop_publishing(topic)
55 def __init__(self, context, publish_clock = ""):
58 super(MyBagWidget, self).
__init__(context, args.clock)
60 self._timeline._player =
MyPlayer(self._timeline)
62 self.graphics_view.setBackgroundBrush(QBrush(QColor(127,127,127)))
64 slabel = StyledLabel(self)
65 layout = self.horizontalLayout
66 self.horizontalLayout.takeAt(0)
67 last = self.horizontalLayout.count() - 1
68 self.horizontalLayout.takeAt(last)
69 self.horizontalLayout.insertWidget(-1, slabel, 1)
77 height = TOPIC_HEIGHT * len(self._timeline._get_topics()) + PADDING
78 return QSize(0, height)
81 parser = argparse.ArgumentParser(prog=
'rqt_bag', add_help=
False)
82 MyBagWidget.add_arguments(parser)
83 return parser.parse_args(argv)
87 if os.path.isfile(arg):
90 parser.error(
"Bag file %s does not exist" % ( arg ))
94 group = parser.add_argument_group(
'Options for rqt_bag plugin')
95 group.add_argument(
'--clock', action=
'store_true', help=
'publish the clock time')
96 group.add_argument(
'bagfiles', type=
lambda x: MyBagWidget._isfile(parser, x),
97 nargs=
'*', default=[], help=
'Bagfiles to load')
100 filename = QFileDialog.getOpenFileName(self, self.tr(
'Load from File'),
'.', self.tr(
'Bag files {.bag} (*.bag)'))
102 if filename[0] !=
'':
104 self.load_bag(filename[0])
105 self._timeline.set_publishing_state(
True)
109 self = _self._timeline._timeline_frame
125 1 * 60, 2 * 60, 5 * 60, 10 * 60, 15 * 60, 30 * 60,
126 1 * 60 * 60, 2 * 60 * 60, 3 * 60 * 60, 6 * 60 * 60, 12 * 60 * 60,
127 1 * 60 * 60 * 24, 7 * 60 * 60 * 24]
144 self._topic_font.setBold(
False)
154 self._time_font.setBold(
False)
161 'sensor_msgs/CameraInfo': QColor(0, 0, 77, 204),
162 'sensor_msgs/Image': QColor(0, 77, 77, 204),
163 'sensor_msgs/LaserScan': QColor(153, 0, 0, 204),
164 'pr2_msgs/LaserScannerSignal': QColor(153, 0, 0, 204),
165 'pr2_mechanism_msgs/MechanismState': QColor(0, 153, 0, 204),
166 'tf/tfMessage': QColor(0, 153, 0, 204),
210 loggerUpdate = Signal(str, name=
'loggerUpdate')
213 super(DynTuneUI, self).
__init__(context)
216 self.setObjectName(
'dyn_tune_plugin')
219 from argparse
import ArgumentParser
220 parser = ArgumentParser()
222 parser.add_argument(
"-q",
"--quiet", action=
"store_true",
224 help=
"Put plugin in silent mode")
225 args, unknowns = parser.parse_known_args(context.argv())
227 print 'arguments: ', args
228 print 'unknowns: ', unknowns
235 ui_file = os.path.join(rospkg.RosPack().get_path(
'rqt_dyn_tune'),
'resource',
'DynTune.ui')
239 self._widget.setObjectName(
'DynTuneUI')
241 self._widget.vLayout.insertWidget(1, self.
_bag_widget, 0)
242 self._widget.vLayout.setStretchFactor(self._widget.hLayout, 1)
243 self._widget.vLayout.setStretchFactor(self._widget._widget_func, 1)
253 context.add_widget(self.
_widget)
255 index = self._widget._widget_values._column_names.index(
"checkbox")
256 self._widget._widget_values.topics_tree_widget.hideColumn(index)
257 self._widget._widget_values.topics_tree_widget.model().setHeaderData(0, Qt.Horizontal,
"value");
259 self._widget._widget_func.start()
260 self._widget._widget_values.start()
261 self._widget._widget_param.start()
267 css_file = os.path.join(rospkg.RosPack().get_path(
'rqt_dyn_tune'),
'src',
'rqt_dyn_tune',
'css',
'selector.css')
268 with open(css_file,
"r") as fh: 270 self._widget._widget_func.setStyleSheet(csstext) 271 self._widget._widget_values.setStyleSheet(csstext) 272 self._widget._widget_param.setStyleSheet(csstext) 275 css_file = os.path.join(rospkg.RosPack().get_path('rqt_dyn_tune'),
'src',
'rqt_dyn_tune',
'css',
'bag.css')
276 with open(css_file,
"r") as fh: 278 self._bag_widget.setStyleSheet(csstext) 281 css_file = os.path.join(rospkg.RosPack().get_path('rqt_dyn_tune'),
'src',
'rqt_dyn_tune',
'css',
'plugin.css')
282 with open(css_file,
"r") as fh: 284 self._widget.setStyleSheet(csstext) 288 self._widget.tune_btn.clicked.connect(self.tune_clicked) 291 def topics_refreshed():
292 topic_widget = self._widget._widget_values
293 values = topic_widget.get_selected_values()
294 self._widget._widget_func.topics_refreshed(values)
297 self._widget._widget_values.topicsRefreshed.connect(topics_refreshed)
301 if msg.name ==
"/dyn_tune_backbone":
302 self.loggerUpdate.emit(msg.msg)
306 self._widget.logger.append(msg)
311 self.
optimize = rospy.ServiceProxy(
'/optimize', Optimize)
319 params_dict = self._widget._widget_param.get_selected()
320 exp.parameters = json.dumps(params_dict)
321 exp.objective = self._widget._widget_func.create_function_msg()
326 opt = OptimizeRequest()
328 opt.observation_values = self._widget._widget_values.get_selected()
329 opt.start_signals =
"{}" 330 opt.end_signals =
"{}" 331 opt.src_bag = self._bag_widget.filename
332 opt.dst_bag =
"_simulation.bag" 334 opt.src_topic =
"/.*" 338 opt.experiments.append(exp)
def save_settings(self, plugin_settings, instance_settings)
def shutdown_plugin(self)
def logger_update_slot(self, msg)
def creat_optimize_srv(self)
def create_publisher(self, topic, msg, prefix="/GROUND_TRUTH")
def restore_settings(self, plugin_settings, instance_settings)
def create_experiment_msg(self, name="experiment_0")
def __init__(self, context)
def logger_update(self, msg)