head_pose_filter.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 import roslib; roslib.load_manifest('head_pose_estimation')
00003 import rospy
00004 from geometry_msgs.msg import PoseStamped, Pose, Point, Quaternion 
00005 from headmath.conversions import pose_quat_to_euler, pose_euler_to_quat
00006 from collections import deque
00007 import numpy as np
00008 
00009 
00010 
00011 poses = None
00012 pose_pub = None
00013 
00014 def pose_sub(pose_msg):
00015         poses.append(pose_quat_to_euler(pose_msg))
00016                                  
00017         if len(poses) == poses.maxlen:
00018                 filtered = np.median(np.array(poses), 0)
00019                 pose_pub.publish(
00020                         PoseStamped(
00021                                 header = pose_msg.header,
00022                                 pose   = pose_euler_to_quat(filtered)
00023                         )
00024                 )
00025 
00026 
00027 if __name__ == '__main__':
00028         rospy.init_node('head_pose_filter')
00029         
00030         window_size = rospy.get_param("~window_size", 3)
00031         rospy.loginfo("window size is: %s" % window_size)
00032         poses = deque([], window_size)
00033         rospy.Subscriber('head_pose', PoseStamped, pose_sub)
00034         pose_pub = rospy.Publisher('head_pose_filtered', PoseStamped)
00035         rospy.spin()


head_pose_estimation
Author(s): Daniel Lazewatsky
autogenerated on Mon Oct 6 2014 00:23:14