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

ros::Service same class instance in frequent callback

asked 2017-06-14 08:51:14 -0500

Felix_N gravatar image

Hello People,

I'm currently having issues writing a ros service for setting moveit goals. It looks like this:

bool myfunc_callback(mypkg::mysrv::Request &req, 
                     mypkg::mysrv::Response &res)
{
moveit::planning_interface::MoveGroupInterface move_group(PLANNING_GROUP);
//other moveit setup stuff


//my data handling

//my actual usage
move_group.setPoseTarget(target_pose);

return true;
}

int main(int argc, char **argv)
{
//ros init stuff (init and nodehandle)

ros::ServiceServer service = mynode.advertiseService("mysrv", myfunc_callback);

while (ros::ok())
{ ros::spinOnce();
r.sleep();
}
return 0;
}

From another node I'm calling this service several times. The service itself works just as intended. At its current state every single service call goes through the whole moveit setup stuff every time, which takes quite some time.

Now I want to implement another function, which also has access to the instance "move_goup". Due to the service callback being defined in some mysterious library i cannot easily add additional values to the callback.

Is there a possibility to define move_group in the main and pass it to the service callback function and to all other functions i need it in?

This would also increase performance significantly.

Thank you in advance

Felix

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2017-06-18 11:52:39 -0500

Felix_N gravatar image

I solved the problem using pointers.

At the top of the code (after the includes) I now have a pointer to a movegroupinterface object like this:

moveit::planning_interface::MoveGroupInterface *move_point;

In the service callback function I can use the pointer like this:

bool callback(.....) {
     move_point->setPoseTarget(target_pose1);
}

because i defined it in the main like this:

 int main(){
      static const std::string PLANNING_GROUP = "mygroup";
      moveit::planning_interface::MoveGroupInterface move_group(PLANNING_GROUP);
      move_point = &move_group;
}

There may be some more effective way, but that works just fine.

edit flag offensive delete link more
0

answered 2017-06-14 10:43:41 -0500

lucasw gravatar image

Instead of creating move_group within the callback make it and the callback a member of a C++ class. http://wiki.ros.org/roscpp_tutorials/... shows how to use class methods as callbacks.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2017-06-14 08:51:14 -0500

Seen: 684 times

Last updated: Jun 18 '17