11 #include <spdlog/spdlog.h>
17 using namespace flexiv;
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;
30 int main(
int argc,
char* argv[])
35 if (argc < 2 || rdk::utility::ProgramArgsExistAny(argc, argv, {
"-h",
"--help"})) {
40 std::string robot_sn = argv[1];
44 ">>> Tutorial description <<<\nThis tutorial executes several basic robot primitives (unit "
45 "skills). For detailed documentation on all available primitives, please see [Flexiv "
46 "Primitives](https://www.flexiv.com/primitives/).\n");
56 spdlog::warn(
"Fault occurred on the connected robot, trying to clear ...");
58 if (!robot.ClearFault()) {
59 spdlog::error(
"Fault cannot be cleared, exiting ...");
62 spdlog::info(
"Fault on the connected robot is cleared");
66 spdlog::info(
"Enabling robot ...");
70 while (!robot.operational()) {
71 std::this_thread::sleep_for(std::chrono::seconds(1));
73 spdlog::info(
"Robot is now operational");
78 robot.SwitchMode(rdk::Mode::NRT_PRIMITIVE_EXECUTION);
84 spdlog::info(
"Executing primitive: Home");
87 robot.ExecutePrimitive(
"Home", std::map<std::string, rdk::FlexivDataTypes> {});
90 while (!std::get<int>(robot.primitive_states()[
"reachedTarget"])) {
91 std::this_thread::sleep_for(std::chrono::seconds(1));
103 spdlog::info(
"Executing primitive: MoveJ");
106 robot.ExecutePrimitive(
"MoveJ",
108 {
"target",
rdk::JPos({30, -45, 0, 90, 0, 40, 30}, {-50, 30})},
110 std::vector<rdk::JPos> {
rdk::JPos({10, -30, 10, 30, 10, 15, 10}, {-15, 10}),
111 rdk::JPos({20, -60, -10, 60, -10, 30, 20}, {-30, 20})}},
118 while (!std::get<int>(robot.primitive_states()[
"reachedTarget"])) {
120 spdlog::info(
"Current primitive states:");
121 for (
const auto& st : robot.primitive_states()) {
122 std::cout << st.first <<
": " << rdk::utility::FlexivTypes2Str(st.second);
123 std::cout << std::endl;
125 std::this_thread::sleep_for(std::chrono::seconds(1));
138 spdlog::info(
"Executing primitive: MoveL");
141 robot.ExecutePrimitive(
"MoveL",
143 {
"target",
rdk::Coord({0.65, -0.3, 0.2}, {180, 0, 180}, {
"WORLD",
"WORLD_ORIGIN"})},
145 std::vector<rdk::Coord> {
146 rdk::Coord({0.45, 0.1, 0.2}, {180, 0, 180}, {
"WORLD",
"WORLD_ORIGIN"}),
147 rdk::Coord({0.45, -0.3, 0.2}, {180, 0, 180}, {
"WORLD",
"WORLD_ORIGIN"})}},
149 {
"zoneRadius",
"Z50"},
153 while (!std::get<int>(robot.primitive_states()[
"reachedTarget"])) {
154 std::this_thread::sleep_for(std::chrono::seconds(1));
161 spdlog::info(
"Executing primitive: MoveL");
164 std::array<double, 4> targetQuat = {0.9185587, 0.1767767, 0.3061862, 0.1767767};
166 auto targetEulerDeg = rdk::utility::Rad2Deg(rdk::utility::Quat2EulerZYX(targetQuat));
169 robot.ExecutePrimitive(
171 {
"target",
rdk::Coord({0.0, 0.0, 0.0}, targetEulerDeg, {
"TRAJ",
"START"})},
175 while (!std::get<int>(robot.primitive_states()[
"reachedTarget"])) {
176 std::this_thread::sleep_for(std::chrono::seconds(1));
182 }
catch (
const std::exception& e) {
183 spdlog::error(e.what());
Main interface to control the robot, containing several function categories and background services.
Data structure representing the customized data type "COORD" in Flexiv Elements.
Data structure representing the customized data type "JPOS" in Flexiv Elements.