How can I access data from a service

asked 2021-02-25 15:47:27 -0500

polestar98 gravatar image

Hi. How can I get the data from a service in real-time in my main python script? I found a service called "get_joint_properties" which returns the position of a revolute joint. From that service, I want to get the "Position" field value and work with it in "real-time" in my main python script. Is that possible? If yes, how?

Image : https://imgur.com/a/pT9dNHs

edit retag flag offensive close merge delete

Comments

This sounds to me like normal use of service. Is it not? If you haven't seen it, can you review the python service client tutorial and further explain if you actually want something else?

jdlangs gravatar image jdlangs  ( 2021-02-25 21:54:48 -0500 )edit

Thank for your answer! I did it and I get a response on my main program. The response looks like this. My question now, is, can I get the only value which is stored in "position" field? Sorry if my questions seems stupid, but I'm new to ros.

Image : https://imgur.com/a/j8JBhX6

polestar98 gravatar image polestar98  ( 2021-02-26 05:16:59 -0500 )edit

Yes, a service response is a python object generated to match the fields in the text description you show in your screenshot. The position field is a list of floating point values, so you would access that first value with something like resp.position[0]

jdlangs gravatar image jdlangs  ( 2021-02-26 17:39:55 -0500 )edit