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

"template argument deduction/substitution failed:" error on using rclcpp::Node::create_wall_timer function

asked 2018-04-16 04:18:43 -0600

Skyking gravatar image

updated 2018-04-16 09:22:01 -0600

gvdhoorn gravatar image

Hi,

When using the rclcpp::Node::create_wall_timer function with std::bind , I am getting the following error

no matching function for call to ‘composition::Talker::create_wall_timer(std::chrono::seconds, std::_Bind_helper<false, void="" (composition::talker::*)(int),="" composition::talker*,="" int="">::type)’

The error can be reproducer if one changes std::bind function inside the create_wall_timer () to add extra arguments to the function pointer.

I am attaching the code for your kind reference.

#include "composition/talker_component.hpp"
#include <chrono>
#include <iostream>
#include <memory>
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"

using namespace std::chrono_literals;

namespace composition
{

Talker::Talker()
: Node("talker"), count_(0)
{
  // Create a publisher of "std_mgs/String" messages on the "chatter" topic.
  pubbase_= this->create_publisher<std_msgs::msg::String>("chatter");

  pub_ = create_publisher<std_msgs::msg::String>("chatter");
  timer_ = create_wall_timer(1s, std::bind(&Talker::on_timer, this,95));

}

void Talker::on_timer(int level)
{
  auto msg = std::make_shared<std_msgs::msg::String>();

  msg->data = "Hello World: " + std::to_string(++count_);

  // Put the message into a queue to be processed by the middleware.

  // This call is non-blocking.
  pub_->publish(msg);
}
edit retag flag offensive close merge delete

Comments

@Skyking please don't use the backtick formatting for code blocks. This is for single code Statements.

Just Highlight the copy-pasted code block and click the preformatted text button (the one with 10101010) on it. Thanks.

mgruhler gravatar image mgruhler  ( 2018-04-16 06:21:24 -0600 )edit

Thanks @mig

Skyking gravatar image Skyking  ( 2018-04-17 23:48:49 -0600 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2018-04-18 13:37:14 -0600

dhood gravatar image

There are some limitations on automatic type deduction of custom callbacks that can be worked around by explicitly declaring the std::function, e.g.:

  std::function<void()> callback_func = std::bind(&Talker::on_timer, this, 95);
  timer_ = create_wall_timer(1s, callback_func);

Or if you want to pass a variable in you might use std::cref in place of the 95.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2018-04-16 04:18:43 -0600

Seen: 3,862 times

Last updated: Apr 18 '18