ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

So it looks like the system is not spinning. I guess because of this specific way of running rostest the node, never calls to ros::spin() because it is busy running the tests. So wherever a sleep needs to occur, we need to spin instead, something like this:

template <typename F>
void spin_sleep(ros::Duration duration, F break_condition) {
    auto end = ros::Time::now() + duration;
    while (end > ros::Time::now() && !break_condition()) {
        ros::spinOnce();
    }
}

void spin_sleep(ros::Duration duration) {
    spin_sleep(duration, []() { return false;});
}

Then instead of sleeping do something like this:

ros::NodeHandle nh(~);
SimpleTicker s(nh);
spin_sleep(ros::Duration{1});
ASSERT_GT(s.val, 0);