Flexiv RDK APIs  1.6.0
basics7_auto_recovery.cpp
1 
9 #include <flexiv/rdk/robot.hpp>
10 #include <flexiv/rdk/utility.hpp>
11 #include <spdlog/spdlog.h>
12 
13 #include <iostream>
14 #include <string>
15 #include <thread>
16 
17 using namespace flexiv;
18 
20 void PrintHelp()
21 {
22  // clang-format off
23  std::cout << "Required arguments: [robot_sn]" << std::endl;
24  std::cout << " robot_sn: Serial number of the robot to connect. Remove any space, e.g. Rizon4s-123456" << std::endl;
25  std::cout << "Optional arguments: None" << std::endl;
26  std::cout << std::endl;
27  // clang-format on
28 }
29 
30 int main(int argc, char* argv[])
31 {
32  // Program Setup
33  // =============================================================================================
34  // Parse parameters
35  if (argc < 2 || rdk::utility::ProgramArgsExistAny(argc, argv, {"-h", "--help"})) {
36  PrintHelp();
37  return 1;
38  }
39  // Serial number of the robot to connect to. Remove any space, for example: Rizon4s-123456
40  std::string robot_sn = argv[1];
41 
42  // Print description
43  spdlog::info(
44  ">>> Tutorial description <<<\nThis tutorial runs an automatic recovery process if the "
45  "robot's safety system is in recovery state. See rdk::Robot::recovery() and RDK "
46  "manual for more details.\n");
47 
48  try {
49  // RDK Initialization
50  // =========================================================================================
51  // Instantiate robot interface
52  rdk::Robot robot(robot_sn);
53 
54  // Enable the robot, make sure the E-stop is released before enabling
55  spdlog::info("Enabling robot ...");
56  robot.Enable();
57 
58  // Run Auto-recovery
59  // =========================================================================================
60  // If the system is in recovery state, we can't use isOperational to tell if the enabling
61  // process is done, so just wait long enough for the process to finish
62  std::this_thread::sleep_for(std::chrono::seconds(8));
63 
64  // Run automatic recovery if the system is in recovery state, the involved joints will start
65  // to move back into allowed position range
66  if (robot.recovery()) {
67  robot.RunAutoRecovery();
68  }
69  // Otherwise the system is normal, do nothing
70  else {
71  spdlog::info("Robot system is not in recovery state, nothing to be done, exiting ...");
72  }
73  } catch (const std::exception& e) {
74  spdlog::error(e.what());
75  return 1;
76  }
77 
78  return 0;
79 }
Main interface with the robot, containing several function categories and background services.
Definition: robot.hpp:25