Ask Your Question
0

Dynamic reconfigure C++ boost::bind error

asked 2019-12-16 10:22:54 -0600

Edoardo gravatar image

updated 2019-12-19 07:23:29 -0600

Hello everyone, I am working on ROS kinetic on Ubuntu 16.04. Today I have decided to implement the dynamic reconfigure in my node ROS in order to tune some parameters by dynamically change them instead than running each time my code to different values. I have followed the easy ROS tutorial in order to understand the basic functioning and now I'm trying to implement it in my code.

Basically I have my main file which is called main_ground_plan_fit.cpp:

#include <ros/ros.h>
#include "groundPlanFit.cpp"

int main(int argc, char **argv)
{
  ros::init(argc, argv, "ground_plan_fit");

  dynamic_reconfigure::Server<ground_plan_fit::ParametersConfig> server;
  dynamic_reconfigure::Server<ground_plan_fit::ParametersConfig>::CallbackType f;

  f = boost::bind(&ground_plan_fit::groundPlanFit::parametersCallback, _1, _2);
  server.setCallback(f);

  ros::NodeHandle node;
  ros::NodeHandle priv_nh("~");
  ground_plan_fit::groundPlanFit class_object(node,priv_nh);
  ros::spin();

  return 0;
}

The other file is the one including all my node functionalities including the node handler and the aforementioned callback to the parameters configurator which is called groundPlanFit.cpp:

// Includes and defines`
namespace ground_plan_fit{

  groundPlanFit::groundPlanFit(ros::NodeHandle ndoe, ros::NodeHandle private_nh){
     // Get parameters, publishers and subscriber definition with callback invocation
  }

  void groundPlanFit::parametersCallback(ground_plan_fit::ParametersConfig &config, uint32_t level) {
    ROS_INFO("Reconfigure Request: %d %f",
              config.int_param, config.double_param);
  }
}

Th problem is that when I try to compile I receive the error hereafter that I'm not understanding correctly:

   In file included from /usr/include/boost/bind.hpp:22:0,
                 from /opt/ros/kinetic/include/ros/publisher.h:35,
                 from /opt/ros/kinetic/include/ros/node_handle.h:32,
                 from /opt/ros/kinetic/include/ros/ros.h:45,
                 from /home/sivalab/lidar_perception/stage/perception_certitude/src/ground_plan_fit/src/main_ground_plan_fit.cpp:1:
/usr/include/boost/bind/bind.hpp: In instantiation of ‘struct boost::_bi::result_traits<boost::_bi::unspecified, void (ground_plan_fit::groundPlanFit::*)(ground_plan_fit::ParametersConfig&, unsigned int)>’:
/usr/include/boost/bind/bind.hpp:883:48:   required from ‘class boost::_bi::bind_t<boost::_bi::unspecified, void (ground_plan_fit::groundPlanFit::*)(ground_plan_fit::ParametersConfig&, unsigned int), boost::_bi::list2<boost::arg<1>, boost::arg<2> > >’
/home/sivalab/lidar_perception/stage/perception_certitude/src/ground_plan_fit/src/main_ground_plan_fit.cpp:11:78:   required from here
/usr/include/boost/bind/bind.hpp:69:37: error: ‘void (ground_plan_fit::groundPlanFit::*)(ground_plan_fit::ParametersConfig&, unsigned int)’ is not a class, struct, or union type
     typedef typename F::result_type type;
                                     ^
In file included from /usr/include/boost/function/detail/maybe_include.hpp:23:0,
                 from /usr/include/boost/function/detail/function_iterate.hpp:14,
                 from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:57,
                 from /usr/include/boost/function.hpp:64,
                 from /opt/ros/kinetic/include/ros/forwards.h:40,
                 from /opt/ros/kinetic/include/ros/common.h:37,
                 from /opt/ros/kinetic/include/ros/ros.h:43,
                 from /home/sivalab/lidar_perception/stage/perception_certitude/src/ground_plan_fit/src/main_ground_plan_fit.cpp:1:
/usr/include/boost/function/function_template.hpp: In instantiation of ‘static void boost::detail::function::void_function_obj_invoker2<FunctionObj, R, T0, T1>::invoke(boost::detail::function::function_buffer&, T0, T1) [with FunctionObj = boost::_bi::bind_t<boost::_bi::unspecified, void (ground_plan_fit::groundPlanFit::*)(ground_plan_fit::ParametersConfig&, unsigned int), boost::_bi::list2<boost::arg<1>, boost::arg<2> > >; R = void; T0 = ground_plan_fit::ParametersConfig& ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2019-12-17 14:24:21 -0600

borgcons gravatar image
#include <ros/ros.h>
#include "groundPlanFit.cpp"

int main(int argc, char **argv)
{
  ros::init(argc, argv, "ground_plan_fit");

  ros::NodeHandle node;
  ros::NodeHandle priv_nh("~");
  ground_plan_fit::groundPlanFit class_object(node,priv_nh);

  dynamic_reconfigure::Server<ground_plan_fit::ParametersConfig> server;
  dynamic_reconfigure::Server<ground_plan_fit::ParametersConfig>::CallbackType f;

  f = boost::bind(&ground_plan_fit::groundPlanFit::parametersCallback, &class_object, _1, _2);
  server.setCallback(f);

  ros::spin();

  return 0;
}

You just need to create the class_object first and then pass it as a parameter to bind. Your using a member function to bind to and it needs the classes "this" pointer.

edit flag offensive delete link more

Comments

It perfectly worked. Thank you very much.

Edoardo gravatar imageEdoardo ( 2019-12-19 07:32:53 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-12-16 10:22:54 -0600

Seen: 47 times

Last updated: Dec 17 '19