change_controllers.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 # Disabling E1002 check since it complains about super for no reason - inheriting from QObject
00004 # pylint: disable=E1002
00005 
00006 import os
00007 from python_qt_binding import loadUi
00008 from qt_gui.plugin import Plugin
00009 from QtGui import QWidget
00010 import rospy
00011 import rospkg
00012 from sr_robot_msgs.srv import RobotTeachMode, RobotTeachModeRequest, RobotTeachModeResponse
00013 
00014 
00015 class SrGuiChangeControllers(Plugin):
00016 
00017     """
00018     A rosgui plugin for loading the different controllers
00019     """
00020 
00021     def __init__(self, context):
00022         super(SrGuiChangeControllers, self).__init__(context)
00023         self.setObjectName('SrGuiTeachMode')
00024 
00025         self._publisher = None
00026         self._widget = QWidget()
00027 
00028         ui_file = os.path.join(rospkg.RosPack().get_path(
00029             'sr_gui_change_controllers'), 'uis', 'SrChangeControllers.ui')
00030         loadUi(ui_file, self._widget)
00031         self._widget.setObjectName('SrChangeControllersUI')
00032         context.add_widget(self._widget)
00033 
00034         self._rh_teach_buttons = []
00035         self._lh_teach_buttons = []
00036         self._ra_teach_buttons = []
00037         self._la_teach_buttons = []
00038 
00039         # rh group
00040         self._rh_teach_buttons.append(self._widget.radioButton_1)
00041         self._rh_teach_buttons.append(self._widget.radioButton_2)
00042         self._rh_teach_buttons.append(self._widget.radioButton_3)
00043         self._widget.radioButton_1.toggled.connect(
00044             self.teach_mode_button_toggled_rh)
00045         self._widget.radioButton_2.toggled.connect(
00046             self.teach_mode_button_toggled_rh)
00047         self._widget.radioButton_3.toggled.connect(
00048             self.teach_mode_button_toggled_rh)
00049 
00050         # lh group
00051         self._lh_teach_buttons.append(self._widget.radioButton_4)
00052         self._lh_teach_buttons.append(self._widget.radioButton_5)
00053         self._lh_teach_buttons.append(self._widget.radioButton_6)
00054         self._widget.radioButton_4.toggled.connect(
00055             self.teach_mode_button_toggled_lh)
00056         self._widget.radioButton_5.toggled.connect(
00057             self.teach_mode_button_toggled_lh)
00058         self._widget.radioButton_6.toggled.connect(
00059             self.teach_mode_button_toggled_lh)
00060 
00061         # ra group
00062         self._ra_teach_buttons.append(self._widget.radioButton_7)
00063         self._ra_teach_buttons.append(self._widget.radioButton_8)
00064         self._ra_teach_buttons.append(self._widget.radioButton_9)
00065         self._widget.radioButton_7.toggled.connect(
00066             self.teach_mode_button_toggled_ra)
00067         self._widget.radioButton_8.toggled.connect(
00068             self.teach_mode_button_toggled_ra)
00069         self._widget.radioButton_9.toggled.connect(
00070             self.teach_mode_button_toggled_ra)
00071 
00072         # la group
00073         self._la_teach_buttons.append(self._widget.radioButton_10)
00074         self._la_teach_buttons.append(self._widget.radioButton_11)
00075         self._la_teach_buttons.append(self._widget.radioButton_12)
00076         self._widget.radioButton_10.toggled.connect(
00077             self.teach_mode_button_toggled_la)
00078         self._widget.radioButton_11.toggled.connect(
00079             self.teach_mode_button_toggled_la)
00080         self._widget.radioButton_12.toggled.connect(
00081             self.teach_mode_button_toggled_la)
00082 
00083     def teach_mode_button_toggled_rh(self, checked):
00084         self.teach_mode_button_toggled(
00085             checked, "right_hand", self._rh_teach_buttons)
00086 
00087     def teach_mode_button_toggled_lh(self, checked):
00088         self.teach_mode_button_toggled(
00089             checked, "left_hand", self._lh_teach_buttons)
00090 
00091     def teach_mode_button_toggled_ra(self, checked):
00092         self.teach_mode_button_toggled(
00093             checked, "right_arm", self._ra_teach_buttons)
00094 
00095     def teach_mode_button_toggled_la(self, checked):
00096         self.teach_mode_button_toggled(
00097             checked, "left_arm", self._la_teach_buttons)
00098 
00099     def teach_mode_button_toggled(self, checked, robot, buttons):
00100         if checked:
00101             if buttons[0].isChecked():
00102                 mode = RobotTeachModeRequest.TRAJECTORY_MODE
00103             elif buttons[1].isChecked():
00104                 mode = RobotTeachModeRequest.TEACH_MODE
00105             elif buttons[2].isChecked():
00106                 mode = RobotTeachModeRequest.POSITION_MODE
00107             else:
00108                 rospy.logerr("None of the buttons checked for robot %s", robot)
00109                 return
00110 
00111             rospy.loginfo("Changing robot %s to mode %d", robot, mode)
00112             self.change_teach_mode(mode, robot)
00113 
00114     @staticmethod
00115     def change_teach_mode(mode, robot):
00116 
00117         teach_mode_client = rospy.ServiceProxy('/teach_mode', RobotTeachMode)
00118 
00119         req = RobotTeachModeRequest()
00120         req.teach_mode = mode
00121         req.robot = robot
00122         try:
00123             resp = teach_mode_client(req)
00124             if resp.result == RobotTeachModeResponse.ERROR:
00125                 rospy.logerr(
00126                     "Failed to change robot %s to mode %d", robot, mode)
00127             else:
00128                 rospy.loginfo(
00129                     "Changed robot %s to mode %d Result = %d", robot, mode, resp.result)
00130         except rospy.ServiceException:
00131             rospy.logerr("Failed to call service teach_mode")


sr_gui_change_controllers
Author(s): Toni Oliver
autogenerated on Thu Jun 6 2019 21:13:39