Skip to content

Commit 650c636

Browse files
committed
Stop torque_control example after timeout
On a simulated robot, torque_control commands don't have any effect. As a result, the torque_control example runs forever when being run on a simulated robot. This commit makes it use the second argument as a timeout after which the example is stopped. If the timeout is hit, it will print a warning stating that this is expected on a simulated robot. This should make the behavior similar to the other examples and make the CI run with that example.
1 parent e571c4d commit 650c636

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

examples/torque_control.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ int main(int argc, char* argv[])
5454
robot_ip = std::string(argv[1]);
5555
}
5656

57+
// Parse how many seconds to run
58+
auto second_to_run = std::chrono::seconds(0);
59+
if (argc > 2)
60+
{
61+
second_to_run = std::chrono::seconds(std::stoi(argv[2]));
62+
}
63+
5764
bool headless_mode = true;
5865
g_my_robot = std::make_unique<urcl::ExampleRobotWrapper>(robot_ip, OUTPUT_RECIPE, INPUT_RECIPE, headless_mode,
5966
"external_control.urp");
@@ -89,6 +96,7 @@ int main(int argc, char* argv[])
8996
// otherwise we will get pipeline overflows. Therefor, do this directly before starting your main
9097
// loop.
9198
g_my_robot->getUrDriver()->startRTDECommunication();
99+
auto start_time = std::chrono::system_clock::now();
92100
while (!(passed_positive_part && passed_negative_part))
93101
{
94102
// Read latest RTDE package. This will block for a hard-coded timeout (see UrDriver), so the
@@ -140,6 +148,12 @@ int main(int argc, char* argv[])
140148
return 1;
141149
}
142150
URCL_LOG_DEBUG("data_pkg:\n%s", data_pkg->toString().c_str());
151+
if (second_to_run.count() > 0 && (std::chrono::system_clock::now() - start_time) > second_to_run)
152+
{
153+
URCL_LOG_WARN("Time limit reached, stopping movement. This is expected on a simualted robot, as it doesn't move "
154+
"to torque commands.");
155+
break;
156+
}
143157
}
144158
g_my_robot->getUrDriver()->stopControl();
145159
URCL_LOG_INFO("Movement done");

0 commit comments

Comments
 (0)