1
$\begingroup$

I am trying to convert a piece of code written in ROS1 to ROS2. I am having trouble with the following line, which instantiates a ros:::Timer object:

in ROS1:

timer_ = control_nh_.createTimer(ros::Duration(1.0), 
    boost::bind(&Robot::feedbackHandle, this, _1, handle));

Which I tried to covert to ROS2 like this:

std::function<void(const std::shared_ptr<rclcpp_action::ServerGoalHandle<control_msgs::action::FollowJointTrajectory>>)> 
callback_func1 = std::bind(&Robot::feedbackHandle, this, handle);
timer_ = rclcpp::create_timer(control_nh_, control_nh_->get_clock(), 
rclcpp::Duration(1, 0), callback_func1);

However I get the following error:

.../robot.cpp:159:34:   required from here
/opt/ros/humble/include/rclcpp/rclcpp/create_timer.hpp:44:60: error: no type named ‘type’ in ‘struct std::enable_if<false, void>’
   44 |   auto timer = rclcpp::GenericTimer<CallbackT>::make_shared(
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
   45 |     clock,
      |     ~~~~~~                                                  
   46 |     period.to_chrono<std::chrono::nanoseconds>(),
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~           
   47 |     std::forward<CallbackT>(callback),
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                      
   48 |     node_base->get_context());
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~                               
/opt/ros/humble/include/rclcpp/rclcpp/create_timer.hpp:44:60: error: no type named ‘type’ in ‘struct std::enable_if<false, void>’
/opt/ros/humble/include/rclcpp/rclcpp/create_timer.hpp:44:60: note: invalid template non-type parameter
/opt/ros/humble/include/rclcpp/rclcpp/create_timer.hpp: In instantiation of ‘rclcpp::TimerBase::SharedPtr rclcpp::create_timer(std::shared_ptr<rclcpp::node_interfaces::NodeBaseInterface>, std::shared_ptr<rclcpp::node_interfaces::NodeTimersInterface>, rclcpp::Clock::SharedPtr, rclcpp::Duration, CallbackT&&, rclcpp::CallbackGroup::SharedPtr) [with CallbackT = std::function<rclcpp_action::GoalResponse(const std::array<unsigned char, 16>&, std::shared_ptr<const control_msgs::action::FollowJointTrajectory_Goal_<std::allocator<void> > >)>&; rclcpp::TimerBase::SharedPtr = std::shared_ptr<rclcpp::TimerBase>; rclcpp::Clock::SharedPtr = std::shared_ptr<rclcpp::Clock>; rclcpp::CallbackGroup::SharedPtr = std::shared_ptr<rclcpp::CallbackGroup>]’:
/opt/ros/humble/include/rclcpp/rclcpp/create_timer.hpp:64:22:   required from ‘rclcpp::TimerBase::SharedPtr rclcpp::create_timer(NodeT, rclcpp::Clock::SharedPtr, rclcpp::Duration, CallbackT&&, rclcpp::CallbackGroup::SharedPtr) [with NodeT = std::shared_ptr<rclcpp::Node>; CallbackT = std::function<rclcpp_action::GoalResponse(const std::array<unsigned char, 16>&, std::shared_ptr<const control_msgs::action::FollowJointTrajectory_Goal_<std::allocator<void> > >)>&; rclcpp::TimerBase::SharedPtr = std::shared_ptr<rclcpp::TimerBase>; rclcpp::Clock::SharedPtr = std::shared_ptr<rclcpp::Clock>; rclcpp::CallbackGroup::SharedPtr = std::shared_ptr<rclcpp::CallbackGroup>]’

I coudln't find anything resembling this error while searching, can anyone help me understand what I did wrong?

Here are the declarations of the function that I'm trying to bind:

    void feedbackHandle(const std::shared_ptr<rclcpp_action::ServerGoalHandle<control_msgs::action::FollowJointTrajectory>> handle);
    rclcpp_action::GoalResponse moveHandle(const rclcpp_action::GoalUUID &uuid, std::shared_ptr<const control_msgs::action::FollowJointTrajectory::Goal> goal);

Thanks in advance.

$\endgroup$

0

Your Answer

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

Browse other questions tagged or ask your own question.