Flexiv RDK APIs  1.6.0
basics2_clear_fault.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 <string>
14 #include <thread>
15 
16 using namespace flexiv;
17 
19 void PrintHelp()
20 {
21  // clang-format off
22  std::cout << "Required arguments: [robot_sn]" << std::endl;
23  std::cout << " robot_sn: Serial number of the robot to connect. Remove any space, e.g. Rizon4s-123456" << 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 < 2 || 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  // Print description
42  spdlog::info(
43  ">>> Tutorial description <<<\nThis tutorial clears minor or critical faults, if any, of "
44  "the connected robot.\n");
45 
46  try {
47  // RDK Initialization
48  // =========================================================================================
49  // Instantiate robot interface
50  rdk::Robot robot(robot_sn);
51 
52  // Fault Clearing
53  // =========================================================================================
54  // Clear fault on the connected robot if any
55  if (robot.fault()) {
56  spdlog::warn("Fault occurred on the connected robot, trying to clear ...");
57  // Try to clear the fault
58  if (!robot.ClearFault()) {
59  spdlog::error("Fault cannot be cleared, exiting ...");
60  return 1;
61  }
62  spdlog::info("Fault on the connected robot is cleared");
63  } else {
64  spdlog::info("No fault on the connected robot");
65  }
66  } catch (const std::exception& e) {
67  spdlog::error(e.what());
68  return 1;
69  }
70 
71  return 0;
72 }
Main interface with the robot, containing several function categories and background services.
Definition: robot.hpp:25