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

How to get the ros service argument type in python

asked 2021-02-23 10:08:04 -0500

DNiebuhr gravatar image

Hello, I'm writing a programm in which it should be possible to show the user the parameters he should give, when he calls a service. So far I know that:

  • I can get a ros service list with the get_service_list() function from the ros service python library: https://docs.ros.org/en/melodic/api/r...
  • I can get the service arguments by get_service_args(service_name): Same source This returns the name that I defined in the srv file. Example: If the following is my SRV file:

float64 move_x_target

(---) (without brackets)

bool success

Then the get_service_args function returns move_x_target.

So how do I get float64 into my python programm? I tried type(move_x_target) but this returns String.

Thanks in advance!

edit retag flag offensive close merge delete

Comments

I would suggest to take a look at how rqt_service_caller does this.

It seems like that implements basically what you describe.

gvdhoorn gravatar image gvdhoorn  ( 2021-02-23 11:42:47 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-05-03 09:32:16 -0500

DNiebuhr gravatar image

updated 2021-05-03 09:34:36 -0500

To anyone who is having a similar problem: I didn't really solve it but I found a workaround: I retrieve the Service class as a string and delete unused lines afterwards.

    self.needed_param = []
    service_class_text = get_service_class_by_name(self.address)._request_class._full_text
    line_list = service_class_text.splitlines()  # splits String in list of its lines
    for line in line_list:  # removes all lines that are irrellevant
        if line and not line.startswith("#") and not line.startswith("\n") and not line.startswith(
                "=") and not line.startswith(" ") and not line.startswith("MSG") and not ("/" in line):
            self.needed_param.append(line)  # safes the remaining lines in needed_param attribute

Like I said it's just a workaround but by catching exeptions, when the wrong data type is entered when calling the services, it worked for my case.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2021-02-23 10:08:04 -0500

Seen: 310 times

Last updated: May 03 '21