ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
From your question it seems that you expect that create_wall_timer
can be used to specify how often the TimeSynchronizer
calls its callback, but that's not the case. The synchronizer will just call its callback as soon as it has two synchronized messages to pass on.
create_wall_timer
sets a completely unrelated timer that just calls its callback after the set time. It doesn't know about any topics or events that you may have used the same callback function for. And it does not have any of such information to pass to its callback, so it expects the callback function that you give to take 0 arguments. You pass it one that takes 2, which causes the error: 'there is no matching version of create_wall_timer
that can deal with a callback that takes 2 arguments'.
That's why your test with callback_test
does work, it takes no arguments, which is what the timer expects.
Side notes:
bind
, you should be able to just use sync.registerCallback(&callback)
. bind
is used if you want to use a class method as callback and you have to bind it to this
.You can also use lambda's instead of either boost::bind
or std::bind
, which I personally like better so you don't have to use function pointers or library methods:
node->create_wall_timer(500ms, []() -> void { callback(); });
Again here wrapping into a lambda is not strictly necessary and you could just use &callback
; you could instead put the logic inside capture()
directly into the lambda function, or capture any local variables that can be used at the time the callback is called. For instance as alternative to binding this
if callback
is a method on your node class:
node->create_wall_timer(500ms, [this]() -> void { callback(); });