WallTimer Usage?

1,126 views
Skip to first unread message

Brad Baillio

unread,
Sep 16, 2016, 5:16:27 PM9/16/16
to ROS SIG NG ROS
I've been playing with the WallTimer and I can't get it to compile properly.
I get this error on Windows:

1>C:\Asi\gluegun-ros2-windows\install\include\rclcpp/timer.hpp(174): error C2207: 'rclcpp::timer::GenericTimer<FunctorT,Clock,__formal>::callback_': a member of a class template cannot acquire a function type
1>  C:\Asi\gluegun-ros2-windows\src\ros2\examples\rclcpp_examples\src\topics\talker.cpp(52): note: see reference to class template instantiation 'rclcpp::timer::GenericTimer<void (void),std::chrono::steady_clock,0x0>' being compiled

When I search this on stack overflow, I saw this post: http://stackoverflow.com/questions/13233213/can-a-function-type-be-a-class-template-parameter, which suggests that time.hpp should be modified on line 174 to be:
FunctorT* callback_;

I equally get frustrated during compilation in Linux.

Am I missing something?

In Windows, I'm just adding it to the talker.cpp sample program.


#include <iostream>
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
void callback()
{
 
}
int main(int argc, char * argv[])
{
  rclcpp::init(argc, argv);
  auto node = rclcpp::node::Node::make_shared("talker");
  rmw_qos_profile_t custom_qos_profile = rmw_qos_profile_default;
  custom_qos_profile.depth = 7;
  auto chatter_pub = node->create_publisher<std_msgs::msg::String>("chatter", custom_qos_profile);
  rclcpp::WallRate loop_rate(2);
  auto msg = std::make_shared<std_msgs::msg::String>();
  auto i = 1;
  while (rclcpp::ok()) {
    msg->data = "Hello World: " + std::to_string(i++);
    std::cout << "Publishing: '" << msg->data << "'" << std::endl;
    chatter_pub->publish(msg);
    rclcpp::spin_some(node);
    loop_rate.sleep();
  }
 
  auto time = std::chrono::nanoseconds(1);
  rclcpp::WallTimer<void(void)>(time, callback);
 

  return 0;
}


William Woodall

unread,
Sep 16, 2016, 5:23:49 PM9/16/16
to ROS SIG NG ROS
`rclcpp::WallTimer<std::function<void()>> wall_timer(time, callback);` works for me, but it's not clear to me why you need to specify the callback type and that it is not implicitly specialized using the second argument's type. It might be because we're mixing implicit template specialization with rvalue reference.

I would have hoped that `rclcpp::WallTimer wall_timer(time, callback);` would work, but it doesn't for me. You can create an issue on rclcpp if you like.

I didn't try Windows, but I expect my first code quote should work there too.

--
You received this message because you are subscribed to the Google Groups "ROS SIG NG ROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ros-sig-ng-ros+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
William Woodall
ROS Development Team

Brad Baillio

unread,
Sep 16, 2016, 5:58:20 PM9/16/16
to ROS SIG NG ROS
Ok. Thanks for the update.
I worked through understanding the std::function calls.
I got it to work both ways when using std::bind and std::function.

auto my_callback = std::bind(callback);
rclcpp::WallTime<std::function<void()>>(time,my_callback);

Works just fine.
To unsubscribe from this group and stop receiving emails from it, send an email to ros-sig-ng-ro...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Brad Baillio

unread,
Sep 22, 2016, 3:10:20 PM9/22/16
to ROS SIG NG ROS
So, should these wall timers just kick off on construction?
I can't get it to actually fire the callback on a period.
Is there a way to start it? Or some rclcpp framework under which it operates that I'm missing?

Brad Baillio

unread,
Sep 22, 2016, 3:16:41 PM9/22/16
to ROS SIG NG ROS
Oh, I just noticed the create_wall_timer method on the Node object.
Using that method to create a wall timer seems to work.

William Woodall

unread,
Sep 22, 2016, 4:15:29 PM9/22/16
to ROS SIG NG ROS
Yeah, the Timers affect the behavior of spinning so they need to be associated with the executor and we do that by creating them through the node. It would be possible, I think, to create a timer and put it in the executor without a node, but it cannot be used in isolation without an executor.

A Rate object, however, can be used without any other infrastructure but it works a bit differently.

To unsubscribe from this group and stop receiving emails from it, send an email to ros-sig-ng-ros+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages