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));
105 spdlog::info(
"Executing primitive: MoveJ");
108 robot.ExecutePrimitive(
"MoveJ",
110 {
"target",
rdk::JPos({30, -45, 0, 90, 0, 40, 30}, {-50, 30})},
112 std::vector<rdk::JPos> {
rdk::JPos({10, -30, 10, 30, 10, 15, 10}, {-15, 10}),
113 rdk::JPos({20, -60, -10, 60, -10, 30, 20}, {-30, 20})}},
116 {
"lockExternalAxes", 0},
123 while (!std::get<int>(robot.primitive_states()[
"reachedTarget"])) {
125 spdlog::info(
"Current primitive states:");
126 for (
const auto& st : robot.primitive_states()) {
127 std::cout << st.first <<
": " << rdk::utility::FlexivTypes2Str(st.second);
128 std::cout << std::endl;
130 std::this_thread::sleep_for(std::chrono::seconds(1));
143 spdlog::info(
"Executing primitive: MoveL");
146 robot.ExecutePrimitive(
"MoveL",
148 {
"target",
rdk::Coord({0.65, -0.3, 0.2}, {180, 0, 180}, {
"WORLD",
"WORLD_ORIGIN"})},
150 std::vector<rdk::Coord> {
151 rdk::Coord({0.45, 0.1, 0.2}, {180, 0, 180}, {
"WORLD",
"WORLD_ORIGIN"}),
152 rdk::Coord({0.45, -0.3, 0.2}, {180, 0, 180}, {
"WORLD",
"WORLD_ORIGIN"})}},
154 {
"zoneRadius",
"Z50"},
158 while (!std::get<int>(robot.primitive_states()[
"reachedTarget"])) {
159 std::this_thread::sleep_for(std::chrono::seconds(1));
166 spdlog::info(
"Executing primitive: MoveL");
169 std::array<double, 4> targetQuat = {0.9185587, 0.1767767, 0.3061862, 0.1767767};
171 auto targetEulerDeg = rdk::utility::Rad2Deg(rdk::utility::Quat2EulerZYX(targetQuat));
174 robot.ExecutePrimitive(
176 {
"target",
rdk::Coord({0.0, 0.0, 0.0}, targetEulerDeg, {
"TRAJ",
"START"})},
180 while (!std::get<int>(robot.primitive_states()[
"reachedTarget"])) {
181 std::this_thread::sleep_for(std::chrono::seconds(1));
187 }
catch (
const std::exception& e) {
188 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.
Data structure representing the customized data type "JPOS" in Flexiv Elements.