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

"rosservice list" and "info" from c++

asked 2014-04-10 04:42:34 -0500

Bastbeat gravatar image

updated 2016-10-24 08:36:48 -0500

ngrennan gravatar image

How can I access to the functions of "rosservice" from a c++? I need to know the existing services and information about each service. Thanks

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2014-04-10 08:55:42 -0500

dornhege gravatar image

A simple way might be to call rosservice.

Alternatively you can use the ROS Master API. In this case getSystemState.

edit flag offensive delete link more

Comments

are there some examples of that?

Bastbeat gravatar image Bastbeat  ( 2014-04-10 11:18:51 -0500 )edit
dornhege gravatar image dornhege  ( 2014-04-11 08:52:06 -0500 )edit

Thanks, I posted the solution. Your link was really usefull.

Bastbeat gravatar image Bastbeat  ( 2014-04-13 03:18:21 -0500 )edit

But, how can I get information about a service?

Bastbeat gravatar image Bastbeat  ( 2014-04-13 04:19:50 -0500 )edit
2

answered 2014-04-13 03:12:11 -0500

Bastbeat gravatar image

With this code, you can get the name of all the running services and copy them to an array.

ros::init(argc, argv, "node");
    ros::NodeHandle n;
    XmlRpc::XmlRpcValue req = "/node";
    XmlRpc::XmlRpcValue res;
    XmlRpc::XmlRpcValue pay;

    if (ros::ok() == true)
    {
ros::master::execute("getSystemState",req ,res ,pay ,true);
    std::string state[res.size()];
      for(int x=0 ; x<res[2][2].size() ; x++)
      {
          std::string gh = res[2][2][x][0].toXml().c_str();
          gh.erase(gh.begin(), gh.begin()+7);
          gh.erase(gh.end()-8, gh.end());
          state[x] = gh;
      }
}
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2014-04-10 04:42:34 -0500

Seen: 1,139 times

Last updated: Apr 13 '14