-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest_base.rb
270 lines (244 loc) · 9.91 KB
/
test_base.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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
require 'minitest/autorun'
require 'minitest/spec'
require 'orocos/test/component'
describe 'auv_control::Base' do
include Orocos::Test::Component
# We cannot instanciate an auv_control::Base component, as it is abstract.
# Instead, use WorldToAligned to test the Base functionality
start 'task', 'auv_control::WorldToAligned' => 'task'
reader 'task', 'cmd_out', :attr_name => 'cmd_out'
it "should create a port with the given name prefixed with cmd_" do
task.addCommandInput('test', Time.at(0))
port = task.cmd_test
assert_equal '/base/commands/LinearAngular6DCommand_m', port.type.name
end
it "should return true when the port could be created" do
assert task.addCommandInput('test', Time.at(0))
end
it "should return false when the port already exists" do
task.addCommandInput('test', Time.at(0))
refute task.addCommandInput('test', Time.at(0))
end
before do
task.expected_inputs do |v|
v.linear = [true, true, false]
v.angular = [false, false, false]
end
end
def invalidated_command
sample = task.cmd_in.new_sample
sample.time = Time.now
sample.linear = Eigen::Vector3.Unset
sample.angular = Eigen::Vector3.Unset
sample
end
def pose_sample
sample = task.pose_samples.new_sample
sample.time = Time.now
sample.position = sample.velocity = sample.angular_velocity = Eigen::Vector3.new(0, 0, 0)
sample.orientation = Eigen::Quaternion.Identity
sample
end
it "should merge all its inputs" do
task.addCommandInput '0', Time.at(0)
task.addCommandInput '1', Time.at(0)
cmd0 = task.cmd_0.writer
cmd1 = task.cmd_1.writer
pose = task.pose_samples.writer
task.keep_position_on_exception = false
task.configure
task.start
sample = invalidated_command
sample.linear[0] = 1
cmd0.write sample
sample = invalidated_command
sample.linear[1] = 2
cmd1.write sample
pose.write pose_sample
merged = assert_has_one_new_sample cmd_out, 1
assert_in_delta 1, merged.linear[0], 1e-6
assert_in_delta 2, merged.linear[1], 1e-6
assert Base.unset?(merged.linear[2])
assert Base.unset?(merged.angular[0])
assert Base.unset?(merged.angular[1])
assert Base.unset?(merged.angular[2])
end
it "should use the cmd_in port if it is connected" do
task.addCommandInput '0', Time.at(0)
cmd0 = task.cmd_0.writer
cmd1 = task.cmd_in.writer
pose = task.pose_samples.writer
task.keep_position_on_exception = false
task.configure
task.start
sample = invalidated_command
sample.linear[0] = 1
cmd0.write sample
sample = invalidated_command
sample.linear[1] = 2
cmd1.write sample
pose.write pose_sample
merged = assert_has_one_new_sample cmd_out, 10
assert_in_delta 1, merged.linear[0], 1e-6
assert_in_delta 2, merged.linear[1], 1e-6
assert Base.unset?(merged.linear[2])
assert Base.unset?(merged.angular[0])
assert Base.unset?(merged.angular[1])
assert Base.unset?(merged.angular[2])
end
it "should use the cmd_cascade port if it is connected" do
task.addCommandInput '0', Time.at(0)
cmd0 = task.cmd_0.writer
cmd1 = task.cmd_cascade.writer
pose = task.pose_samples.writer
task.keep_position_on_exception = false
task.configure
task.start
sample = invalidated_command
sample.linear[0] = 1
cmd0.write sample
sample = invalidated_command
sample.linear[1] = 2
cmd1.write sample
pose.write pose_sample
merged = assert_has_one_new_sample cmd_out, 10
assert_in_delta 1, merged.linear[0], 1e-6
assert_in_delta 2, merged.linear[1], 1e-6
assert Base.unset?(merged.linear[2])
assert Base.unset?(merged.angular[0])
assert Base.unset?(merged.angular[1])
assert Base.unset?(merged.angular[2])
end
it "should go in INPUT_MISSING state if an expected input is not there" do
task.addCommandInput '0', Time.at(0)
cmd0 = task.cmd_0.writer
pose = task.pose_samples.writer
task.keep_position_on_exception = false
task.configure
task.start
sample = invalidated_command
sample.linear[0] = 1
pose.write pose_sample
cmd0.write sample
assert_state_change(task) { |s| s == :INPUT_MISSING }
end
it "should go in INPUT_COLLIDING state if two inputs provide the same value" do
task.addCommandInput '0', Time.at(0)
task.addCommandInput '1', Time.at(0)
cmd0 = task.cmd_0.writer
cmd1 = task.cmd_1.writer
pose = task.pose_samples.writer
task.keep_position_on_exception = false
task.configure
task.start
pose.write pose_sample
sample = invalidated_command
sample.linear[0] = 1
sample.linear[1] = 1
cmd0.write sample
sample.linear[1] = Base.unset
cmd1.write sample
assert_state_change(task) { |s| s == :INPUT_COLLIDING }
end
it "should go in INPUT_UNEXPECTED state if there is a value for an unexpected input" do
task.addCommandInput '0', Time.at(0)
cmd0 = task.cmd_0.writer
pose = task.pose_samples.writer
task.keep_position_on_exception = false
task.configure
task.start
sample = invalidated_command
sample.linear[0] = 1
sample.linear[1] = 1
sample.linear[2] = 1
cmd0.write sample
pose.write pose_sample
assert_state_change(task) { |s| s == :INPUT_UNEXPECTED }
end
it "should go in TIMEOUT state if one port is not updated for its specified timeout and recover in case of new data" do
task.addCommandInput '0', Time.at(1)
cmd0 = task.cmd_0.writer
pose = task.pose_samples.writer
task.timeout_pose = Time.at(10)
task.keep_position_on_exception = false
task.configure
task.start
sample = invalidated_command
sample.linear[0] = 1
sample.linear[1] = 1
cmd0.write sample
pose.write pose_sample
cmd_out0 = assert_has_one_new_sample cmd_out, 1
assert_equal sample.time.usec, cmd_out0.time.usec
sample = invalidated_command
cmd_out0 = assert_has_no_new_sample cmd_out, 1
sleep(1)
assert_state_change(task) { |s| s == :TIMEOUT }
sample.time = Time.now
sample.linear[0] = 1
sample.linear[1] = 1
cmd0.write sample
sleep(0.02)
cmd_out0 = assert_has_one_new_sample cmd_out, 1
assert_state_change(task) { |s| s == :CONTROLLING }
end
it "should not check for timeouts on ports that have a timeout value of zero" do
task.addCommandInput '0', Time.at(0)
cmd0 = task.cmd_0.writer
pose = task.pose_samples.writer
task.timeout_pose = Time.at(10)
task.configure
task.start
sample = invalidated_command
sample.linear[0] = 1
sample.linear[1] = 1
cmd0.write sample
pose.write pose_sample
sample = invalidated_command
sample.time = Time.now
sleep(2)
sample.linear[0] = 1
sample.linear[1] = 1
cmd0.write sample
pose.write pose_sample
assert_state_change(task) { |s| s != :TIMEOUT }
end
it "should control if multiple inputs are connected, with only producing all the expected data" do
task.addCommandInput '0', Time.at(0)
task.addCommandInput '1', Time.at(0)
cmd0 = task.cmd_0.writer
cmd1 = task.cmd_1.writer
pose = task.pose_samples.writer
task.expected_inputs = Hash[linear: [true, true, false], angular: [false, false, false]]
task.keep_position_on_exception = false
task.configure
task.start
sample = invalidated_command
sample.linear[0] = 1
sample.linear[1] = 1
cmd0.write sample
pose.write pose_sample
assert_state_change(task) { |s| s == :CONTROLLING }
end
it "should delete all created ports" do
task.addCommandInput '0', Time.at(0)
task.configure
task.cleanup
end
it "should go to WAIT_FOR_CONNECTED_INPUT_PORT state when no port is connected" do
pose = task.pose_samples.writer
task.keep_position_on_exception = false
task.configure
task.start
pose.write pose_sample
assert_state_change(task) { |s| s == :WAIT_FOR_CONNECTED_INPUT_PORT }
end
it "should NOT go to WAIT_FOR_CONNECTED_INPUT_PORT state when at least one port is connected" do
pose = task.pose_samples.writer
cmd = task.cmd_in.writer
task.configure
task.start
pose.write pose_sample
assert_state_change(task) { |s| s != :WAIT_FOR_CONNECTED_INPUT_PORT }
end
end