test_trajectory_point.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Copyright (c) 2016-2019 The UUV Simulator Authors.
3 # All rights reserved.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 import roslib
18 
19 PKG = 'uuv_trajectory_control'
20 roslib.load_manifest(PKG)
21 
22 import sys
23 import unittest
24 import numpy as np
25 from uuv_trajectory_generator import TrajectoryPoint
26 from uuv_control_msgs.msg import TrajectoryPoint as TrajectoryPointMsg
27 
28 
29 class TestTrajectoryPoint(unittest.TestCase):
31  p = TrajectoryPoint()
32  self.assertEquals(p.pos.size, 3, 'Position vector len() is incorrect')
33  self.assertTrue(np.array_equal(p.pos, [0, 0, 0]), 'Position initialization failed')
34 
36  p = TrajectoryPoint()
37  p.pos = [1, 2, 3]
38  self.assertEquals(p.pos[0], 1, 'X position was initialized wrong')
39  self.assertEquals(p.pos[1], 2, 'Y position was initialized wrong')
40  self.assertEquals(p.pos[2], 3, 'Z position was initialized wrong')
41 
43  p = TrajectoryPoint()
44  self.assertEquals(p.rotq.size, 4, 'Quaternion vector len() is incorrect')
45  self.assertTrue(np.array_equal(p.rotq, [0, 0, 0, 1]), 'Quaternion initialization failed')
46 
47  def test_to_message(self):
48  p0 = TrajectoryPoint()
49  p0.t = 1
50  p0.pos = [1, 2, 3]
51  p0.rotq = [0, 0, 1, 1]
52  p0.vel = [1, 2, 3, 4, 5, 6]
53  p0.acc = [1, 2, 3, 4, 5, 6]
54 
55  p1 = TrajectoryPoint()
56  p1.from_message(p0.to_message())
57 
58  self.assertEquals(p0, p1, 'Point to message conversion failed')
59 
60  def test_to_dict(self):
61  p0 = TrajectoryPoint()
62  p0.t = 1
63  p0.pos = [1, 2, 3]
64  p0.rotq = [0, 0, 1, 1]
65  p0.vel = [1, 2, 3, 4, 5, 6]
66  p0.acc = [1, 2, 3, 4, 5, 6]
67 
68  p1 = TrajectoryPoint()
69  p1.from_dict(p0.to_dict())
70 
71  self.assertEquals(p0, p1, 'Point to dict conversion failed')
72 
73 if __name__ == '__main__':
74  import rosunit
75  rosunit.unitrun(PKG, 'test_trajectory_point', TestTrajectoryPoint)


uuv_trajectory_control
Author(s):
autogenerated on Thu Jun 18 2020 03:28:42