parameter_editor_widget.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import rospy
00004 import actionlib
00005 import std_msgs.msg
00006 import vigir_footstep_planning_msgs.msg
00007 
00008 from rqt_gui_py.plugin import Plugin
00009 from python_qt_binding.QtCore import Qt
00010 from python_qt_binding.QtGui import QWidget, QSplitter, QVBoxLayout, QPushButton
00011 
00012 from vigir_generic_params.msg import SetParameterSetAction, SetParameterSetGoal, GetParameterSetAction, GetParameterSetGoal, GetParameterSetResult
00013 from vigir_footstep_planning_msgs.msg import ErrorStatus
00014 from vigir_footstep_planning_msgs.parameter import *
00015 from vigir_footstep_planning_lib.error_status_widget import *
00016 from vigir_footstep_planning_lib.logging import *
00017 from vigir_footstep_planning_lib.parameter_set_widget import *
00018 from vigir_footstep_planning_lib.parameter_tree_widget import *
00019 from vigir_footstep_planning_lib.topic_widget import *
00020 from vigir_footstep_planning_lib.qt_helper import *
00021 
00022 
00023 class ParameterEditorDialog(Plugin):
00024 
00025     def __init__(self, context):
00026         super(ParameterEditorDialog, self).__init__(context)
00027         self.setObjectName('ParameterEditorDialog')
00028 
00029         self._parent = QWidget()
00030         self._widget = ParameterEditorWidget(self._parent)
00031 
00032         context.add_widget(self._parent)
00033 
00034     def shutdown_plugin(self):
00035         self._widget.shutdown_plugin()
00036 
00037 
00038 class ParameterEditorWidget(QObject):
00039 
00040     def __init__(self, context):
00041         super(ParameterEditorWidget, self).__init__()
00042 
00043         # start widget
00044         widget = context
00045         vbox = QVBoxLayout()
00046         error_status_widget = QErrorStatusWidget()
00047         self.logger = Logger(error_status_widget)
00048 
00049         # parameter set selection
00050         self.parameter_set_widget = QParameterSetWidget(logger=self.logger)
00051         add_widget_with_frame(vbox, self.parameter_set_widget, "Parameter Set:")
00052 
00053         # start horizontal splitter
00054         vsplitter = QSplitter()
00055         vsplitter.setOrientation(Qt.Vertical)
00056         vsplitter.setChildrenCollapsible(False)
00057 
00058         # parameter set editor
00059         parameter_editor_widget = QParameterEditorWidget(logger=self.logger)
00060         add_widget_with_frame(vsplitter, parameter_editor_widget, "Editor:")
00061 
00062         # add error status widget
00063         add_widget_with_frame(vsplitter, error_status_widget, "Status:")
00064 
00065         # end horizontal splitter
00066         vbox.addWidget(vsplitter)
00067 
00068         # end widget
00069         widget.setLayout(vbox)
00070         #context.add_widget(widget)
00071 
00072         # init parameter editor
00073         self.parameter_set_widget.topic_changed_signal.connect(parameter_editor_widget.set_get_parameter_set_topic_name)
00074         self.parameter_set_widget.param_changed_signal.connect(parameter_editor_widget.load_parameters)
00075         self.parameter_set_widget.param_cleared_signal.connect(parameter_editor_widget.clear)
00076 
00077     def shutdown_plugin(self):
00078         print "Shutting down ..."
00079         print "Done!"
00080 
00081 
00082 class QParameterEditorWidget(QWidgetWithLogger):
00083 
00084     parameter_set_name = str()
00085 
00086     def __init__(self, parent=None, logger=Logger()):
00087         QWidgetWithLogger.__init__(self, parent, logger)
00088 
00089         # start widget
00090         vbox = QVBoxLayout()
00091         vbox.setMargin(0)
00092         vbox.setContentsMargins(0, 0, 0, 0)
00093 
00094         # add layout which is dynamically filled
00095         self.parameter_tree_widget = QParameterTreeWidget(logger=self.logger)
00096         vbox.addWidget(self.parameter_tree_widget)
00097 
00098         # button panel
00099         vbox_commands = QVBoxLayout()
00100         hbox = QHBoxLayout()
00101 
00102         # upload topic
00103         send_parameter_topic_widget = QTopicWidget(self, 'vigir_footstep_planning_msgs/SetParameterSetAction', True)
00104         send_parameter_topic_widget.topic_changed_signal.connect(self._init_upload_paramater_set_client)
00105         hbox.addWidget(send_parameter_topic_widget)
00106 
00107         # upload command
00108         self.upload_command = QPushButton("Upload")
00109         self.upload_command.clicked.connect(self.upload_parameters)
00110         hbox.addWidget(self.upload_command)
00111         vbox_commands.addLayout(hbox)
00112 
00113         # reload command
00114         self.reload_command = QPushButton("Reload")
00115         self.reload_command.clicked.connect(self.reload_parameters)
00116         vbox_commands.addWidget(self.reload_command)
00117 
00118         # add button panel
00119         vbox.addLayout(vbox_commands)
00120 
00121         # end widget
00122         self.setLayout(vbox)
00123 
00124         # init
00125         self.clear()
00126         send_parameter_topic_widget.emit_topic_name()
00127 
00128     @Slot(str)
00129     def _init_get_parameter_set_client(self, topic_name):
00130         self.get_parameter_set_client = actionlib.SimpleActionClient(topic_name, GetParameterSetAction)
00131         print "Parameter set topic changed: " + topic_name
00132 
00133     @Slot(str)
00134     def _init_upload_paramater_set_client(self, topic_name):
00135         if len(topic_name) > 0:
00136             print "Upload parameter set topic changed: " + topic_name
00137             self.upload_parameter_set_client = actionlib.SimpleActionClient(topic_name, SetParameterSetAction)
00138 
00139     @Slot(str)
00140     def set_get_parameter_set_topic_name(self, topic_name):
00141         # assume that there are no topic remaps
00142         if len(topic_name) > 0:
00143             self._init_get_parameter_set_client(topic_name[:-6])
00144 
00145     # clear current vis
00146     @Slot()
00147     def clear(self):
00148         self.upload_command.setEnabled(False)
00149         self.reload_command.setEnabled(False)
00150         self.parameter_tree_widget.clear()
00151 
00152     @Slot()
00153     def upload_parameters(self):
00154         param_set_msg = self.parameter_tree_widget.get_parameter_set()
00155 
00156         if self.upload_parameter_set_client.wait_for_server(rospy.Duration(0.5)):
00157             self.logger.log_info("Sending parameter set '" + param_set_msg.name.data + "'...")
00158 
00159             goal = SetParameterSetGoal()
00160             goal.params = param_set_msg;
00161             self.upload_parameter_set_client.send_goal(goal)
00162 
00163             if self.upload_parameter_set_client.wait_for_result(rospy.Duration(0.5)):
00164                 self.logger.log_info("Sent parameter set!")
00165                 result = self.upload_parameter_set_client.get_result()
00166                 self.logger.log(result.status)
00167             else:
00168                 self.logger.log_error("Can't send parameter set. Check communcation!")
00169         else:
00170             self.logger.log_error("Can't connect to footstep parameter action server!")
00171 
00172     @Slot(str)
00173     def load_parameters(self, name):
00174         self.clear()
00175 
00176         if self.get_parameter_set_client.wait_for_server(rospy.Duration(0.5)):
00177             self.logger.log_info("Requesting parameter set '" + name + "'...")
00178 
00179             goal = GetParameterSetGoal()
00180             goal.name.data = name;
00181             self.get_parameter_set_client.send_goal(goal)
00182 
00183             if self.get_parameter_set_client.wait_for_result(rospy.Duration(0.5)):
00184                 self.logger.log_info("Received parameter set!")
00185                 result = self.get_parameter_set_client.get_result()
00186                 self.current_parameter_set_name = name
00187                 self._visualize_parameters(result.params)
00188             else:
00189                 self.logger.log_error("Didn't received parameter set. Check communcation!")
00190         else:
00191             self.logger.log_error("Can't connect to footstep parameter action server!")
00192 
00193     @Slot()
00194     def reload_parameters(self):
00195         self.load_parameters(self.current_parameter_set_name)
00196 
00197     # get parameter set as msg
00198     def _visualize_parameters(self, param_set_msg):
00199         self.logger.log_info("Visualize parameter set with " + str(len(param_set_msg.params)) + " parameters.")
00200         self.parameter_tree_widget.set_parameter_set(param_set_msg)
00201         self.upload_command.setEnabled(True)
00202         self.reload_command.setEnabled(True)


vigir_footstep_planning_widgets
Author(s): Alexander Stumpf
autogenerated on Sat Jul 15 2017 02:48:11