16 from __future__
import print_function
20 from geometry_msgs.msg
import Vector3, Inertia
21 from uuv_gazebo_ros_plugins_msgs.msg
import UnderwaterObjectModel
24 PKG =
'uuv_gazebo_ros_plugins' 25 NAME =
'test_default_fossen_vehicle' 27 import roslib; roslib.load_manifest(PKG)
37 rospy.wait_for_service(
'/vehicle/get_model_properties')
39 s = rospy.ServiceProxy(
'/vehicle/get_model_properties',
43 self.assertEqual(len(models.link_names), 1)
44 self.assertEqual(len(models.models), 1)
48 models.link_names[0],
'vehicle/base_link',
49 'Link name is invalid, name=' + str(models.link_names[0]))
52 self.assertIsInstance(models.models[0].added_mass, tuple)
53 self.assertIsInstance(models.models[0].linear_damping, tuple)
54 self.assertIsInstance(models.models[0].linear_damping_forward_speed, tuple)
55 self.assertIsInstance(models.models[0].quadratic_damping, tuple)
56 self.assertIsInstance(models.models[0].volume, float)
57 self.assertIsInstance(models.models[0].bbox_length, float)
58 self.assertIsInstance(models.models[0].bbox_width, float)
59 self.assertIsInstance(models.models[0].bbox_height, float)
60 self.assertIsInstance(models.models[0].fluid_density, float)
61 self.assertIsInstance(models.models[0].neutrally_buoyant, bool)
62 self.assertIsInstance(models.models[0].cob, Vector3)
63 self.assertIsInstance(models.models[0].inertia, Inertia)
67 d_idxs = [i*6 + j
for i, j
in zip(range(6), range(6))]
68 self.assertEqual(len(models.models[0].added_mass), 36)
69 for i
in range(len(models.models[0].added_mass)):
71 self.assertEqual(models.models[0].added_mass[i], 1.0)
73 self.assertEqual(models.models[0].added_mass[i], 0.0)
75 self.assertEqual(len(models.models[0].linear_damping), 36)
76 for i
in range(len(models.models[0].linear_damping)):
78 self.assertEqual(models.models[0].linear_damping[i], 1.0)
80 self.assertEqual(models.models[0].linear_damping[i], 0.0)
82 self.assertEqual(len(models.models[0].linear_damping_forward_speed), 36)
83 for i
in range(len(models.models[0].linear_damping_forward_speed)):
85 self.assertEqual(models.models[0].linear_damping_forward_speed[i], 1.0)
87 self.assertEqual(models.models[0].linear_damping_forward_speed[i], 0.0)
89 self.assertEqual(len(models.models[0].quadratic_damping), 36)
90 for i
in range(len(models.models[0].quadratic_damping)):
92 self.assertEqual(models.models[0].quadratic_damping[i], 1.0)
94 self.assertEqual(models.models[0].quadratic_damping[i], 0.0)
97 self.assertEqual(models.models[0].fluid_density, 1028.0)
98 self.assertEqual(models.models[0].volume, 1.0)
99 self.assertEqual(models.models[0].bbox_height, 1.0)
100 self.assertEqual(models.models[0].bbox_length, 1.0)
101 self.assertEqual(models.models[0].bbox_width, 1.0)
104 rospy.wait_for_service(
'/vehicle/set_fluid_density')
105 set_func = rospy.ServiceProxy(
'/vehicle/set_fluid_density', SetFloat)
107 rospy.wait_for_service(
'/vehicle/get_fluid_density')
108 get_func = rospy.ServiceProxy(
'/vehicle/get_fluid_density', GetFloat)
110 self.assertEqual(get_func().data, 1028.0)
111 self.assertTrue(set_func(1025.0).success)
112 self.assertEqual(get_func().data, 1025.0)
113 self.assertTrue(set_func(1028.0).success)
116 rospy.wait_for_service(
'/vehicle/set_volume_offset')
117 set_func = rospy.ServiceProxy(
'/vehicle/set_volume_offset', SetFloat)
119 rospy.wait_for_service(
'/vehicle/get_volume_offset')
120 get_func = rospy.ServiceProxy(
'/vehicle/get_volume_offset', GetFloat)
122 rospy.wait_for_service(
'/vehicle/get_model_properties')
123 get_model = rospy.ServiceProxy(
'/vehicle/get_model_properties',
127 self.assertEqual(get_func().data, 0.0)
128 self.assertTrue(set_func(1.0).success)
129 self.assertEqual(get_func().data, 1.0)
133 self.assertEqual(get_model().models[0].volume, 1.0)
135 self.assertTrue(set_func(0.0).success)
138 rospy.wait_for_service(
'/vehicle/set_added_mass_scaling')
139 set_func = rospy.ServiceProxy(
'/vehicle/set_added_mass_scaling', SetFloat)
141 rospy.wait_for_service(
'/vehicle/get_added_mass_scaling')
142 get_func = rospy.ServiceProxy(
'/vehicle/get_added_mass_scaling', GetFloat)
144 self.assertEqual(get_func().data, 1.0)
145 self.assertTrue(set_func(0.8).success)
146 self.assertEqual(get_func().data, 0.8)
147 self.assertTrue(set_func(1.0).success)
150 rospy.wait_for_service(
'/vehicle/set_damping_scaling')
151 set_func = rospy.ServiceProxy(
'/vehicle/set_damping_scaling', SetFloat)
153 rospy.wait_for_service(
'/vehicle/get_damping_scaling')
154 get_func = rospy.ServiceProxy(
'/vehicle/get_damping_scaling', GetFloat)
156 self.assertEqual(get_func().data, 1.0)
157 self.assertTrue(set_func(0.8).success)
158 self.assertEqual(get_func().data, 0.8)
159 self.assertTrue(set_func(1.0).success)
162 rospy.wait_for_service(
'/vehicle/set_volume_scaling')
163 set_func = rospy.ServiceProxy(
'/vehicle/set_volume_scaling', SetFloat)
165 rospy.wait_for_service(
'/vehicle/get_volume_scaling')
166 get_func = rospy.ServiceProxy(
'/vehicle/get_volume_scaling', GetFloat)
168 self.assertEqual(get_func().data, 1.0)
169 self.assertTrue(set_func(0.8).success)
170 self.assertEqual(get_func().data, 0.8)
171 self.assertTrue(set_func(1.0).success)
174 rospy.wait_for_service(
'/vehicle/set_added_mass_offset')
175 set_func = rospy.ServiceProxy(
'/vehicle/set_added_mass_offset', SetFloat)
177 rospy.wait_for_service(
'/vehicle/get_added_mass_offset')
178 get_func = rospy.ServiceProxy(
'/vehicle/get_added_mass_offset', GetFloat)
180 self.assertEqual(get_func().data, 0.0)
182 self.assertTrue(set_func(1.0).success)
183 self.assertEqual(get_func().data, 1.0)
184 self.assertTrue(set_func(0.0).success)
187 rospy.wait_for_service(
'/vehicle/set_linear_damping_offset')
188 set_func = rospy.ServiceProxy(
'/vehicle/set_linear_damping_offset', SetFloat)
190 rospy.wait_for_service(
'/vehicle/get_linear_damping_offset')
191 get_func = rospy.ServiceProxy(
'/vehicle/get_linear_damping_offset', GetFloat)
193 self.assertEqual(get_func().data, 0.0)
194 self.assertTrue(set_func(1.0).success)
195 self.assertEqual(get_func().data, 1.0)
196 self.assertTrue(set_func(0.0).success)
199 rospy.wait_for_service(
'/vehicle/set_linear_forward_speed_damping_offset')
200 set_func = rospy.ServiceProxy(
'/vehicle/set_linear_forward_speed_damping_offset', SetFloat)
202 rospy.wait_for_service(
'/vehicle/get_linear_forward_speed_damping_offset')
203 get_func = rospy.ServiceProxy(
'/vehicle/get_linear_forward_speed_damping_offset', GetFloat)
205 self.assertEqual(get_func().data, 0.0)
206 self.assertTrue(set_func(1.0).success)
207 self.assertEqual(get_func().data, 1.0)
208 self.assertTrue(set_func(0.0).success)
211 rospy.wait_for_service(
'/vehicle/set_nonlinear_damping_offset')
212 set_func = rospy.ServiceProxy(
'/vehicle/set_nonlinear_damping_offset', SetFloat)
214 rospy.wait_for_service(
'/vehicle/get_nonlinear_damping_offset')
215 get_func = rospy.ServiceProxy(
'/vehicle/get_nonlinear_damping_offset', GetFloat)
217 self.assertEqual(get_func().data, 0.0)
218 self.assertTrue(set_func(1.0).success)
219 self.assertEqual(get_func().data, 1.0)
220 self.assertTrue(set_func(0.0).success)
223 if __name__ ==
'__main__':
225 rosunit.unitrun(PKG, NAME, TestDefaultFossenVehicle)
def test_set_fluid_density(self)
def test_volume_scaling(self)
def test_get_model_parameters(self)
def test_linear_forward_speed_damping_offset(self)
def test_damping_scaling(self)
def test_linear_damping_offset(self)
def test_added_mass_scaling(self)
def test_volume_offset(self)
def test_added_mass_offset(self)