dual_arm_interactive_marker.py
Go to the documentation of this file.
1 #!/usr/bin/env python
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.
5 """
6 
7 import rospy
8 import argparse
9 
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
16 
17 marker_pose = PoseStamped()
18 
19 has_error = False
20 left_has_error = False
21 right_has_error = False
22 
23 pose_pub = None
24 
25 
26 def make_sphere(scale=0.3):
27  """
28  This function returns sphere marker for 3D translational movements.
29  :param scale: scales the size of the sphere
30  :return: sphere marker
31  """
32  marker = 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
37  marker.color.r = 0.5
38  marker.color.g = 0.5
39  marker.color.b = 0.5
40  marker.color.a = 1.0
41  return marker
42 
43 
45  """
46  This function publishes desired centering pose which the controller will subscribe to.
47  :return: None
48  """
49  marker_pose.header.stamp = rospy.Time(0)
50  pose_pub.publish(marker_pose)
51 
52 
54  """
55  This callback function set `has_error` variable to True if the left arm is having an error.
56  :param msg: FrankaState msg data
57  :return: None
58  """
59  global has_error, left_has_error
60  if msg.robot_mode == FrankaState.ROBOT_MODE_MOVE:
61  left_has_error = False
62  else:
63  left_has_error = True
64  has_error = left_has_error or right_has_error
65 
66 
68  """
69  This callback function set `has_error` variable to True if the right arm is having an error.
70  :param msg: FrankaState msg data
71  :return: None
72  """
73  global has_error, right_has_error
74  if msg.robot_mode == FrankaState.ROBOT_MODE_MOVE:
75  right_has_error = False
76  else:
77  right_has_error = True
78  has_error = left_has_error or right_has_error
79 
80 
82  """
83  This function resets the marker pose to current "middle pose" of left and right arm EEs.
84  :return: None
85  """
86 
87  global marker_pose
88  marker_pose = rospy.wait_for_message(
89  "dual_arm_cartesian_impedance_example_controller/centering_frame", PoseStamped)
90 
91 
92 def process_feedback(feedback):
93  """
94  This callback function clips the marker_pose inside a predefined box to prevent misuse of the
95  marker.
96  :param feedback: feedback data of interactive marker
97  :return: None
98  """
99  global marker_pose
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()
106 
107 
108 if __name__ == "__main__":
109  rospy.init_node("target_pose_node")
110 
111  parser = argparse.ArgumentParser("dual_panda_interactive_marker.py")
112  parser.add_argument("--left_arm_id",
113  help="The id of the left arm.",
114  required=True)
115  parser.add_argument("--right_arm_id",
116  help="The id of the right arm.",
117  required=True)
118  parser.add_argument('args', nargs=argparse.REMAINDER)
119  args = parser.parse_args()
120 
121  # Arm IDs of left and right arms
122  left_arm_id = args.left_arm_id
123  right_arm_id = args.right_arm_id
124 
125  # Initialize subscribers for error states of the arms
126  left_state_sub = rospy.Subscriber(left_arm_id + "_state_controller/franka_states",
127  FrankaState, left_franka_state_callback)
128 
129  right_state_sub = rospy.Subscriber(right_arm_id + "_state_controller/franka_states",
130  FrankaState, right_franka_state_callback)
131 
132  # Set marker pose to be the current "middle pose" of both EEs
134 
135  # Initialize publisher for publishing desired centering pose
136  pose_pub = rospy.Publisher(
137  "dual_arm_cartesian_impedance_example_controller/centering_frame_target_pose",
138  PoseStamped,
139  queue_size=1)
140 
141  # Interactive marker settings
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"
148  "BE CAREFUL! \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
155 
156  # insert a box
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)
165 
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
213  control.markers.append(make_sphere())
214  control.interaction_mode = InteractiveMarkerControl.MOVE_3D
215  int_marker.controls.append(control)
216 
217  server.insert(int_marker, process_feedback)
218  server.applyChanges()
219 
220  # main loop
221  while not rospy.is_shutdown():
223  if has_error:
226  server.setPose("centering_frame_pose", marker_pose.pose)
227  server.applyChanges()
228  rospy.sleep(0.5)
229  rospy.sleep(0.1)
dual_arm_interactive_marker.left_franka_state_callback
def left_franka_state_callback(msg)
Definition: dual_arm_interactive_marker.py:53
dual_arm_interactive_marker.publish_target_pose
def publish_target_pose()
Definition: dual_arm_interactive_marker.py:44
dual_arm_interactive_marker.right_franka_state_callback
def right_franka_state_callback(msg)
Definition: dual_arm_interactive_marker.py:67
dual_arm_interactive_marker.make_sphere
def make_sphere(scale=0.3)
Definition: dual_arm_interactive_marker.py:26
dual_arm_interactive_marker.process_feedback
def process_feedback(feedback)
Definition: dual_arm_interactive_marker.py:92
dual_arm_interactive_marker.reset_marker_pose_blocking
def reset_marker_pose_blocking()
Definition: dual_arm_interactive_marker.py:81


franka_example_controllers
Author(s): Franka Emika GmbH
autogenerated on Mon Sep 19 2022 02:33:26