trackpoint_controller.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import math
4 import numpy
5 import commands
6 import sys
7 
8 import rospy
9 import roslib
10 
11 roslib.load_manifest('jsk_joy')
12 
13 from view_controller_msgs.msg import CameraPlacement
14 from geometry_msgs.msg import PoseStamped
15 from sensor_msgs.msg import Joy
16 import tf.transformations
17 
18 sys.path.append(commands.getoutput('rospack find jsk_joy') + '/scripts')
19 from trackpoint_status import TrackpointStatus
20 from nanokontrol_status import NanoKONTROL2Status
21 from nanopad_status import NanoPAD2Status
22 
23 INTERACTIVE_MARKER_TOPIC = '/goal_marker'
24 pre_pose = None
25 
27  global nanokontrol_st
28  nanokontrol_st = NanoKONTROL2Status(msg)
29 
30 def nanopad_joyCB(msg):
31  global nanopad_st
32  nanopad_st = NanoPAD2Status(msg)
33 
35  global pre_view, g_seq_num, pre_pose
36  global nanokontrol_st, nanopad_st
37  if not pre_pose:
38  pre_pose = PoseStamped()
39  status = TrackpointStatus(msg)
40 
41  # rospy.loginfo(status)
42  # move interactive marker
43  new_pose = PoseStamped()
44  new_pose.header.frame_id = '/map'
45  new_pose.header.stamp = rospy.Time(0.0)
46  # move in local
47  local_xy_move = numpy.array((0.0,
48  0.0,
49  0.0,
50  1.0))
51  z_move = 0
52  yaw_move = 0
53  if ( nanopad_st and nanopad_st.buttonL1 ):
54  scale_xy = 1500.0
55  scale_z = 1500.0
56  scale_yaw = 1000.0
57  else:
58  scale_xy = 500.0
59  scale_z = 500.0
60  scale_yaw = 300.0
61 
62  if not ( status.left or status.right or status.middle ):
63  # if ( nanokontrol_st and nanokontrol_st.S8 ):
64  # z_move = status.y / scale
65  # elif ( nanokontrol_st and nanokontrol_st.R8 ):
66  # yaw_move = status.y / scale
67  if ( nanopad_st and nanopad_st.buttonU1 ):
68  z_move = status.y / scale_z
69  elif ( nanopad_st and nanopad_st.buttonU2 ):
70  yaw_move = status.y / scale_yaw
71  else:
72  local_xy_move = numpy.array((- status.x / scale_xy,
73  - status.y / scale_xy,
74  0.0,
75  1.0))
76  q = numpy.array((pre_pose.pose.orientation.x,
77  pre_pose.pose.orientation.y,
78  pre_pose.pose.orientation.z,
79  pre_pose.pose.orientation.w))
80  # xy_move = numpy.dot(tf.transformations.quaternion_matrix(q),
81  # local_xy_move)
82  xy_move = local_xy_move
83 
84  new_pose.pose.position.x = pre_pose.pose.position.x + xy_move[0]
85  new_pose.pose.position.y = pre_pose.pose.position.y + xy_move[1]
86  new_pose.pose.position.z = pre_pose.pose.position.z + z_move
87  (roll, pitch, yaw) = tf.transformations.euler_from_quaternion(q)
88  yaw = yaw + yaw_move
89 
90  new_q = tf.transformations.quaternion_from_euler(roll, pitch, yaw)
91  new_pose.pose.orientation.x = new_q[0]
92  new_pose.pose.orientation.y = new_q[1]
93  new_pose.pose.orientation.z = new_q[2]
94  new_pose.pose.orientation.w = new_q[3]
95  g_interactive_pub.publish(new_pose)
96  pre_pose = new_pose
97 
98  # view update
99  # view = ViewProperty()
100  # view.focus = numpy.copy(pre_view.focus)
101  # view.yaw = pre_view.yaw
102  # view.pitch = pre_view.pitch
103  # view.distance = pre_view.distance
104  # if status.R3:
105  # view.distance = view.distance - status.left_analog_y * 0.1
106  # # calc camera orietation
107  # if status.left:
108  # view_x = 1.0
109  # elif status.right:
110  # view_x = -1.0
111  # else:
112  # view_x = 0.0
113  # if status.up:
114  # view_y = 1.0
115  # elif status.down:
116  # view_y = -1.0
117  # else:
118  # view_y = 0.0
119  # focus_diff = numpy.dot(view.cameraOrientation(),
120  # numpy.array((view_x / 10.0 / view.distance,
121  # view_y / 10.0 / view.distance,
122  # 0)))
123  # view.focus = view.focus + focus_diff
124  # if status.L2 and status.R2: #align to marker
125  # view.distance = 1.0
126  # view.focus = numpy.array((new_pose.pose.position.x,
127  # new_pose.pose.position.y,
128  # new_pose.pose.position.z))
129  # #view.yaw = math.pi
130  # view.yaw = yaw + math.pi
131  # view.pitch = math.pi / 2.0 - 0.01
132  # else:
133  # view.yaw = view.yaw - 0.5 * status.right_analog_x
134  # view.pitch = view.pitch + 0.5 * status.right_analog_y
135  # if view.pitch > math.pi / 2.0 - 0.01:
136  # view.pitch = math.pi / 2.0 - 0.01
137  # elif view.pitch < - math.pi / 2.0 + 0.01:
138  # view.pitch = - math.pi / 2.0 + 0.01
139  # g_camera_pub.publish(view.cameraPlacement())
140  # pre_view = view
141 
142 
143 def main():
144  global g_camera_pub, g_interactive_pub
145  global nanokontrol_st, nanopad_st
146  rospy.sleep(1)
147  rospy.init_node('trackpoint_controller')
148  g_camera_pub = rospy.Publisher('/rviz/camera_placement', CameraPlacement)
149  g_interactive_pub = rospy.Publisher(INTERACTIVE_MARKER_TOPIC + '/move_marker', PoseStamped)
150  trackpoint_sub = rospy.Subscriber('/trackpoint/joy', Joy, trackpoint_joyCB)
151  nanokontrol_sub= rospy.Subscriber('/nanokontrol/joy', Joy, nanokontrol_joyCB)
152  nanopad_sub= rospy.Subscriber('/nanopad/joy', Joy, nanopad_joyCB)
153  nanokontrol_st = None
154  nanopad_st = None
155 
156  rospy.spin()
157 
158 
159 if __name__ == '__main__':
160  main()
161 


jsk_interactive_test
Author(s): Kei Okada
autogenerated on Sat Mar 20 2021 03:03:46