37 from python_qt_binding
import loadUi
39 from QtCore
import QEvent, QObject, Qt, QTimer, Slot
40 from QtGui
import QIcon
41 from QtWidgets
import QShortcut, QMessageBox, QWidget
42 from controller_manager_msgs.srv
import ListControllers, SwitchController, LoadController
43 from sr_robot_msgs.srv
import ChangeControlType
44 from sr_robot_msgs.msg
import ControlType
50 A rosgui plugin for loading the different controllers 52 ICON_DIR = os.path.join(
53 rospkg.RosPack().get_path(
'sr_visualization_icons'),
'icons')
54 CONTROLLER_ON_ICON = QIcon(os.path.join(ICON_DIR,
'green.png'))
55 CONTROLLER_OFF_ICON = QIcon(os.path.join(ICON_DIR,
'red.png'))
58 "valve": [
"sh_ffj0_muscle_valve_controller",
59 "sh_ffj3_muscle_valve_controller",
60 "sh_ffj4_muscle_valve_controller",
61 "sh_mfj0_muscle_valve_controller",
62 "sh_mfj3_muscle_valve_controller",
63 "sh_mfj4_muscle_valve_controller",
64 "sh_rfj0_muscle_valve_controller",
65 "sh_rfj3_muscle_valve_controller",
66 "sh_rfj4_muscle_valve_controller",
67 "sh_lfj0_muscle_valve_controller",
68 "sh_lfj3_muscle_valve_controller",
69 "sh_lfj4_muscle_valve_controller",
70 "sh_lfj5_muscle_valve_controller",
71 "sh_thj1_muscle_valve_controller",
72 "sh_thj2_muscle_valve_controller",
73 "sh_thj3_muscle_valve_controller",
74 "sh_thj4_muscle_valve_controller",
75 "sh_thj5_muscle_valve_controller",
76 "sh_wrj1_muscle_valve_controller",
77 "sh_wrj2_muscle_valve_controller"],
78 "position": [
"sh_ffj0_muscle_position_controller",
79 "sh_ffj3_muscle_position_controller",
80 "sh_ffj4_muscle_position_controller",
81 "sh_mfj0_muscle_position_controller",
82 "sh_mfj3_muscle_position_controller",
83 "sh_mfj4_muscle_position_controller",
84 "sh_rfj0_muscle_position_controller",
85 "sh_rfj3_muscle_position_controller",
86 "sh_rfj4_muscle_position_controller",
87 "sh_lfj0_muscle_position_controller",
88 "sh_lfj3_muscle_position_controller",
89 "sh_lfj4_muscle_position_controller",
90 "sh_lfj5_muscle_position_controller",
91 "sh_thj1_muscle_position_controller",
92 "sh_thj2_muscle_position_controller",
93 "sh_thj3_muscle_position_controller",
94 "sh_thj4_muscle_position_controller",
95 "sh_thj5_muscle_position_controller",
96 "sh_wrj1_muscle_position_controller",
97 "sh_wrj2_muscle_position_controller"],
101 super(SrGuiChangeControllers, self).
__init__(context)
102 self.setObjectName(
'SrGuiChangeControllers')
107 ui_file = os.path.join(rospkg.RosPack().get_path(
108 'sr_gui_change_muscle_controllers'),
'uis',
'SrChangeControllers.ui')
110 self._widget.setObjectName(
'SrChangeControllersUi')
111 context.add_widget(self.
_widget)
115 self._widget.btn_valve.setChecked(
False)
117 self._widget.btn_position.setChecked(
False)
122 self._widget.btn_position.pressed.connect(
129 self._widget.btn_stop.setEnabled(
False)
131 self._widget.btn_valve.setChecked(
False)
133 self._widget.btn_position.setChecked(
False)
135 self._widget.btn_stop.setEnabled(
True)
139 Switch to valve control 141 self._widget.btn_valve.setEnabled(
False)
142 if not self._widget.btn_valve.isChecked():
144 self._widget.btn_valve.setChecked(
True)
146 self._widget.btn_position.setChecked(
False)
147 rospy.loginfo(
"Valve checked: " + str(
148 self._widget.btn_valve.isChecked()))
152 self._widget.btn_valve.setChecked(
False)
153 rospy.loginfo(
"Valve checked: " + str(
154 self._widget.btn_valve.isChecked()))
156 self._widget.btn_valve.setEnabled(
True)
160 Switch to position control 162 self._widget.btn_position.setEnabled(
False)
163 if not self._widget.btn_position.isChecked():
165 self._widget.btn_position.setChecked(
True)
167 self._widget.btn_valve.setChecked(
False)
168 rospy.loginfo(
"Position checked: " + str(
169 self._widget.btn_position.isChecked()))
173 self._widget.btn_position.setChecked(
False)
174 rospy.loginfo(
"Position checked: " + str(
175 self._widget.btn_position.isChecked()))
177 self._widget.btn_position.setEnabled(
True)
181 Switch controller type 184 list_controllers = rospy.ServiceProxy(
185 'controller_manager/list_controllers', ListControllers)
187 resp1 = list_controllers()
188 except rospy.ServiceException:
192 current_controllers = [
193 c.name
for c
in resp1.controller
if c.state ==
"running"]
194 all_loaded_controllers = [c.name
for c
in resp1.controller]
196 controllers_to_start = self.
controllers[controller]
197 controllers_to_start.append(
'joint_state_controller')
199 load_controllers = rospy.ServiceProxy(
200 'controller_manager/load_controller', LoadController)
201 for load_control
in controllers_to_start:
202 if load_control
not in all_loaded_controllers:
204 resp1 = load_controllers(load_control)
205 except rospy.ServiceException:
210 switch_controllers = rospy.ServiceProxy(
211 'controller_manager/switch_controller', SwitchController)
213 resp1 = switch_controllers(
214 controllers_to_start, current_controllers, SwitchController._request_class.BEST_EFFORT,
False, 0)
215 except rospy.ServiceException:
223 "Failed to change some of the controllers. This is normal if this is not a 5 finger hand.")
227 self._publisher.unregister()
def change_ctrl(self, controller)
def on_valve_ctrl_clicked_(self)
def _unregisterPublisher(self)
def save_settings(self, global_settings, perspective_settings)
def on_position_ctrl_clicked_(self)
def on_stop_ctrl_clicked_(self)
def restore_settings(self, global_settings, perspective_settings)
def shutdown_plugin(self)
def __init__(self, context)