interactive_marker.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 
3 import rospy
4 import tf.transformations
5 import numpy as np
6 
8  InteractiveMarkerServer, InteractiveMarkerFeedback
9 from visualization_msgs.msg import InteractiveMarker, \
10  InteractiveMarkerControl
11 from geometry_msgs.msg import PoseStamped
12 from franka_msgs.msg import FrankaState
13 
14 marker_pose = PoseStamped()
15 initial_pose_found = False
16 pose_pub = None
17 # [[min_x, max_x], [min_y, max_y], [min_z, max_z]]
18 position_limits = [[-0.6, 0.6], [-0.6, 0.6], [0.05, 0.9]]
19 
20 
21 def publisherCallback(msg, link_name):
22  marker_pose.header.frame_id = link_name
23  marker_pose.header.stamp = rospy.Time(0)
24  pose_pub.publish(marker_pose)
25 
26 
28  initial_quaternion = \
29  tf.transformations.quaternion_from_matrix(
30  np.transpose(np.reshape(msg.O_T_EE,
31  (4, 4))))
32  initial_quaternion = initial_quaternion / np.linalg.norm(initial_quaternion)
33  marker_pose.pose.orientation.x = initial_quaternion[0]
34  marker_pose.pose.orientation.y = initial_quaternion[1]
35  marker_pose.pose.orientation.z = initial_quaternion[2]
36  marker_pose.pose.orientation.w = initial_quaternion[3]
37  marker_pose.pose.position.x = msg.O_T_EE[12]
38  marker_pose.pose.position.y = msg.O_T_EE[13]
39  marker_pose.pose.position.z = msg.O_T_EE[14]
40  global initial_pose_found
41  initial_pose_found = True
42 
43 
44 def processFeedback(feedback):
45  if feedback.event_type == InteractiveMarkerFeedback.POSE_UPDATE:
46  marker_pose.pose.position.x = max([min([feedback.pose.position.x,
47  position_limits[0][1]]),
48  position_limits[0][0]])
49  marker_pose.pose.position.y = max([min([feedback.pose.position.y,
50  position_limits[1][1]]),
51  position_limits[1][0]])
52  marker_pose.pose.position.z = max([min([feedback.pose.position.z,
53  position_limits[2][1]]),
54  position_limits[2][0]])
55  marker_pose.pose.orientation = feedback.pose.orientation
56  server.applyChanges()
57 
58 
59 if __name__ == "__main__":
60  rospy.init_node("equilibrium_pose_node")
61  state_sub = rospy.Subscriber("franka_state_controller/franka_states",
62  FrankaState, franka_state_callback)
63  listener = tf.TransformListener()
64  link_name = rospy.get_param("~link_name")
65 
66  # Get initial pose for the interactive marker
67  while not initial_pose_found:
68  rospy.sleep(1)
69  state_sub.unregister()
70 
71  pose_pub = rospy.Publisher(
72  "equilibrium_pose", PoseStamped, queue_size=10)
73  server = InteractiveMarkerServer("equilibrium_pose_marker")
74  int_marker = InteractiveMarker()
75  int_marker.header.frame_id = link_name
76  int_marker.scale = 0.3
77  int_marker.name = "equilibrium_pose"
78  int_marker.description = ("Equilibrium Pose\nBE CAREFUL! "
79  "If you move the \nequilibrium "
80  "pose the robot will follow it\n"
81  "so be aware of potential collisions")
82  int_marker.pose = marker_pose.pose
83  # run pose publisher
84  rospy.Timer(rospy.Duration(0.005),
85  lambda msg: publisherCallback(msg, link_name))
86 
87  # insert a box
88  control = InteractiveMarkerControl()
89  control.orientation.w = 1
90  control.orientation.x = 1
91  control.orientation.y = 0
92  control.orientation.z = 0
93  control.name = "rotate_x"
94  control.interaction_mode = InteractiveMarkerControl.ROTATE_AXIS
95  int_marker.controls.append(control)
96 
97  control = InteractiveMarkerControl()
98  control.orientation.w = 1
99  control.orientation.x = 1
100  control.orientation.y = 0
101  control.orientation.z = 0
102  control.name = "move_x"
103  control.interaction_mode = InteractiveMarkerControl.MOVE_AXIS
104  int_marker.controls.append(control)
105  control = InteractiveMarkerControl()
106  control.orientation.w = 1
107  control.orientation.x = 0
108  control.orientation.y = 1
109  control.orientation.z = 0
110  control.name = "rotate_y"
111  control.interaction_mode = InteractiveMarkerControl.ROTATE_AXIS
112  int_marker.controls.append(control)
113  control = InteractiveMarkerControl()
114  control.orientation.w = 1
115  control.orientation.x = 0
116  control.orientation.y = 1
117  control.orientation.z = 0
118  control.name = "move_y"
119  control.interaction_mode = InteractiveMarkerControl.MOVE_AXIS
120  int_marker.controls.append(control)
121  control = InteractiveMarkerControl()
122  control.orientation.w = 1
123  control.orientation.x = 0
124  control.orientation.y = 0
125  control.orientation.z = 1
126  control.name = "rotate_z"
127  control.interaction_mode = InteractiveMarkerControl.ROTATE_AXIS
128  int_marker.controls.append(control)
129  control = InteractiveMarkerControl()
130  control.orientation.w = 1
131  control.orientation.x = 0
132  control.orientation.y = 0
133  control.orientation.z = 1
134  control.name = "move_z"
135  control.interaction_mode = InteractiveMarkerControl.MOVE_AXIS
136  int_marker.controls.append(control)
137  server.insert(int_marker, processFeedback)
138 
139  server.applyChanges()
140 
141  rospy.spin()
def publisherCallback(msg, link_name)
def processFeedback(feedback)


franka_example_controllers
Author(s): Franka Emika GmbH
autogenerated on Fri Oct 23 2020 03:47:17