13 #include <spdlog/spdlog.h>
18 using namespace flexiv;
24 std::cout <<
"Required arguments: [robot_sn]" << std::endl;
25 std::cout <<
" robot_sn: Serial number of the robot to connect. Remove any space, e.g. Rizon4s-123456" << std::endl;
26 std::cout <<
"Optional arguments: None" << std::endl;
27 std::cout << std::endl;
31 int main(
int argc,
char* argv[])
36 if (argc < 2 || rdk::utility::ProgramArgsExistAny(argc, argv, {
"-h",
"--help"})) {
41 std::string robot_sn = argv[1];
45 ">>> Tutorial description <<<\nThis tutorial executes a plan selected by the user from a "
46 "list of available plans. A plan is a pre-written script to execute a series of robot "
47 "primitives with pre-defined transition conditions between 2 adjacent primitives. Users "
48 "can use Flexiv Elements to compose their own plan and assign to the robot, which will "
49 "appear in the plan list.\n");
59 spdlog::warn(
"Fault occurred on the connected robot, trying to clear ...");
61 if (!robot.ClearFault()) {
62 spdlog::error(
"Fault cannot be cleared, exiting ...");
65 spdlog::info(
"Fault on the connected robot is cleared");
69 spdlog::info(
"Enabling robot ...");
73 while (!robot.operational()) {
74 std::this_thread::sleep_for(std::chrono::seconds(1));
76 spdlog::info(
"Robot is now operational");
81 robot.SwitchMode(rdk::Mode::NRT_PLAN_EXECUTION);
86 throw std::runtime_error(
"Fault occurred on the connected robot, exiting ...");
90 spdlog::info(
"Choose an action:");
91 std::cout <<
"[1] Show available plans" << std::endl;
92 std::cout <<
"[2] Execute a plan by index" << std::endl;
93 std::cout <<
"[3] Execute a plan by name" << std::endl;
95 std::string inputBuffer;
96 std::cin >> inputBuffer;
97 int userInput = std::stoi(inputBuffer);
102 auto plan_list = robot.plan_list();
103 for (
size_t i = 0; i < plan_list.size(); i++) {
104 std::cout <<
"[" << i <<
"] " << plan_list[i] << std::endl;
106 std::cout << std::endl;
110 spdlog::info(
"Enter plan index to execute:");
115 robot.ExecutePlan(index,
true);
118 while (robot.busy()) {
119 spdlog::info(
"Current plan info:");
120 std::cout << robot.plan_info() << std::endl;
121 std::this_thread::sleep_for(std::chrono::seconds(1));
126 spdlog::info(
"Enter plan name to execute:");
131 robot.ExecutePlan(name,
true);
134 while (robot.busy()) {
135 spdlog::info(
"Current plan info:");
136 std::cout << robot.plan_info() << std::endl;
137 std::this_thread::sleep_for(std::chrono::seconds(1));
141 spdlog::warn(
"Invalid input");
146 }
catch (
const std::exception& e) {
147 spdlog::error(e.what());
Main interface with the robot, containing several function categories and background services.