13 #include <spdlog/spdlog.h>
19 using namespace flexiv;
25 std::cout <<
"Required arguments: [robot_sn]" << std::endl;
26 std::cout <<
" robot_sn: Serial number of the robot to connect. Remove any space, e.g. Rizon4s-123456" << std::endl;
27 std::cout <<
"Optional arguments: None" << std::endl;
28 std::cout << std::endl;
32 int main(
int argc,
char* argv[])
37 if (argc < 2 || rdk::utility::ProgramArgsExistAny(argc, argv, {
"-h",
"--help"})) {
42 std::string robot_sn = argv[1];
46 ">>> Tutorial description <<<\nThis tutorial shows how to online update and interact with "
47 "the robot tools. All changes made to the robot tool system will take effect immediately "
48 "without needing to reboot. However, the robot must be put into IDLE mode when making "
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::IDLE);
87 spdlog::info(
"All configured tools:");
88 auto tool_list = tool.list();
89 for (
size_t i = 0; i < tool_list.size(); i++) {
90 std::cout <<
"[" << i <<
"] " << tool_list[i] << std::endl;
92 std::cout << std::endl;
95 spdlog::info(
"Current active tool: {}", tool.name());
98 std::string new_tool_name =
"ExampleTool1";
100 new_tool_params.
mass = 0.9;
101 new_tool_params.
CoM = {0.0, 0.0, 0.057};
102 new_tool_params.
inertia = {2.768e-03, 3.149e-03, 5.64e-04, 0.0, 0.0, 0.0};
103 new_tool_params.
tcp_location = {0.0, -0.207, 0.09, 0.7071068, 0.7071068, 0.0, 0.0};
107 if (tool.exist(new_tool_name)) {
109 "Tool with the same name [{}] already exists, removing it now", new_tool_name);
111 tool.Switch(
"Flange");
112 tool.Remove(new_tool_name);
116 spdlog::info(
"Adding new tool [{}] to the robot", new_tool_name);
117 tool.Add(new_tool_name, new_tool_params);
120 spdlog::info(
"All configured tools:");
121 tool_list = tool.list();
122 for (
size_t i = 0; i < tool_list.size(); i++) {
123 std::cout <<
"[" << i <<
"] " << tool_list[i] << std::endl;
125 std::cout << std::endl;
128 spdlog::info(
"Switching to tool [{}]", new_tool_name);
129 tool.Switch(new_tool_name);
132 spdlog::info(
"Current active tool: {}", tool.name());
135 tool.Switch(
"Flange");
138 std::this_thread::sleep_for(std::chrono::seconds(2));
139 spdlog::info(
"Removing tool [{}]", new_tool_name);
140 tool.Remove(new_tool_name);
142 spdlog::info(
"Program finished");
144 }
catch (
const std::exception& e) {
145 spdlog::error(e.what());
Main interface with the robot, containing several function categories and background services.