transformable_spacenav_configure.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import rospy
4 
5 PKG='sensor_msgs'
6 
7 import imp
8 try:
9  imp.find_module(PKG)
10 except:
11  import roslib;roslib.load_manifest(PKG)
12 
13 from sensor_msgs.msg import Joy
14 from geometry_msgs.msg import *
15 from std_msgs.msg import *
16 from tf.transformations import quaternion_from_euler
17 from jsk_rviz_plugins.msg import OverlayText
18 
19 x_max = 10
20 y_max = 10
21 z_max = 10
22 
23 set_pose_pub = None
24 prev_b = 0
25 translate_mode = True
26 display_separate_mode = True
27 def callback(msg):
28  global x_max, y_max, z_max, rx_max, ry_max, rz_max, set_pose_pub
29  global prev_b, translate_mode
30 
31  a = msg.axes
32  b = msg.buttons
33 
34  if prev_b == 0 and (b[0] == 1 or b[1] == 1):
35  translate_mode = not translate_mode
36 
37  if b[0] == 1 or b[1] == 1:
38  prev_b = 1
39  else:
40  prev_b = 0
41 
42  x_v1,y_v1,z_v1,rx_v1,ry_v1,rz_v1 = a
43 
44  target_pose = Pose()
45  if not separate_mode or (separate_mode and translate_mode):
46  target_pose.position.x = x_v1 * x_max
47  target_pose.position.y = y_v1 * y_max
48  target_pose.position.z = z_v1 * z_max
49 
50  target_pose.orientation.w = 1
51  if not separate_mode or (separate_mode and not translate_mode):
52  q = quaternion_from_euler(rx_v1 * rx_max, ry_v1 * ry_max, rz_v1 * rz_max, 'rxyz')
53  target_pose.orientation.x = q[0]
54  target_pose.orientation.y = q[1]
55  target_pose.orientation.z = q[2]
56  target_pose.orientation.w = q[3]
57 
58  set_pose_pub.publish(target_pose)
59  if translate_mode and separate_mode:
60  publishModeText("TranslateMode")
61  elif separate_mode:
62  publishModeText("RotateMode")
63 
64 def publishModeText(message):
65  send_text = OverlayText()
66  send_text.text = message
67  send_text.top = 100
68  send_text.left = 0
69  send_text.width = 300
70  send_text.height = 50
71 
72  send_text.bg_color.r = 0.9;
73  send_text.bg_color.b = 0.9;
74  send_text.bg_color.g = 0.9;
75  send_text.bg_color.a = 0.1;
76  send_text.fg_color.r = 0.3;
77  send_text.fg_color.g = 0.8;
78  send_text.fg_color.b = 0.3;
79  send_text.fg_color.a = 1;
80  send_text.line_width = 1;
81  send_text.text_size = 30;
82  send_text_pub.publish(send_text);
83 
84 
85 if __name__ == "__main__":
86  rospy.init_node("transformable_spacenav_configure")
87  ns = rospy.get_param('~transformable_interactive_server_nodename', '')
88 
89  x_max = rospy.get_param("~x_max")
90  y_max = rospy.get_param("~y_max")
91  z_max = rospy.get_param("~z_max")
92  rx_max = rospy.get_param("~rx_max")
93  ry_max = rospy.get_param("~ry_max")
94  rz_max = rospy.get_param("~rz_max")
95 
96  separate_mode = rospy.get_param("~separate_mode")
97  display_separate_mode = rospy.get_param("~display_separate_mode")
98 
99  set_pose_pub = rospy.Publisher(ns+"/add_pose", Pose)
100  send_text_pub = rospy.Publisher("separate_mode_text", OverlayText)
101 
102  s = rospy.Subscriber("input_joy", Joy, callback)
103  rospy.spin()
104 


jsk_interactive_marker
Author(s): furuta
autogenerated on Sat Mar 20 2021 03:03:33