2 """ This simple script creates an interactive marker for changing desired centering pose of
3 two the dual_panda_cartesian_impedance_example_controller. It features also resetting the
4 marker to current centering pose between the left and the right endeffector.
10 from interactive_markers.interactive_marker_server
import \
11 InteractiveMarkerServer, InteractiveMarkerFeedback
12 from visualization_msgs.msg
import InteractiveMarker, \
13 InteractiveMarkerControl, Marker
14 from franka_msgs.msg
import FrankaState
15 from geometry_msgs.msg
import PoseStamped
17 marker_pose = PoseStamped()
20 left_has_error =
False
21 right_has_error =
False
28 This function returns sphere marker for 3D translational movements.
29 :param scale: scales the size of the sphere
30 :return: sphere marker
33 marker.type = Marker.SPHERE
34 marker.scale.x = scale * 0.45
35 marker.scale.y = scale * 0.45
36 marker.scale.z = scale * 0.45
46 This function publishes desired centering pose which the controller will subscribe to.
49 marker_pose.header.stamp = rospy.Time(0)
50 pose_pub.publish(marker_pose)
55 This callback function set `has_error` variable to True if the left arm is having an error.
56 :param msg: FrankaState msg data
59 global has_error, left_has_error
60 if msg.robot_mode == FrankaState.ROBOT_MODE_MOVE:
61 left_has_error =
False
64 has_error = left_has_error
or right_has_error
69 This callback function set `has_error` variable to True if the right arm is having an error.
70 :param msg: FrankaState msg data
73 global has_error, right_has_error
74 if msg.robot_mode == FrankaState.ROBOT_MODE_MOVE:
75 right_has_error =
False
77 right_has_error =
True
78 has_error = left_has_error
or right_has_error
83 This function resets the marker pose to current "middle pose" of left and right arm EEs.
88 marker_pose = rospy.wait_for_message(
89 "dual_arm_cartesian_impedance_example_controller/centering_frame", PoseStamped)
94 This callback function clips the marker_pose inside a predefined box to prevent misuse of the
96 :param feedback: feedback data of interactive marker
100 if feedback.event_type == InteractiveMarkerFeedback.POSE_UPDATE:
101 marker_pose.pose.position.x = feedback.pose.position.x
102 marker_pose.pose.position.y = feedback.pose.position.y
103 marker_pose.pose.position.z = feedback.pose.position.z
104 marker_pose.pose.orientation = feedback.pose.orientation
105 server.applyChanges()
108 if __name__ ==
"__main__":
109 rospy.init_node(
"target_pose_node")
111 parser = argparse.ArgumentParser(
"dual_panda_interactive_marker.py")
112 parser.add_argument(
"--left_arm_id",
113 help=
"The id of the left arm.",
115 parser.add_argument(
"--right_arm_id",
116 help=
"The id of the right arm.",
118 parser.add_argument(
'args', nargs=argparse.REMAINDER)
119 args = parser.parse_args()
122 left_arm_id = args.left_arm_id
123 right_arm_id = args.right_arm_id
126 left_state_sub = rospy.Subscriber(left_arm_id +
"_state_controller/franka_states",
127 FrankaState, left_franka_state_callback)
129 right_state_sub = rospy.Subscriber(right_arm_id +
"_state_controller/franka_states",
130 FrankaState, right_franka_state_callback)
136 pose_pub = rospy.Publisher(
137 "dual_arm_cartesian_impedance_example_controller/centering_frame_target_pose",
142 server = InteractiveMarkerServer(
"target_pose_marker")
143 int_marker = InteractiveMarker()
144 int_marker.header.frame_id = marker_pose.header.frame_id
145 int_marker.scale = 0.3
146 int_marker.name =
"centering_frame_pose"
147 int_marker.description = (
"Target centering pose\n"
149 "If you move the target marker\n"
150 "both robots will follow it \n"
151 "as the center between the two\n"
152 "endeffectors. Be aware of\n"
153 "potential collisions!")
154 int_marker.pose = marker_pose.pose
157 control = InteractiveMarkerControl()
158 control.orientation.w = 1
159 control.orientation.x = 1
160 control.orientation.y = 0
161 control.orientation.z = 0
162 control.name =
"rotate_x"
163 control.interaction_mode = InteractiveMarkerControl.ROTATE_AXIS
164 int_marker.controls.append(control)
166 control = InteractiveMarkerControl()
167 control.orientation.w = 1
168 control.orientation.x = 1
169 control.orientation.y = 0
170 control.orientation.z = 0
171 control.name =
"move_x"
172 control.interaction_mode = InteractiveMarkerControl.MOVE_AXIS
173 int_marker.controls.append(control)
174 control = InteractiveMarkerControl()
175 control.orientation.w = 1
176 control.orientation.x = 0
177 control.orientation.y = 1
178 control.orientation.z = 0
179 control.name =
"rotate_y"
180 control.interaction_mode = InteractiveMarkerControl.ROTATE_AXIS
181 int_marker.controls.append(control)
182 control = InteractiveMarkerControl()
183 control.orientation.w = 1
184 control.orientation.x = 0
185 control.orientation.y = 1
186 control.orientation.z = 0
187 control.name =
"move_y"
188 control.interaction_mode = InteractiveMarkerControl.MOVE_AXIS
189 int_marker.controls.append(control)
190 control = InteractiveMarkerControl()
191 control.orientation.w = 1
192 control.orientation.x = 0
193 control.orientation.y = 0
194 control.orientation.z = 1
195 control.name =
"rotate_z"
196 control.interaction_mode = InteractiveMarkerControl.ROTATE_AXIS
197 int_marker.controls.append(control)
198 control = InteractiveMarkerControl()
199 control.orientation.w = 1
200 control.orientation.x = 0
201 control.orientation.y = 0
202 control.orientation.z = 1
203 control.name =
"move_z"
204 control.interaction_mode = InteractiveMarkerControl.MOVE_AXIS
205 int_marker.controls.append(control)
206 control = InteractiveMarkerControl()
207 control.orientation.w = 1
208 control.orientation.x = 1
209 control.orientation.y = 1
210 control.orientation.z = 1
211 control.name =
"move_3D"
212 control.always_visible =
True
214 control.interaction_mode = InteractiveMarkerControl.MOVE_3D
215 int_marker.controls.append(control)
217 server.insert(int_marker, process_feedback)
218 server.applyChanges()
221 while not rospy.is_shutdown():
226 server.setPose(
"centering_frame_pose", marker_pose.pose)
227 server.applyChanges()