Go to the documentation of this file.00001
00002
00003 import math
00004 import numpy
00005 import commands
00006 import sys
00007
00008 import rospy
00009 import roslib
00010
00011 roslib.load_manifest('jsk_joy')
00012
00013 from view_controller_msgs.msg import CameraPlacement
00014 from geometry_msgs.msg import PoseStamped
00015 from sensor_msgs.msg import Joy
00016 import tf.transformations
00017
00018 sys.path.append(commands.getoutput('rospack find jsk_joy') + '/scripts')
00019 from trackpoint_status import TrackpointStatus
00020 from nanokontrol_status import NanoKONTROL2Status
00021 from nanopad_status import NanoPAD2Status
00022
00023 INTERACTIVE_MARKER_TOPIC = '/goal_marker'
00024 pre_pose = None
00025
00026 def nanokontrol_joyCB(msg):
00027 global nanokontrol_st
00028 nanokontrol_st = NanoKONTROL2Status(msg)
00029
00030 def nanopad_joyCB(msg):
00031 global nanopad_st
00032 nanopad_st = NanoPAD2Status(msg)
00033
00034 def trackpoint_joyCB(msg):
00035 global pre_view, g_seq_num, pre_pose
00036 global nanokontrol_st, nanopad_st
00037 if not pre_pose:
00038 pre_pose = PoseStamped()
00039 status = TrackpointStatus(msg)
00040
00041
00042
00043 new_pose = PoseStamped()
00044 new_pose.header.frame_id = '/map'
00045 new_pose.header.stamp = rospy.Time(0.0)
00046
00047 local_xy_move = numpy.array((0.0,
00048 0.0,
00049 0.0,
00050 1.0))
00051 z_move = 0
00052 yaw_move = 0
00053 if ( nanopad_st and nanopad_st.buttonL1 ):
00054 scale_xy = 1500.0
00055 scale_z = 1500.0
00056 scale_yaw = 1000.0
00057 else:
00058 scale_xy = 500.0
00059 scale_z = 500.0
00060 scale_yaw = 300.0
00061
00062 if not ( status.left or status.right or status.middle ):
00063
00064
00065
00066
00067 if ( nanopad_st and nanopad_st.buttonU1 ):
00068 z_move = status.y / scale_z
00069 elif ( nanopad_st and nanopad_st.buttonU2 ):
00070 yaw_move = status.y / scale_yaw
00071 else:
00072 local_xy_move = numpy.array((- status.x / scale_xy,
00073 - status.y / scale_xy,
00074 0.0,
00075 1.0))
00076 q = numpy.array((pre_pose.pose.orientation.x,
00077 pre_pose.pose.orientation.y,
00078 pre_pose.pose.orientation.z,
00079 pre_pose.pose.orientation.w))
00080
00081
00082 xy_move = local_xy_move
00083
00084 new_pose.pose.position.x = pre_pose.pose.position.x + xy_move[0]
00085 new_pose.pose.position.y = pre_pose.pose.position.y + xy_move[1]
00086 new_pose.pose.position.z = pre_pose.pose.position.z + z_move
00087 (roll, pitch, yaw) = tf.transformations.euler_from_quaternion(q)
00088 yaw = yaw + yaw_move
00089
00090 new_q = tf.transformations.quaternion_from_euler(roll, pitch, yaw)
00091 new_pose.pose.orientation.x = new_q[0]
00092 new_pose.pose.orientation.y = new_q[1]
00093 new_pose.pose.orientation.z = new_q[2]
00094 new_pose.pose.orientation.w = new_q[3]
00095 g_interactive_pub.publish(new_pose)
00096 pre_pose = new_pose
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 def main():
00144 global g_camera_pub, g_interactive_pub
00145 global nanokontrol_st, nanopad_st
00146 rospy.sleep(1)
00147 rospy.init_node('trackpoint_controller')
00148 g_camera_pub = rospy.Publisher('/rviz/camera_placement', CameraPlacement)
00149 g_interactive_pub = rospy.Publisher(INTERACTIVE_MARKER_TOPIC + '/move_marker', PoseStamped)
00150 trackpoint_sub = rospy.Subscriber('/trackpoint/joy', Joy, trackpoint_joyCB)
00151 nanokontrol_sub= rospy.Subscriber('/nanokontrol/joy', Joy, nanokontrol_joyCB)
00152 nanopad_sub= rospy.Subscriber('/nanopad/joy', Joy, nanopad_joyCB)
00153 nanokontrol_st = None
00154 nanopad_st = None
00155
00156 rospy.spin()
00157
00158
00159 if __name__ == '__main__':
00160 main()
00161