5 from tf
import transformations
7 from geometry_msgs.msg
import Vector3, Quaternion, Transform, Point, Pose
13 p_arr = ros_numpy.numpify(p)
14 np.testing.assert_array_equal(p_arr, [1, 2, 3])
16 p_arrh = ros_numpy.numpify(p, hom=
True)
17 np.testing.assert_array_equal(p_arrh, [1, 2, 3, 1])
19 self.assertEqual(p, ros_numpy.msgify(Point, p_arr))
20 self.assertEqual(p, ros_numpy.msgify(Point, p_arrh))
21 self.assertEqual(p, ros_numpy.msgify(Point, p_arrh * 2))
26 v_arr = ros_numpy.numpify(v)
27 np.testing.assert_array_equal(v_arr, [1, 2, 3])
29 v_arrh = ros_numpy.numpify(v, hom=
True)
30 np.testing.assert_array_equal(v_arrh, [1, 2, 3, 0])
32 self.assertEqual(v, ros_numpy.msgify(Vector3, v_arr))
33 self.assertEqual(v, ros_numpy.msgify(Vector3, v_arrh))
35 with self.assertRaises(AssertionError):
36 ros_numpy.msgify(Vector3, np.array([0, 0, 0, 1]))
40 translation=Vector3(1, 2, 3),
41 rotation=Quaternion(*transformations.quaternion_from_euler(np.pi, 0, 0))
44 t_mat = ros_numpy.numpify(t)
46 np.testing.assert_allclose(t_mat.dot([0, 0, 1, 1]), [1.0, 2.0, 2.0, 1.0])
48 msg = ros_numpy.msgify(Transform, t_mat)
50 np.testing.assert_allclose(msg.translation.x, t.translation.x)
51 np.testing.assert_allclose(msg.translation.y, t.translation.y)
52 np.testing.assert_allclose(msg.translation.z, t.translation.z)
53 np.testing.assert_allclose(msg.rotation.x, t.rotation.x)
54 np.testing.assert_allclose(msg.rotation.y, t.rotation.y)
55 np.testing.assert_allclose(msg.rotation.z, t.rotation.z)
56 np.testing.assert_allclose(msg.rotation.w, t.rotation.w)
60 position=Point(1.0, 2.0, 3.0),
61 orientation=Quaternion(*transformations.quaternion_from_euler(np.pi, 0, 0))
64 t_mat = ros_numpy.numpify(t)
66 np.testing.assert_allclose(t_mat.dot([0, 0, 1, 1]), [1.0, 2.0, 2.0, 1.0])
68 msg = ros_numpy.msgify(Pose, t_mat)
70 np.testing.assert_allclose(msg.position.x, t.position.x)
71 np.testing.assert_allclose(msg.position.y, t.position.y)
72 np.testing.assert_allclose(msg.position.z, t.position.z)
73 np.testing.assert_allclose(msg.orientation.x, t.orientation.x)
74 np.testing.assert_allclose(msg.orientation.y, t.orientation.y)
75 np.testing.assert_allclose(msg.orientation.z, t.orientation.z)
76 np.testing.assert_allclose(msg.orientation.w, t.orientation.w)
78 if __name__ ==
'__main__':