test_sphere_vehicle.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Copyright (c) 2016 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 from __future__ import print_function
17 import rospy
18 import unittest
19 import numpy as np
20 from geometry_msgs.msg import Vector3, Inertia
21 from uuv_gazebo_ros_plugins_msgs.msg import UnderwaterObjectModel
23 
24 PKG = 'uuv_gazebo_ros_plugins'
25 NAME = 'test_sphere_vehicle'
26 
27 import roslib; roslib.load_manifest(PKG)
28 
29 # Sphere model radius
30 RADIUS = 0.1
31 # Damping coefficient
32 CD = 0.5
33 
34 
35 class TestSphereVehicle(unittest.TestCase):
36  # def tearDownClass(self):
37  # FIXME Temporary solution to avoid gzserver lingering after the
38  # simulation node is killed (Gazebo 9.1)
39  # os.system('killall -9 gzserver')
40 
42  rospy.wait_for_service('/vehicle/get_model_properties')
43 
44  get_models = rospy.ServiceProxy('/vehicle/get_model_properties',
45  GetModelProperties)
46  models = get_models()
47 
48  self.assertEqual(len(models.link_names), 1)
49  self.assertEqual(len(models.models), 1)
50 
51  # Test the name of the link
52  self.assertEqual(
53  models.link_names[0], 'vehicle/base_link',
54  'Link name is invalid, name=' + str(models.link_names[0]))
55 
56  # Test message types
57  self.assertIsInstance(models.models[0].added_mass, tuple)
58  self.assertIsInstance(models.models[0].linear_damping, tuple)
59  self.assertIsInstance(models.models[0].linear_damping_forward_speed, tuple)
60  self.assertIsInstance(models.models[0].quadratic_damping, tuple)
61  self.assertIsInstance(models.models[0].volume, float)
62  self.assertIsInstance(models.models[0].bbox_length, float)
63  self.assertIsInstance(models.models[0].bbox_width, float)
64  self.assertIsInstance(models.models[0].bbox_height, float)
65  self.assertIsInstance(models.models[0].fluid_density, float)
66  self.assertIsInstance(models.models[0].neutrally_buoyant, bool)
67  self.assertIsInstance(models.models[0].cob, Vector3)
68  self.assertIsInstance(models.models[0].inertia, Inertia)
69 
70  # Test size of the parameter lists
71  self.assertEqual(len(models.models[0].added_mass), 36)
72  self.assertEqual(len(models.models[0].linear_damping), 36)
73  self.assertEqual(len(models.models[0].linear_damping_forward_speed), 36)
74  self.assertEqual(len(models.models[0].quadratic_damping), 36)
75 
76  # Tests if some of the parameters match to the ones given in the URDF
77  self.assertEqual(models.models[0].fluid_density, 1028.0)
78  self.assertEqual(models.models[0].volume, 0.009727626)
79  self.assertEqual(models.models[0].bbox_height, 1.0)
80  self.assertEqual(models.models[0].bbox_length, 1.0)
81  self.assertEqual(models.models[0].bbox_width, 1.0)
82 
84  rospy.wait_for_service('/vehicle/get_model_properties')
85 
86  get_models = rospy.ServiceProxy('/vehicle/get_model_properties',
87  GetModelProperties)
88  models = get_models()
89 
90  d_idxs = [i*6 + j for i, j in zip(range(3), range(3))]
91  sphere_ma = 2.0 / 3.0 * models.models[0].fluid_density * np.pi * \
92  RADIUS**3.0
93  for i in range(len(models.models[0].added_mass)):
94  if i in d_idxs:
95  self.assertLess(abs(models.models[0].added_mass[i] - sphere_ma), 0.001)
96  else:
97  self.assertEqual(models.models[0].added_mass[i], 0.0)
98 
100  rospy.wait_for_service('/vehicle/get_model_properties')
101 
102  get_models = rospy.ServiceProxy('/vehicle/get_model_properties',
103  GetModelProperties)
104  models = get_models()
105 
106  area_section = np.pi * RADIUS**2
107  dq = -0.5 * models.models[0].fluid_density * CD * area_section
108 
109  d_idxs = [i*6 + j for i, j in zip(range(3), range(3))]
110  for i in range(len(models.models[0].quadratic_damping)):
111  if i in d_idxs:
112  self.assertLess(abs(models.models[0].quadratic_damping[i] - dq), 0.001)
113  else:
114  self.assertEqual(models.models[0].quadratic_damping[i], 0.0)
115 
116 
117 if __name__ == '__main__':
118  import rosunit
119  rosunit.unitrun(PKG, NAME, TestSphereVehicle)


uuv_gazebo_ros_plugins
Author(s): Musa Morena Marcusso Manhaes , Sebastian Scherer , Luiz Ricardo Douat
autogenerated on Thu Jun 18 2020 03:28:28