5 from math
import fmod, pi
11 from tf.msg
import tfMessage
12 from tf.transformations
import euler_from_quaternion
13 from std_srvs.srv
import Empty
24 for t
in msg.transforms:
25 if t.header.frame_id ==
'map':
28 print 'Curr:\t %16.6f %16.6f %16.6f' % (self.tf.translation.x, self.tf.translation.y, a_curr)
30 print 'Diff:\t %16.6f %16.6f %16.6f' % (
31 abs(self.tf.translation.x - self.
target_x), abs(self.tf.translation.y - self.
target_y), a_diff)
34 rot = self.tf.rotation
35 a = euler_from_quaternion([rot.x, rot.y, rot.z, rot.w])[2]
38 return (a, abs(fmod(a - d_a + 5*pi, 2*pi) - pi))
41 global_localization = int(sys.argv[1])
45 tolerance_d = float(sys.argv[5])
46 tolerance_a = float(sys.argv[6])
47 target_time = float(sys.argv[7])
49 if global_localization == 1:
51 rospy.wait_for_service(
'global_localization')
52 global_localization = rospy.ServiceProxy(
'global_localization', Empty)
55 rospy.init_node(
'test', anonymous=
True)
56 while(rospy.rostime.get_time() == 0.0):
59 start_time = rospy.rostime.get_time()
61 rospy.Subscriber(
'/tf', tfMessage, self.
tf_cb)
63 while (rospy.rostime.get_time() - start_time) < target_time:
68 print 'Curr:\t %16.6f %16.6f %16.6f' % (self.tf.translation.x, self.tf.translation.y, a_curr)
70 print 'Diff:\t %16.6f %16.6f %16.6f' % (
71 abs(self.tf.translation.x - self.
target_x), abs(self.tf.translation.y - self.
target_y), a_diff)
72 self.assertNotEquals(self.
tf,
None)
73 self.assertTrue(abs(self.tf.translation.x - self.
target_x) <= tolerance_d)
74 self.assertTrue(abs(self.tf.translation.y - self.
target_y) <= tolerance_d)
75 self.assertTrue(a_diff <= tolerance_a)
77 if __name__ ==
'__main__':
78 rostest.run(
'amcl',
'amcl_localization',
79 TestBasicLocalization, sys.argv)
def test_basic_localization(self)
def compute_angle_diff(self)