forked from UniversalRobots/Universal_Robots_Client_Library
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_dashboard_client_g5.cpp
More file actions
675 lines (611 loc) · 24.6 KB
/
Copy pathtest_dashboard_client_g5.cpp
File metadata and controls
675 lines (611 loc) · 24.6 KB
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
// -- BEGIN LICENSE BLOCK ----------------------------------------------
// Copyright 2022 Universal Robots A/S
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the {copyright_holder} nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// -- END LICENSE BLOCK ------------------------------------------------
#include <gtest/gtest.h>
#include <ur_client_library/exceptions.h>
#include <chrono>
#include <thread>
#include "gtest/gtest.h"
#include "test_utils.h"
#include "ur_client_library/comm/tcp_socket.h"
#include "ur_client_library/ur/dashboard_client_implementation_g5.h"
#include "ur_client_library/ur/version_information.h"
#include <ur_client_library/ur/dashboard_client.h>
using namespace urcl;
std::string g_ROBOT_IP = "192.168.56.101";
class TestableDashboardClientImplG5 : public DashboardClientImplG5
{
public:
TestableDashboardClientImplG5(const std::string& host) : DashboardClientImplG5(host)
{
}
void setPolyscopeVersion(const VersionInformation& version)
{
polyscope_version_ = version;
}
};
class DashboardClientTestG5 : public ::testing::Test
{
protected:
void SetUp()
{
if (!robotVersionLessThan(g_ROBOT_IP, "10.0.0"))
{
GTEST_SKIP_("G5 DashboardClient tests are only applicable for robots with a G5 dashboard server.");
}
dashboard_client_.reset(new TestableDashboardClientImplG5(g_ROBOT_IP));
// In CI we the dashboard client times out for no obvious reason. Hence we increase the timeout
// here.
timeval tv;
tv.tv_sec = 10;
tv.tv_usec = 0;
dashboard_client_->setReceiveTimeout(tv);
}
void TearDown()
{
dashboard_client_.reset();
}
std::unique_ptr<TestableDashboardClientImplG5> dashboard_client_;
};
TEST_F(DashboardClientTestG5, connect)
{
EXPECT_TRUE(dashboard_client_->connect());
DashboardResponse response;
response = dashboard_client_->commandCloseSafetyPopup();
ASSERT_TRUE(response.ok);
}
TEST_F(DashboardClientTestG5, power_cycle)
{
EXPECT_TRUE(dashboard_client_->connect());
DashboardResponse response;
// Cycle from POWER_OFF to IDLE to RUNNING
response = dashboard_client_->commandPowerOff();
EXPECT_TRUE(response.ok);
response = dashboard_client_->commandPowerOn(std::chrono::seconds(5));
EXPECT_TRUE(response.ok);
response = dashboard_client_->commandBrakeRelease();
EXPECT_TRUE(response.ok);
// Calling power_on on a brake-released robot should succeed
response = dashboard_client_->commandPowerOn(std::chrono::seconds(5));
EXPECT_TRUE(response.ok);
// Power off from brake-released state (RUNNING)
response = dashboard_client_->commandPowerOff();
EXPECT_TRUE(response.ok);
// Power off from powered_on state (IDLE)
dashboard_client_->commandPowerOn();
response = dashboard_client_->commandPowerOff();
EXPECT_TRUE(response.ok);
// Power off from powered_on state (IDLE)
dashboard_client_->commandPowerOff();
response = dashboard_client_->commandPowerOff();
EXPECT_TRUE(response.ok);
// Brake release from POWER_OFF should succeed
dashboard_client_->commandPowerOff();
response = dashboard_client_->commandBrakeRelease();
EXPECT_TRUE(response.ok);
}
TEST_F(DashboardClientTestG5, run_program)
{
EXPECT_TRUE(dashboard_client_->connect());
DashboardResponse response;
response = dashboard_client_->commandLoadProgram("wait_program.urp");
EXPECT_TRUE(response.ok);
EXPECT_EQ(std::get<std::string>(response.data["program_name"]), "wait_program.urp");
response = dashboard_client_->commandPowerOff();
EXPECT_TRUE(response.ok);
dashboard_client_->commandClosePopup(); // Necessary for CB3 test
response = dashboard_client_->commandPowerOn();
EXPECT_TRUE(response.ok);
response = dashboard_client_->commandBrakeRelease();
EXPECT_TRUE(response.ok);
response = dashboard_client_->commandPlay();
EXPECT_TRUE(response.ok);
response = dashboard_client_->commandPause();
EXPECT_TRUE(response.ok);
response = dashboard_client_->commandPlay();
EXPECT_TRUE(response.ok);
response = dashboard_client_->commandRunning();
EXPECT_TRUE(response.ok);
EXPECT_TRUE(std::get<bool>(response.data["running"]));
response = dashboard_client_->commandStop();
EXPECT_TRUE(response.ok);
response = response = dashboard_client_->commandRunning();
EXPECT_TRUE(response.ok);
EXPECT_FALSE(std::get<bool>(response.data["running"]));
response = dashboard_client_->commandPowerOff();
EXPECT_TRUE(response.ok);
dashboard_client_->commandClosePopup(); // Necessary for CB3 test
}
TEST_F(DashboardClientTestG5, load_installation)
{
EXPECT_TRUE(dashboard_client_->connect());
DashboardResponse response;
response = dashboard_client_->commandLoadInstallation("default.installation");
ASSERT_TRUE(response.ok);
ASSERT_EQ(std::get<std::string>(response.data["installation_name"]), "default.installation");
}
TEST_F(DashboardClientTestG5, load_program)
{
EXPECT_TRUE(dashboard_client_->connect());
DashboardResponse response = dashboard_client_->commandLoadProgram("wait_program.urp");
ASSERT_TRUE(response.ok);
ASSERT_EQ(std::get<std::string>(response.data["program_name"]), "wait_program.urp");
}
TEST_F(DashboardClientTestG5, not_connected)
{
EXPECT_THROW(dashboard_client_->commandPowerOff(), UrException);
}
TEST_F(DashboardClientTestG5, popup)
{
EXPECT_TRUE(dashboard_client_->connect());
DashboardResponse response;
response = dashboard_client_->commandPopup("Test Popup");
ASSERT_TRUE(response.ok);
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // Give time for popup to pop up
response = dashboard_client_->commandClosePopup();
ASSERT_TRUE(response.ok);
}
TEST_F(DashboardClientTestG5, log_and_getters)
{
std::string msg = "My message";
EXPECT_TRUE(dashboard_client_->connect());
DashboardResponse response;
response = dashboard_client_->commandAddToLog("Testing Log:");
ASSERT_TRUE(response.ok);
response = dashboard_client_->commandPolyscopeVersion();
ASSERT_TRUE(response.ok);
response = dashboard_client_->commandAddToLog("Polyscope Version: " + msg);
ASSERT_TRUE(response.ok);
response = dashboard_client_->commandRobotMode();
ASSERT_TRUE(response.ok);
response = dashboard_client_->commandAddToLog("Robot mode: " + msg);
ASSERT_TRUE(response.ok);
response = dashboard_client_->commandGetLoadedProgram();
ASSERT_TRUE(response.ok);
response = dashboard_client_->commandAddToLog("Loaded program: " + msg);
ASSERT_TRUE(response.ok);
response = dashboard_client_->commandProgramState();
ASSERT_TRUE(response.ok);
response = dashboard_client_->commandAddToLog("Program state: " + msg);
ASSERT_TRUE(response.ok);
}
TEST_F(DashboardClientTestG5, flight_report_and_support_file)
{
EXPECT_TRUE(dashboard_client_->connect());
bool correct_polyscope_version = false;
try
{
auto version = dashboard_client_->getPolyscopeVersion();
if (version.major == 5)
{
correct_polyscope_version = version >= VersionInformation::fromString("5.6.0");
}
else if (version.major == 3)
{
correct_polyscope_version = version >= VersionInformation::fromString("3.13");
}
}
catch (const UrException& e)
{
correct_polyscope_version = false;
}
DashboardResponse response;
if (correct_polyscope_version)
{
response = dashboard_client_->commandGenerateFlightReport("");
ASSERT_TRUE(response.ok);
response = dashboard_client_->commandGenerateSupportFile(".");
ASSERT_TRUE(response.ok);
}
else
{
EXPECT_THROW(dashboard_client_->commandGenerateFlightReport(""), UrException);
EXPECT_THROW(dashboard_client_->commandGenerateSupportFile("."), UrException);
}
}
// Only runs this test if robot is e-series
TEST_F(DashboardClientTestG5, e_series_version)
{
EXPECT_TRUE(dashboard_client_->connect());
if (!dashboard_client_->getPolyscopeVersion().isESeries())
GTEST_SKIP();
dashboard_client_->setPolyscopeVersion(VersionInformation::fromString("5.0.0"));
EXPECT_THROW(dashboard_client_->commandSafetyStatus(), UrException);
dashboard_client_->setPolyscopeVersion(VersionInformation::fromString("5.5.0"));
DashboardResponse response;
response = dashboard_client_->commandSafetyStatus();
ASSERT_TRUE(response.ok);
EXPECT_THROW(dashboard_client_->commandSetUserRole("none"), UrException);
EXPECT_THROW(dashboard_client_->commandGetUserRole(), UrException);
}
// Only runs this test if robot is CB3
TEST_F(DashboardClientTestG5, cb3_version)
{
EXPECT_TRUE(dashboard_client_->connect());
if (dashboard_client_->getPolyscopeVersion().isESeries())
GTEST_SKIP();
DashboardResponse response;
// Get a defined starting state
dashboard_client_->commandSetUserRole("NONE");
response = dashboard_client_->commandSetUserRole("PROGRAMMER");
EXPECT_TRUE(response.ok);
response = dashboard_client_->commandGetUserRole();
EXPECT_TRUE(response.ok);
EXPECT_EQ(std::get<std::string>(response.data["user_role"]), "PROGRAMMER");
response = dashboard_client_->commandSetUserRole("OPERATOR");
ASSERT_TRUE(response.ok);
EXPECT_TRUE(response.ok);
response = dashboard_client_->commandGetUserRole();
EXPECT_TRUE(response.ok);
EXPECT_EQ(std::get<std::string>(response.data["user_role"]), "OPERATOR");
response = dashboard_client_->commandSetUserRole("NONE");
ASSERT_TRUE(response.ok);
EXPECT_TRUE(response.ok);
response = dashboard_client_->commandGetUserRole();
EXPECT_TRUE(response.ok);
EXPECT_EQ(std::get<std::string>(response.data["user_role"]), "NONE");
response = dashboard_client_->commandSetUserRole("LOCKED");
ASSERT_TRUE(response.ok);
EXPECT_TRUE(response.ok);
response = dashboard_client_->commandGetUserRole();
EXPECT_TRUE(response.ok);
EXPECT_EQ(std::get<std::string>(response.data["user_role"]), "LOCKED");
response = dashboard_client_->commandSetUserRole("RESTRICTED");
ASSERT_TRUE(response.ok);
EXPECT_TRUE(response.ok);
response = dashboard_client_->commandGetUserRole();
EXPECT_TRUE(response.ok);
EXPECT_EQ(std::get<std::string>(response.data["user_role"]), "RESTRICTED");
EXPECT_THROW(dashboard_client_->commandSafetyStatus(), UrException);
dashboard_client_->setPolyscopeVersion(VersionInformation::fromString("1.6.0"));
EXPECT_THROW(dashboard_client_->commandIsProgramSaved(), UrException);
dashboard_client_->setPolyscopeVersion(VersionInformation::fromString("1.8.0"));
EXPECT_TRUE(dashboard_client_->commandLoadProgram("wait_program.urp").ok);
response = dashboard_client_->commandIsProgramSaved();
ASSERT_TRUE(response.ok);
EXPECT_THROW(dashboard_client_->commandIsInRemoteControl(), UrException);
}
TEST_F(DashboardClientTestG5, set_receive_timeout)
{
timeval expected_tv;
expected_tv.tv_sec = 30;
expected_tv.tv_usec = 0.0;
dashboard_client_->setReceiveTimeout(expected_tv);
EXPECT_TRUE(dashboard_client_->connect());
// Ensure that the receive timeout hasn't been overwritten
timeval actual_tv = dashboard_client_->getConfiguredReceiveTimeout();
EXPECT_EQ(expected_tv.tv_sec, actual_tv.tv_sec);
EXPECT_EQ(expected_tv.tv_usec, actual_tv.tv_usec);
bool correct_polyscope_version = false;
try
{
auto version = dashboard_client_->getPolyscopeVersion();
if (version.major == 5)
{
correct_polyscope_version = version >= VersionInformation::fromString("5.6.0");
}
else if (version.major == 3)
{
correct_polyscope_version = version >= VersionInformation::fromString("3.13");
}
}
catch (const UrException& e)
{
correct_polyscope_version = false;
}
if (correct_polyscope_version)
{
DashboardResponse response;
response = dashboard_client_->commandGenerateFlightReport("");
ASSERT_TRUE(response.ok);
// Ensure that the receive timeout hasn't been overwritten
actual_tv = dashboard_client_->getConfiguredReceiveTimeout();
EXPECT_EQ(expected_tv.tv_sec, actual_tv.tv_sec);
EXPECT_EQ(expected_tv.tv_usec, actual_tv.tv_usec);
response = dashboard_client_->commandGenerateSupportFile(".");
ASSERT_TRUE(response.ok);
// Ensure that the receive timeout hasn't been overwritten
actual_tv = dashboard_client_->getConfiguredReceiveTimeout();
EXPECT_EQ(expected_tv.tv_sec, actual_tv.tv_sec);
EXPECT_EQ(expected_tv.tv_usec, actual_tv.tv_usec);
}
}
TEST_F(DashboardClientTestG5, connect_non_running_robot)
{
std::unique_ptr<DashboardClient> dashboard_client;
// We use an IP address on the integration_test's subnet
dashboard_client.reset(new DashboardClient("192.168.56.123"));
auto start = std::chrono::system_clock::now();
EXPECT_FALSE(dashboard_client->connect(2, std::chrono::milliseconds(500)));
auto end = std::chrono::system_clock::now();
auto elapsed = end - start;
// This is only a rough estimate, obviously.
// Since this isn't done on the loopback device, trying to open a socket on a non-existing address
// takes considerably longer.
EXPECT_LT(elapsed, 2 * comm::TCPSocket::DEFAULT_RECONNECTION_TIME);
}
TEST_F(DashboardClientTestG5, non_expected_result_returns_correctly)
{
ASSERT_TRUE(dashboard_client_->connect());
DashboardResponse response;
response = dashboard_client_->commandPowerOff();
ASSERT_TRUE(response.ok);
// We will not get this answer
EXPECT_FALSE(dashboard_client_->sendRequest("brake release", "non-existing-response"));
// A non-matching answer should throw an exception for this call
EXPECT_THROW(dashboard_client_->sendRequestString("brake release", "non-existing-response"), UrException);
// Waiting for a non-matching answer should return false
// Internally we wait 100ms between each attempt, hence the 300ms wait time
EXPECT_FALSE(
dashboard_client_->waitForReply("brake_release", "non-existing-response", std::chrono::milliseconds(300)));
}
TEST_F(DashboardClientTestG5, connecting_twice_returns_false)
{
ASSERT_TRUE(dashboard_client_->connect());
EXPECT_FALSE(dashboard_client_->connect());
}
TEST_F(DashboardClientTestG5, load_program_in_subdir_works)
{
ASSERT_TRUE(dashboard_client_->connect());
DashboardResponse response;
response = dashboard_client_->commandLoadProgram("/ursim/programs/wait_program.urp");
ASSERT_TRUE(response.ok);
ASSERT_EQ(std::get<std::string>(response.data["program_name"]), "/ursim/programs/wait_program.urp");
}
TEST_F(DashboardClientTestG5, clear_protective_stop)
{
ASSERT_TRUE(dashboard_client_->connect());
auto notifier = comm::INotifier();
auto primary_client = primary_interface::PrimaryClient(g_ROBOT_IP, notifier);
primary_client.start();
primary_client.sendScript("protective_stop()");
if (dashboard_client_->getPolyscopeVersion().isESeries())
{
EXPECT_NO_THROW(waitFor(
[this]() {
DashboardResponse response;
response = dashboard_client_->commandSafetyStatus();
return std::get<std::string>(response.data["safety_status"]) == "PROTECTIVE_STOP";
},
std::chrono::milliseconds(1000)));
}
std::string safety_mode;
EXPECT_NO_THROW(waitFor(
[this]() {
DashboardResponse response;
response = dashboard_client_->commandSafetyMode();
return std::get<std::string>(response.data["safety_mode"]) == "PROTECTIVE_STOP";
},
std::chrono::milliseconds(5000)));
sleep(5); // Wait for the protective stop to be triggered
// Clear the protective stop
DashboardResponse response;
response = dashboard_client_->commandUnlockProtectiveStop();
ASSERT_TRUE(response.ok);
// Check that the protective stop is cleared
if (dashboard_client_->getPolyscopeVersion().isESeries())
{
EXPECT_NO_THROW(waitFor(
[this]() {
DashboardResponse response;
response = dashboard_client_->commandSafetyStatus();
return std::get<std::string>(response.data["safety_status"]) == "NORMAL";
},
std::chrono::milliseconds(5000)));
}
EXPECT_NO_THROW(waitFor(
[this]() {
DashboardResponse response;
response = dashboard_client_->commandSafetyMode();
return std::get<std::string>(response.data["safety_mode"]) == "NORMAL";
},
std::chrono::milliseconds(5000)));
response = dashboard_client_->commandSafetyMode();
ASSERT_TRUE(response.ok);
response = dashboard_client_->commandCloseSafetyPopup();
ASSERT_TRUE(response.ok);
}
TEST_F(DashboardClientTestG5, restart_safety)
{
ASSERT_TRUE(dashboard_client_->connect());
DashboardResponse response;
response = dashboard_client_->commandPowerOff();
ASSERT_TRUE(response.ok);
response = dashboard_client_->commandRestartSafety();
ASSERT_TRUE(response.ok);
response = dashboard_client_->commandPowerOn();
ASSERT_TRUE(response.ok);
}
TEST_F(DashboardClientTestG5, program_interaction)
{
DashboardResponse response;
ASSERT_TRUE(dashboard_client_->connect());
response = dashboard_client_->commandLoadProgram("wait_program.urp");
ASSERT_TRUE(response.ok);
response = dashboard_client_->commandPowerOff();
ASSERT_TRUE(response.ok);
response = dashboard_client_->commandPowerOn();
ASSERT_TRUE(response.ok);
response = dashboard_client_->commandBrakeRelease();
ASSERT_TRUE(response.ok);
response = dashboard_client_->commandPlay();
ASSERT_TRUE(response.ok);
EXPECT_NO_THROW(waitFor(
[this]() {
DashboardResponse response = dashboard_client_->commandRunning();
return response.ok && std::get<bool>(response.data["running"]);
},
std::chrono::milliseconds(500)));
response = dashboard_client_->commandProgramState();
ASSERT_TRUE(response.ok);
ASSERT_EQ(std::get<std::string>(response.data["program_state"]), "PLAYING");
ASSERT_EQ(std::get<std::string>(response.data["program_name"]), "wait_program.urp");
response = dashboard_client_->commandPause();
ASSERT_TRUE(response.ok);
response = dashboard_client_->commandProgramState();
ASSERT_TRUE(response.ok);
ASSERT_EQ(std::get<std::string>(response.data["program_state"]), "PAUSED");
ASSERT_EQ(std::get<std::string>(response.data["program_name"]), "wait_program.urp");
response = dashboard_client_->commandPlay();
ASSERT_TRUE(response.ok);
response = dashboard_client_->commandProgramState();
ASSERT_TRUE(response.ok);
ASSERT_EQ(std::get<std::string>(response.data["program_state"]), "PLAYING");
ASSERT_EQ(std::get<std::string>(response.data["program_name"]), "wait_program.urp");
response = dashboard_client_->commandStop();
ASSERT_TRUE(response.ok);
response = dashboard_client_->commandProgramState();
ASSERT_TRUE(response.ok);
ASSERT_EQ(std::get<std::string>(response.data["program_state"]), "STOPPED");
ASSERT_EQ(std::get<std::string>(response.data["program_name"]), "wait_program.urp");
response = dashboard_client_->commandRunning();
ASSERT_TRUE(response.ok);
ASSERT_FALSE(std::get<bool>(response.data["running"]));
response = dashboard_client_->commandIsProgramSaved();
ASSERT_TRUE(response.ok);
}
TEST_F(DashboardClientTestG5, test_save_log)
{
ASSERT_TRUE(dashboard_client_->connect());
DashboardResponse response;
response = dashboard_client_->commandAddToLog("Test log message");
ASSERT_TRUE(response.ok);
response = dashboard_client_->commandSaveLog();
ASSERT_TRUE(response.ok);
}
TEST_F(DashboardClientTestG5, operational_mode)
{
ASSERT_TRUE(dashboard_client_->connect());
DashboardResponse response;
if (dashboard_client_->getPolyscopeVersion().isESeries())
{
response = dashboard_client_->commandSetOperationalMode("AUTOMATIC");
ASSERT_TRUE(response.ok);
EXPECT_NO_THROW(waitFor(
[this]() {
DashboardResponse response;
response = dashboard_client_->commandGetOperationalMode();
return std::get<std::string>(response.data["operational_mode"]) == "AUTOMATIC";
},
std::chrono::milliseconds(500)));
response = dashboard_client_->commandClearOperationalMode();
ASSERT_TRUE(response.ok);
// response = dashboard_client_->commandGetOperationalMode(operational_mode);
ASSERT_TRUE(response.ok);
response = dashboard_client_->commandSetOperationalMode("MANUAL");
ASSERT_TRUE(response.ok);
EXPECT_NO_THROW(waitFor(
[this]() {
DashboardResponse response;
response = dashboard_client_->commandGetOperationalMode();
return std::get<std::string>(response.data["operational_mode"]) == "MANUAL";
},
std::chrono::milliseconds(500)));
response = dashboard_client_->commandClearOperationalMode();
ASSERT_TRUE(response.ok);
EXPECT_NO_THROW(waitFor(
[this]() {
DashboardResponse response;
response = dashboard_client_->commandGetOperationalMode();
return std::get<std::string>(response.data["operational_mode"]) == "NONE";
},
std::chrono::milliseconds(500)));
response = dashboard_client_->commandIsInRemoteControl();
ASSERT_TRUE(response.ok);
ASSERT_FALSE(std::get<bool>(response.data["remote_control"]));
}
else
{
EXPECT_THROW(response = dashboard_client_->commandGetOperationalMode(), UrException);
EXPECT_THROW(response = dashboard_client_->commandSetOperationalMode("NONE"), UrException);
EXPECT_THROW(response = dashboard_client_->commandIsInRemoteControl(), UrException);
}
}
TEST_F(DashboardClientTestG5, test_disconnect)
{
ASSERT_TRUE(dashboard_client_->connect());
dashboard_client_->disconnect();
DashboardResponse response;
EXPECT_THROW(dashboard_client_->commandRobotMode(), UrException);
ASSERT_TRUE(dashboard_client_->connect());
response = dashboard_client_->commandRobotMode();
ASSERT_TRUE(response.ok);
response = dashboard_client_->commandQuit();
ASSERT_TRUE(response.ok);
EXPECT_THROW(dashboard_client_->commandRobotMode(), UrException);
}
TEST_F(DashboardClientTestG5, get_robot_info)
{
ASSERT_TRUE(dashboard_client_->connect());
std::string robot_model;
std::string serial_number;
DashboardResponse response;
response = dashboard_client_->commandGetRobotModel();
ASSERT_TRUE(response.ok);
response = dashboard_client_->commandGetSerialNumber();
ASSERT_TRUE(response.ok);
}
TEST_F(DashboardClientTestG5, unknown_command_throws)
{
ASSERT_TRUE(dashboard_client_->connect());
EXPECT_THROW(dashboard_client_->sendRequest("unknown_command"), UrException);
EXPECT_THROW(dashboard_client_->sendRequestString("unknown_command"), UrException);
}
TEST_F(DashboardClientTestG5, run_commands_through_client)
{
ASSERT_TRUE(dashboard_client_->connect());
ASSERT_TRUE(dashboard_client_->sendRequest("power off"));
ASSERT_TRUE(dashboard_client_->waitForReply("robotmode", "Robotmode: POWER_OFF")); // Necessary for CB3 test
ASSERT_TRUE(dashboard_client_->retryCommand("power on", "Powering on", "robotmode", "Robotmode: IDLE",
std::chrono::seconds(5)));
EXPECT_THROW(dashboard_client_->sendRequestString("brake release", "non-existing-response"), UrException);
dashboard_client_->disconnect();
}
TEST_F(DashboardClientTestG5, all_x_only_commands_throw)
{
ASSERT_TRUE(dashboard_client_->connect());
EXPECT_THROW(dashboard_client_->commandGetProgramList(), NotImplementedException);
EXPECT_THROW(dashboard_client_->commandUploadProgram(""), NotImplementedException);
EXPECT_THROW(dashboard_client_->commandUpdateProgram(""), NotImplementedException);
EXPECT_THROW(dashboard_client_->commandDownloadProgram("", ""), NotImplementedException);
EXPECT_THROW(dashboard_client_->commandResume(), NotImplementedException);
}
int main(int argc, char* argv[])
{
::testing::InitGoogleTest(&argc, argv);
for (int i = 0; i < argc; i++)
{
if (std::string(argv[i]) == "--robot_ip" && i + 1 < argc)
{
g_ROBOT_IP = argv[i + 1];
++i;
}
}
return RUN_ALL_TESTS();
}