Ask Your Question
0

Service Advertice and Class Usage

asked 2012-09-05 23:44:40 -0500

cheour gravatar image

Hello,

When we try to advertise a service we normally use as shown in ros tutorials:

 ros::ServiceServer service = n.advertiseService("add_two_ints", add);

This is with normal function way.

And if we want to use with class, documentation says use like this:

AddTwo a;
 ros::ServiceServer ss = n.advertiseService("add_two_ints", &AddTwo::add, &a);

Which means we need to initialize an object first.

But suppose I want to use everything related with ros in class and suppose my code is like this:

Comm::Comm()
{
  ros::ServiceServer ss = n.advertiseService("add_two_ints", &write);
  // write() is member of Comm class.
}

In my mind, I should have been use like this, but of course this kind of usage gave me error. Is there any possibility to use service advertise in class as describe. Do I need to initialize the class always?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2012-09-06 00:07:19 -0500

dornhege gravatar image

Use it the same way as above with: &Comm::write, this.

Also you might want to store the ServiceServer as a member variable as otherwise it will go out of scope.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2012-09-05 23:44:40 -0500

Seen: 68 times

Last updated: Sep 06 '12