laser_client.py
Go to the documentation of this file.
00001 #from sound_play.libsoundplay import SoundClient
00002 import hrl_lib.tf_utils as tfu
00003 from std_msgs.msg import String
00004 import rospy
00005 import tf
00006 
00007 import subprocess as sb
00008 import numpy as np
00009 import geometry_msgs.msg as gms
00010 import os
00011 
00012 class LaserPointerClient:
00013 
00014     def __init__(self, target_frame='/base_link', tf_listener=None):
00015         self.dclick_cbs = []
00016         self.point_cbs = []
00017         self.target_frame = target_frame
00018         self.laser_point_base = None
00019         self.base_sound_path = (sb.Popen(["rospack", "find", "laser_interface"], stdout=sb.PIPE).communicate()[0]).strip()
00020         #self.sound = SoundClient()
00021 
00022         if tf_listener == None:
00023             self.tf_listener = tf.TransformListener()
00024         else:
00025             self.tf_listener = tf_listener
00026 
00027         rospy.Subscriber('cursor3d', gms.PointStamped, self.laser_point_handler)
00028         self.double_click = rospy.Subscriber('mouse_left_double_click', String, self.double_click_cb)
00029         os.system("aplay %s" % (self.base_sound_path + '/sounds/beep_beep.wav'))
00030         #self.sound.waveSound().play()
00031 
00032 
00033     def transform_point(self, point_stamped):
00034         point_head = point_stamped.point
00035         #Tranform into base link
00036         base_T_head = tfu.transform(self.target_frame, point_stamped.header.frame_id, self.tf_listener)
00037         point_mat_head = tfu.translation_matrix([point_head.x, point_head.y, point_head.z])
00038         point_mat_base = base_T_head * point_mat_head
00039         t_base, _ = tfu.matrix_as_tf(point_mat_base)
00040         return np.matrix(t_base).T
00041         
00042     def laser_point_handler(self, point_stamped):
00043         #self.sound.waveSound(self.base_sound_path + '/sounds/blow.wav').play()
00044         #os.system("aplay %s" % (self.base_sound_path + '/sounds/beeeeeep.wav'))
00045         self.laser_point_base = self.transform_point(point_stamped)
00046         for f in self.point_cbs:
00047             f(self.laser_point_base)
00048 
00049     def double_click_cb(self, a_str):
00050         rospy.loginfo('Double CLICKED')
00051         #self.sound.waveSound(self.base_sound_path + '/sounds/beep.wav').play()
00052         os.system("aplay %s" % (self.base_sound_path + '/sounds/beep_beep.wav'))
00053         #if self.laser_point_base != None:
00054         for f in self.dclick_cbs:
00055             f(self.laser_point_base)
00056         self.laser_point_base = None
00057 
00058     def add_double_click_cb(self, func):
00059         self.dclick_cbs.append(func)
00060 
00061     def add_point_cb(self, func):
00062         self.point_cbs.append(func)


laser_interface
Author(s): Hai Nguyen and Travis Deyle. Advisor: Prof. Charlie Kemp, Lab: Healthcare Robotics Lab at Georgia Tech
autogenerated on Wed Nov 27 2013 11:45:51