Freedrive Mode example
Freedrive allows the robot arm to be manually pulled into desired positions and/or poses. The joints move with little resistance because the brakes are released.
An example to utilize the freedrive mode can be found in the freedrive_example.cpp.
Note
For the following example to work on an e-Series (PolyScope 5) robot, the robot has to be in remote control mode.
At first, we create a ExampleRobotWrapper
object in order to initialize communication with the
robot.
83 bool headless_mode = true;
84
85 g_my_robot = std::make_unique<ExampleRobotWrapper>(robot_ip, OUTPUT_RECIPE, INPUT_RECIPE, headless_mode,
86 "external_control.urp");
87
88 if (!g_my_robot->isHealthy())
89 {
90 URCL_LOG_ERROR("Something in the robot initialization went wrong. Exiting. Please check the output above.");
91 return 1;
92 }
Start freedrive mode
The UrDriver
provides a method to start freedrive mode directly:
94 URCL_LOG_INFO("Starting freedrive mode");
95 sendFreedriveMessageOrDie(control::FreedriveControlMessage::FREEDRIVE_START);
As it is potentially dangerous to leave the robot in freedrive mode, the robot program expect frequent keepalive messages to verify that the remote connection is still available and freedrive mode is being expected to be active.
Freedrive mode will be active from this point on until it is either stopped, or no keepalive message is received by the robot anymore.
Therefore, we have to make sure to send regular keepalive messages to the robot. The following
section will keep freedrive mode active for a period of time defined in seconds_to_run
.
97 std::chrono::duration<double> time_done(0);
98 std::chrono::duration<double> timeout(second_to_run);
99 auto stopwatch_last = std::chrono::steady_clock::now();
100 auto stopwatch_now = stopwatch_last;
101
102 while (time_done < timeout || second_to_run.count() == 0)
103 {
104 sendFreedriveMessageOrDie(control::FreedriveControlMessage::FREEDRIVE_NOOP);
105
106 stopwatch_now = std::chrono::steady_clock::now();
107 time_done += stopwatch_now - stopwatch_last;
108 stopwatch_last = stopwatch_now;
109 std::this_thread::sleep_for(std::chrono::milliseconds(2));
110 }
111
112 URCL_LOG_INFO("Stopping freedrive mode");
Stop freedrive Mode
To stop freedrive mode either stop sending keepalive signals or request deactivating it explicitly:
113 sendFreedriveMessageOrDie(control::FreedriveControlMessage::FREEDRIVE_STOP);