-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest_thruster_feedback.rb
224 lines (151 loc) · 6.52 KB
/
test_thruster_feedback.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
require 'minitest/spec'
require 'orocos/test/component'
require 'minitest/autorun'
describe 'auv_control::ThrustersFeedback configuration' do
include Orocos::Test::Component
start 'thrusters_feedback', 'auv_control::ThrustersFeedback' => 'thrusters_feedback'
reader 'thrusters_feedback', 'cmd_out', :attr_name => 'cmd_out'
writer 'thrusters_feedback', 'cmd_in', :attr_name => 'cmd_in'
it 'thruster_coeff_pos < 0' do
thrusters_feedback.apply_conf_file("auv_control::ThrustersFeedback.yml")
aux = thrusters_feedback.thruster_coeff_pos
aux[0] = -8
thrusters_feedback.thruster_coeff_pos = aux
assert_raises(Orocos::StateTransitionFailed) { thrusters_feedback.configure }
end
it 'thruster_coeff_neg < 0' do
thrusters_feedback.apply_conf_file("auv_control::ThrustersFeedback.yml")
aux = thrusters_feedback.thruster_coeff_neg
aux[0] = -8
thrusters_feedback.thruster_coeff_neg = aux
assert_raises(Orocos::StateTransitionFailed) { thrusters_feedback.configure }
end
it 'wrong control_modes size' do
thrusters_feedback.apply_conf_file("auv_control::ThrustersFeedback.yml",
['default', 'control_mode_3_raw'], true)
assert_raises(Orocos::StateTransitionFailed) { thrusters_feedback.configure }
end
it 'wrong thruster_coeff_pos size' do
thrusters_feedback.apply_conf_file("auv_control::ThrustersFeedback.yml",
['default', 'thruster_coeff_pos_size_3'], true)
assert_raises(Orocos::StateTransitionFailed) { thrusters_feedback.configure }
end
it 'automatically setting control_modes' do
thrusters_feedback.apply_conf_file("auv_control::ThrustersFeedback.yml")
aux = thrusters_feedback.control_modes
aux.clear
thrusters_feedback.control_modes = aux
thrusters_feedback.configure
end
it 'pos and neg coefficients have different sizes' do
thrusters_feedback.apply_conf_file("auv_control::ThrustersFeedback.yml",
['default', 'thruster_coeff_pos_size_3'], true)
aux = thrusters_feedback.control_modes
aux.clear
thrusters_feedback.control_modes = aux
assert_raises(Orocos::StateTransitionFailed) { thrusters_feedback.configure }
end
it 'control modes set to EFFORT' do
thrusters_feedback.apply_conf_file("auv_control::ThrustersFeedback.yml",
['default', 'control_modes_effort'], true)
assert_raises(Orocos::StateTransitionFailed) { thrusters_feedback.configure }
end
it 'control mode equals to RAW but no thruster voltage was set' do
thrusters_feedback.apply_conf_file("auv_control::ThrustersFeedback.yml")
thrusters_feedback.thruster_voltage = 0
assert_raises(Orocos::StateTransitionFailed) { thrusters_feedback.configure }
end
it 'wrong number of thrusters input' do
thrusters_feedback.apply_conf_file("auv_control::ThrustersFeedback.yml")
thrusters_feedback.configure
thrusters_feedback.start
sample = thrusters_feedback.cmd_in.new_sample
# 3 thrusters inputs were sent and 2 are expected
thruster = Types.base.JointState.zero
thruster.effort = 3
sample.elements = [thruster, thruster, thruster]
cmd_in.write sample
assert_state_change(thrusters_feedback) { |s| s == :UNEXPECTED_THRUSTER_INPUT }
end
it 'thruster input not set' do
thrusters_feedback.apply_conf_file("auv_control::ThrustersFeedback.yml")
thrusters_feedback.configure
thrusters_feedback.start
sample = thrusters_feedback.cmd_in.new_sample
# the effort field was not set
thruster = Types.base.JointState.zero
sample.elements = [thruster, thruster]
cmd_in.write sample
assert_state_change(thrusters_feedback) { |s| s == :UNSET_THRUSTER_INPUT }
end
it 'testing positive speed calculated value' do
thrusters_feedback.apply_conf_file("auv_control::ThrustersFeedback.yml",
['default', 'control_modes_speed'], true)
thrusters_feedback.configure
thrusters_feedback.start
sample = thrusters_feedback.cmd_in.new_sample
thruster1 = Types.base.JointState.zero
thruster2 = Types.base.JointState.zero
thruster1.speed = 457
thruster2.speed = 789
sample.elements = [thruster1, thruster2]
cmd_in.write sample
data = assert_has_one_new_sample cmd_out, 1
assert_in_delta data.elements[0].effort, 13.99, 0.001,
"wrong expected value for thruster 1"
assert_in_delta data.elements[1].effort, 41.701, 0.001,
"wrong expected value for thruster 2"
end
it 'testing negative speed calculated value' do
thrusters_feedback.apply_conf_file("auv_control::ThrustersFeedback.yml",
['default', 'control_modes_speed'], true)
thrusters_feedback.configure
thrusters_feedback.start
sample = thrusters_feedback.cmd_in.new_sample
thruster1 = Types.base.JointState.zero
thruster2 = Types.base.JointState.zero
thruster1.speed = -530
thruster2.speed = -650
sample.elements = [thruster1, thruster2]
cmd_in.write sample
data = assert_has_one_new_sample cmd_out, 1
assert_in_delta data.elements[0].effort, -18.817, 0.001,
"wrong expected value for thruster 1"
assert_in_delta data.elements[1].effort, -28.302, 0.001,
"wrong expected value for thruster 2"
end
it 'testing positive raw calculated value' do
thrusters_feedback.apply_conf_file("auv_control::ThrustersFeedback.yml")
thrusters_feedback.configure
thrusters_feedback.start
sample = thrusters_feedback.cmd_in.new_sample
thruster1 = Types.base.JointState.zero
thruster2 = Types.base.JointState.zero
thruster1.raw = 25
thruster2.raw = 17
sample.elements = [thruster1, thruster2]
cmd_in.write sample
data = assert_has_one_new_sample cmd_out, 1
assert_in_delta data.elements[0].effort, 15.114, 0.001,
"wrong expected value for thruster 1"
assert_in_delta data.elements[1].effort, 6.9887, 0.001,
"wrong expected value for thruster 2"
end
it 'testing negative raw calculated value' do
thrusters_feedback.apply_conf_file("auv_control::ThrustersFeedback.yml")
thrusters_feedback.configure
thrusters_feedback.start
sample = thrusters_feedback.cmd_in.new_sample
thruster1 = Types.base.JointState.zero
thruster2 = Types.base.JointState.zero
thruster1.raw = -49
thruster2.raw = -31
sample.elements = [thruster1, thruster2]
cmd_in.write sample
data = assert_has_one_new_sample cmd_out, 1
assert_in_delta data.elements[0].effort, -58.061, 0.001,
"wrong expected value for thruster 1"
assert_in_delta data.elements[1].effort, -23.239, 0.001,
"wrong expected value for thruster 2"
end
end