10 #include <spdlog/spdlog.h>
15 using namespace flexiv;
21 std::cout <<
"Required arguments: [robot_sn]" << 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 <<
"Optional arguments: None" << std::endl;
24 std::cout << std::endl;
28 int main(
int argc,
char* argv[])
33 if (argc < 2 || rdk::utility::ProgramArgsExistAny(argc, argv, {
"-h",
"--help"})) {
38 std::string robot_sn = argv[1];
42 ">>> Tutorial description <<<\nThis tutorial shows how to get and set global variables.\n");
52 spdlog::warn(
"Fault occurred on the connected robot, trying to clear ...");
54 if (!robot.ClearFault()) {
55 spdlog::error(
"Fault cannot be cleared, exiting ...");
58 spdlog::info(
"Fault on the connected robot is cleared");
62 spdlog::info(
"Enabling robot ...");
66 while (!robot.operational()) {
67 std::this_thread::sleep_for(std::chrono::seconds(1));
69 spdlog::info(
"Robot is now operational");
73 auto global_vars = robot.global_variables();
74 if (global_vars.empty()) {
75 spdlog::warn(
"No global variables available");
78 spdlog::info(
"Existing global variables and their original values:");
79 for (
const auto& var : global_vars) {
80 std::cout << var.first <<
": " << rdk::utility::FlexivTypes2Str(var.second)
88 spdlog::info(
"Setting new values to existing global variables");
89 robot.SetGlobalVariables({
92 {
"test_double", 100.123},
93 {
"test_string",
"Flexiv"},
94 {
"test_int_vec", std::vector<int> {1, 2, 3}},
95 {
"test_double_vec", std::vector<double> {1.1, 2.2, 3.3}},
96 {
"test_string_vec", std::vector<std::string> {
"Go",
"Flexiv",
"Go!"}},
97 {
"test_pose", std::vector<double> {0.1, -0.2, 0.3, -90, -45, 120}},
98 {
"test_coord",
rdk::Coord({0.1, -0.2, 0.3}, {-90, -45, 120}, {
"WORLD",
"WORLD_ORIGIN"},
99 {1, 2, 3, 4, 5, 6, 7}, {10, 20, 0, 0, 0, 0})},
101 std::vector<rdk::Coord> {
rdk::Coord({1, 2, 3}, {4, 5, 6}, {
"WORK",
"WorkCoord0"}),
102 rdk::Coord({10, 20, 30}, {40, 50, 60}, {
"WORLD",
"WORLD_ORIGIN"},
103 {1, 2, 3, 4, 5, 6, 7}, {10, 20, 0, 0, 0, 0}),
104 rdk::Coord({3, 2, 1}, {180, 0, 180}, {
"WORLD",
"WORLD_ORIGIN"})}},
109 global_vars = robot.global_variables();
110 if (global_vars.empty()) {
111 spdlog::warn(
"No global variables available");
114 spdlog::info(
"Updated global variables:");
115 for (
const auto& var : global_vars) {
116 std::cout << var.first <<
": " << rdk::utility::FlexivTypes2Str(var.second)
121 spdlog::info(
"Program finished");
123 }
catch (
const std::exception& e) {
124 spdlog::error(e.what());
Main interface with the robot, containing several function categories and background services.
Data structure representing the customized data type "COORD" in Flexiv Elements.