This tutorial executes several basic robot primitives (unit skills). For detailed documentation on all available primitives, please see Flexiv Primitives.
#include <spdlog/spdlog.h>
#include <iostream>
#include <thread>
void PrintHelp()
{
std::cout << "Required arguments: [robot SN]" << std::endl;
std::cout << " robot SN: Serial number of the robot to connect to. "
"Remove any space, for example: Rizon4s-123456" << std::endl;
std::cout << "Optional arguments: None" << std::endl;
std::cout << std::endl;
}
int main(int argc, char* argv[])
{
if (argc < 2 ||
flexiv::rdk::utility::ProgramArgsExistAny(argc, argv, {
"-h",
"--help"})) {
PrintHelp();
return 1;
}
std::string robot_sn = argv[1];
spdlog::info(
">>> Tutorial description <<<\nThis tutorial executes several basic robot primitives (unit "
"skills). For detailed documentation on all available primitives, please see [Flexiv "
"Primitives](https://www.flexiv.com/primitives/).");
try {
if (robot.fault()) {
spdlog::warn("Fault occurred on the connected robot, trying to clear ...");
if (!robot.ClearFault()) {
spdlog::error("Fault cannot be cleared, exiting ...");
return 1;
}
spdlog::info("Fault on the connected robot is cleared");
}
spdlog::info("Enabling robot ...");
robot.Enable();
while (!robot.operational()) {
std::this_thread::sleep_for(std::chrono::seconds(1));
}
spdlog::info("Robot is now operational");
robot.SwitchMode(
flexiv::rdk::Mode::NRT_PRIMITIVE_EXECUTION);
spdlog::info("Executing primitive: Home");
robot.ExecutePrimitive("Home()");
while (robot.busy()) {
std::this_thread::sleep_for(std::chrono::seconds(1));
}
spdlog::info("Executing primitive: MoveJ");
robot.ExecutePrimitive("MoveJ(target=30 -45 0 90 0 40 30)");
while (
flexiv::rdk::utility::ParsePtStates(robot.primitive_states(),
"reachedTarget") !=
"1") {
std::this_thread::sleep_for(std::chrono::seconds(1));
}
spdlog::info("Executing primitive: MoveL");
robot.ExecutePrimitive(
"MoveL(target=0.65 -0.3 0.2 180 0 180 WORLD WORLD_ORIGIN,waypoints=0.45 0.1 0.2 180 0 "
"180 WORLD WORLD_ORIGIN : 0.45 -0.3 0.2 180 0 180 WORLD WORLD_ORIGIN, vel=0.2)");
while (
flexiv::rdk::utility::ParsePtStates(robot.primitive_states(), "reachedTarget") != "1") {
std::this_thread::sleep_for(std::chrono::seconds(1));
}
spdlog::info("Executing primitive: MoveL");
std::array<double, 4> targetQuat = {0.9185587, 0.1767767, 0.3061862, 0.1767767};
auto targetEulerDeg
robot.ExecutePrimitive("MoveL(target=0.0 0.0 0.0 "
+
flexiv::rdk::utility::Arr2Str(targetEulerDeg) +
"TRAJ START)");
while (
flexiv::rdk::utility::ParsePtStates(robot.primitive_states(), "reachedTarget") != "1") {
std::this_thread::sleep_for(std::chrono::seconds(1));
}
robot.Stop();
} catch (const std::exception& e) {
spdlog::error(e.what());
return 1;
}
return 0;
}
Main interface with the robot, containing several function categories and background services.
double Rad2Deg(double rad)
Convert radians to degrees for a single value.