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

Problem in assigning a callback when it is a method (Rviz Interactive Markers)

asked 2021-02-04 05:40:32 -0500

Kansai gravatar image

updated 2021-02-04 06:44:26 -0500

I have tried the Rviz tutorial on Interactive markers, in particular the one for menus. But as you can see in the code this is not object-oriented.

I want to do the same using classes, and so far I have been able to show the menus and everything except the callback.

In the code you have

void deepCb( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback )
  {
      ROS_INFO("The deep sub-menu has been found.");
  }
void initMenu()
{
  h_first_entry = menu_handler.insert( "First Entry" );
  MenuHandler::EntryHandle entry = menu_handler.insert( h_first_entry, "deep" );
  entry = menu_handler.insert( entry, "sub" );
  entry = menu_handler.insert( entry, "menu", &deepCb );  //<----This works HERE but not with classes
  }

This code works but when I convert this to classes I have

void MyClass::deepCb( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback )
  {
      ROS_INFO("The deep sub-menu has been found.");
  }

So I want to do the line marked above

   entry = menu_handler.insert( entry, "menu", &MyClass::deepCb );

This does not compile. I got the error

‘static void boost::detail::function::function_void_mem_invoker1<MemberPtr, R, T0>::invoke(boost::detail::function::function_buffer&, T0) [with MemberPtr = void (MyClass::*)(const boost::shared_ptr<const visualization_msgs::InteractiveMarkerFeedback_<std::allocator<void> > >&); R = void; T0 = const boost::shared_ptr<const visualization_msgs::InteractiveMarkerFeedback_<std::allocator<void> > >&]’:


error: no match for call to ‘(boost::_mfi::mf1<void, MyClass, const boost::shared_ptr<const visualization_msgs::InteractiveMarkerFeedback_<std::allocator<void> > >&>) (const boost::shared_ptr<const visualization_msgs::InteractiveMarkerFeedback_<std::allocator<void> > >&)’
           BOOST_FUNCTION_RETURN(boost::mem_fn(*f)(BOOST_FUNCTION_ARGS));

My question is how can I assign a callback here when it is a method?

EDITT:

This is a question with a similar error problem but the answers do not solve the problem

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2021-09-30 10:01:56 -0500

dieg0- gravatar image

Hi Kansai, for this to work within a class you need to bind your callback and its argument:

entry = menu_handler.insert(entry, "menu", boost::bind(&MyClass::deepCb, this, _1));

Here, _1 is a placeholder to bind the only parameter your callback takes in, namely &feedback.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2021-02-04 05:40:32 -0500

Seen: 191 times

Last updated: Sep 30 '21