0
$\begingroup$

tl;dr

  • Expected behaviour: Having a non-blocking spin.
  • Current behaviour: spin_until_future_complete() always returns timeout without firing any topic callback

Hi, I am working on implementing the ROS2 logic into an existing Qt5 GUI application. Because of this I should somewhat follow the already established patterns. To achieve this I wanted to call a non-blocking spin, which I understood as the rclcpp::spin_until_future_complete() would be perfect for with the parameter timeout set to 0, as I reffered to this fragment of ROS2 Humble documentation:

timeout – [in] Optional timeout parameter, which gets passed to Executor::spin_node_once. -1 is block forever, 0 is non-blocking. If the time spent inside the blocking loop exceeds this timeout, return a TIMEOUT return code.

Currently I am testing the solution, but it always returns TIMEOUT:

int main(int argc, char *argv[])
{
    rclcpp::init(argc, argv);

    std::promise<int> prom;
    std::future<int> fut = prom.get_future();
    auto node = std::make_shared<ros2_proxy>("ros2_node", true); // true to create subscriptions on initialization
    rclcpp::spin_until_future_complete(node, fut, std::chrono::duration</*TimeRepT*/int64_t, /*TimeT*/ std::milli>(0));

    std::thread t([&prom]() -> void {
        std::this_thread::sleep_for(std::chrono::seconds(60));  // wait for 60 seconds
        prom.set_value(10);  // fulfill promise (sends value)
    });

    fut.wait();
    t.join();
    /// ...

Would appreciate any help or ideas towards solving this issue, maybe there is more elegant way to make the spin non-blocking?

$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.