19 from time
import sleep
20 from uuv_gazebo_ros_plugins_msgs.msg
import FloatStamped
22 SetThrusterState, GetThrusterState, SetThrusterEfficiency, \
25 PKG =
'uuv_gazebo_ros_plugins' 26 NAME =
'test_thrusters' 28 import roslib; roslib.load_manifest(PKG)
33 super(TestThrusters, self).
__init__(*args)
34 rospy.init_node(
'test_thrusters', anonymous=
True)
39 '/vehicle/thrusters/%d/input' % i, FloatStamped, queue_size=1)
42 pub = rospy.Publisher(
'/vehicle/thrusters/0/input', FloatStamped,
47 input_message = FloatStamped()
48 input_message.header.stamp = rospy.Time.now()
49 input_message.data = 0.2
54 output = rospy.wait_for_message(
'/vehicle/thrusters/%d/thrust' % k,
55 FloatStamped, timeout=30)
56 self.assertIsNot(output.data, 0.0)
59 input_message.data = 0.0
60 pub.publish(input_message)
64 rospy.wait_for_service(
65 '/vehicle/thrusters/0/get_thruster_conversion_fcn')
67 get_thruster_convertion_fcn = rospy.ServiceProxy(
68 '/vehicle/thrusters/0/get_thruster_conversion_fcn',
69 GetThrusterConversionFcn)
71 fcn = get_thruster_convertion_fcn()
73 self.assertEqual(fcn.fcn.function_name,
'Basic')
74 self.assertEqual(len(fcn.fcn.tags), len(fcn.fcn.data))
75 self.assertEqual(len(fcn.fcn.tags), 1)
76 self.assertIn(
'rotor_constant', fcn.fcn.tags)
77 self.assertEqual(fcn.fcn.data[0], 0.001)
80 rospy.wait_for_service(
81 '/vehicle/thrusters/1/get_thruster_conversion_fcn')
83 get_thruster_convertion_fcn = rospy.ServiceProxy(
84 '/vehicle/thrusters/1/get_thruster_conversion_fcn',
85 GetThrusterConversionFcn)
87 fcn = get_thruster_convertion_fcn()
89 bessa_tags = [
'rotor_constant_l',
'rotor_constant_r',
'delta_l',
91 bessa_params = [0.001, 0.001, -0.01, 0.01]
92 self.assertEqual(fcn.fcn.function_name,
'Bessa')
93 self.assertEqual(len(fcn.fcn.tags), len(fcn.fcn.data))
94 self.assertEqual(len(fcn.fcn.tags), 4)
95 for t, p
in zip(fcn.fcn.tags, fcn.fcn.data):
96 self.assertIn(t, bessa_tags)
97 self.assertEqual(p, bessa_params[bessa_tags.index(t)])
100 rospy.wait_for_service(
101 '/vehicle/thrusters/2/get_thruster_conversion_fcn')
103 get_thruster_convertion_fcn = rospy.ServiceProxy(
104 '/vehicle/thrusters/2/get_thruster_conversion_fcn',
105 GetThrusterConversionFcn)
107 fcn = get_thruster_convertion_fcn()
109 self.assertEqual(fcn.fcn.function_name,
'LinearInterp')
110 self.assertEqual(len(fcn.fcn.tags), len(fcn.fcn.data))
111 self.assertEqual(len(fcn.fcn.tags), 0)
112 self.assertEqual(len(fcn.fcn.lookup_table_input),
113 len(fcn.fcn.lookup_table_output))
114 self.assertListEqual([-0.1, 0.0, 0.1],
115 list(fcn.fcn.lookup_table_input))
116 self.assertListEqual([-0.01, 0.0, 0.01],
117 list(fcn.fcn.lookup_table_output))
121 rospy.wait_for_service(
122 '/vehicle/thrusters/%d/set_thruster_state' % i)
123 set_state = rospy.ServiceProxy(
124 '/vehicle/thrusters/%d/set_thruster_state' % i,
126 self.assertTrue(set_state(
False).success)
129 rospy.wait_for_service(
130 '/vehicle/thrusters/%d/get_thruster_state' % i)
131 get_state = rospy.ServiceProxy(
132 '/vehicle/thrusters/%d/get_thruster_state' % i,
135 self.assertFalse(get_state().is_on)
138 self.assertTrue(set_state(
True).success)
139 self.assertTrue(get_state().is_on)
143 rospy.wait_for_service(
144 '/vehicle/thrusters/%d/set_thrust_force_efficiency' % i)
145 set_efficiency = rospy.ServiceProxy(
146 '/vehicle/thrusters/%d/set_thrust_force_efficiency' % i,
147 SetThrusterEfficiency)
148 self.assertTrue(set_efficiency(0.5).success)
151 rospy.wait_for_service(
152 '/vehicle/thrusters/%d/get_thrust_force_efficiency' % i)
153 get_efficiency = rospy.ServiceProxy(
154 '/vehicle/thrusters/%d/get_thrust_force_efficiency' % i,
155 GetThrusterEfficiency)
157 self.assertEqual(get_efficiency().efficiency, 0.5)
160 self.assertTrue(set_efficiency(1.0).success)
161 self.assertEqual(get_efficiency().efficiency, 1.0)
165 rospy.wait_for_service(
166 '/vehicle/thrusters/%d/set_dynamic_state_efficiency' % i)
167 set_efficiency = rospy.ServiceProxy(
168 '/vehicle/thrusters/%d/set_dynamic_state_efficiency' % i,
169 SetThrusterEfficiency)
170 self.assertTrue(set_efficiency(0.5).success)
173 rospy.wait_for_service(
174 '/vehicle/thrusters/%d/get_dynamic_state_efficiency' % i)
175 get_efficiency = rospy.ServiceProxy(
176 '/vehicle/thrusters/%d/get_dynamic_state_efficiency' % i,
177 GetThrusterEfficiency)
179 self.assertEqual(get_efficiency().efficiency, 0.5)
182 self.assertTrue(set_efficiency(1.0).success)
183 self.assertEqual(get_efficiency().efficiency, 1.0)
186 if __name__ ==
'__main__':
188 rostest.rosrun(PKG, NAME, TestThrusters, sys.argv)
def test_input_output_topics_exist(self)
def test_change_thruster_state(self)
def test_change_dyn_state_efficiency(self)
def test_change_thrust_efficiency(self)
def test_convertion_fcn_parameters(self)