Flexiv RDK APIs  1.9.0
test_repeated_instantiation.cpp
1 
8 #include <flexiv/rdk/robot.hpp>
9 #include <flexiv/rdk/utility.hpp>
10 #include <spdlog/spdlog.h>
11 
12 #include <iostream>
13 #include <thread>
14 
15 using namespace flexiv;
16 
18 void PrintHelp()
19 {
20  // clang-format off
21  std::cout << "Required arguments: [robot_sn] [test_cycles]" << std::endl;
22  std::cout << " robot_sn: Serial number of the robot to connect. Remove any space, e.g. Rizon4s-123456" << std::endl;
23  std::cout << " test_cycles: Number of cycles to repeat the instantiation" << std::endl;
24  std::cout << "Optional arguments: None" << std::endl;
25  std::cout << std::endl;
26  // clang-format on
27 }
28 
29 int main(int argc, char* argv[])
30 {
31  // Program Setup
32  // =============================================================================================
33  // Parse parameters
34  if (argc < 3 || rdk::utility::ProgramArgsExistAny(argc, argv, {"-h", "--help"})) {
35  PrintHelp();
36  return 1;
37  }
38  // Serial number of the robot to connect to. Remove any space, for example: Rizon4s-123456
39  std::string robot_sn = argv[1];
40 
41  // Number of cycles
42  unsigned int test_cycles = std::stoi(argv[2]);
43 
44  try {
45  for (size_t i = 1; i <= test_cycles; i++) {
46  spdlog::info("Test cycle: {}/{}", i, test_cycles);
47 
48  // Instantiate robot interface
49  rdk::Robot robot(robot_sn);
50 
51  // Enable the robot, make sure the E-stop is released before enabling
52  spdlog::info("Enabling robot ...");
53  robot.Enable();
54 
55  // Wait for the robot to become operational
56  while (!robot.operational()) {
57  std::this_thread::sleep_for(std::chrono::seconds(1));
58  }
59  spdlog::info("Robot is now operational");
60  }
61 
62  } catch (const std::exception& e) {
63  spdlog::error(e.what());
64  return 1;
65  }
66 
67  return 0;
68 }
Main interface to control the robot, containing several function categories and background services.
Definition: robot.hpp:25