Exercise 3.1 How to know what to import when interacting with ROS service messages programmatically

Hi, all,

in the exercise, two classes are inserted.

from iri_wam_reproduce_trajectory.srv import ExecTraj, ExecTrajRequest # Import the service message used by the service /gazebo/delete_model

But how could I know they have to be imported before I saw the example.

result = execute_trajectory_service_client(execute_trajectory_request_object) # Send through the connection the path to the trajectory file to be executed

And how could I know the input to execute_trajectory_service_client, is an object of ExecTrajRequest() ?

I would like to know where can I find those information.
Thank you in advance!

Kailin

Hi @kailin.tong,

The answers to these questions can be found by:

  • Following Example 3.5,
  • the section titled But how do you interact with a service programmatically?, and
  • the instructions in Exercise 3.1.

Now let me address them one by one.

  • We know the package we are dealing with here is iri_wam_reproduce_trajectory
  • We know it’s service messages will be located in iri_wam_reproduce_trajectory.srv
  • We know the name of the service is /execute_trajectory
  • We can get information about the service by running:

PS: to get information about a service, it needs to be running. Run it using the roslaunch command in another terminal:

user:~$ roslaunch iri_wam_aff_demo start_demo.launch
user:~$ rosservice info /execute_trajectory
Node: /iri_wam_reproduce_trajectory
URI: rosrpc://rosdscomputer:54731
Type: iri_wam_reproduce_trajectory/ExecTraj
Args: file
  • From the output above, we know this service is using the message type iri_wam_reproduce_trajectory/ExecTraj. Name of message file is ExecTraj. We can get more information about this service message by running:
user:~$ rossrv show iri_wam_reproduce_trajectory/ExecTraj
string file
---

  • We know that to interact with the service programmatically, we need to import:
    • ExecTraj for creating a connection to the service server, just as we used DeleteModel in Example 3.5
    • ExecTrajRequest for creating a request to send to the server, also similar to example 3.5
    • ExecTraj and ExecTrajRequest are available by convention in ROS; once you create and compile the service message. In fact, a third class is available, called ExecTrajResponse…you will learn more about this in Services part 2.

I hope this helps. Please let us know if you require further clarifications.


The code block you quoted above is sending the request object (execute_trajectory_request_object) through the service connection (execute_trajectory_service_client).

This is something similar to what is done in the “DeleteModel” example, Example 3.5

# Create the connection to the service
delete_model_service = rospy.ServiceProxy('/gazebo/delete_model', DeleteModel)
# Create an object of type DeleteModelRequest
delete_model_object = DeleteModelRequest()
...
# Send through the connection the name of the object to be deleted by the service
result = delete_model_service(delete_model_object)

Again, I hope this helps. Don’t hesitate to ask if you need further clarifications.

Keep pushing your ROS learning!

2 Likes

Thank you so much for this detailed clarification!
:+1::+1::+1:

1 Like

Thank you for the answer @bayodesegun. Although, I still don’t understand how to knowexecute_trajectory_service_client , is an object of ExecTrajRequest().

There is nothing that gives me an hint of the actual name of the object to use. I don’t know if i am missing something. I could not but just check the solution for the exercise though completed almost 80% of it on my own.

HI @jimohafeezco,

I think you meant to ask what Kailin asked earlier…

You know this by convention. The input to the service_client must be an object of the MessageRequest.

  • Your service message is named ExecTraj.
  • A service client connects to the service server and makes a request, just like your web browser (a client) connects to a webserver to request web pages, using HttpRequest objects.
  • Since we are dealing with an ExecTraj message, ROS makes an ExecTrajRequest object available once your service message has been properly compiled.
  • If your service message was named GetLunch, you will send a request to the “lunch server” using GetLunchRequest. And so on…

I hope this clarifies.

Cheers.

1 Like

I was about to ask the same question. This is not clear at all in the course notes (and, therefore, it is almost impossible to finish the exercise without help!). I’d be helpful to add a section in the notes about it.

Cheers,

1 Like

@paedusan,

Thanks so much for your feedback. We will consider updating the section But how do you interact with a service programmatically? to make this clearer.

I have to say I agree with the other comments above. The structure of this exercise is poor and doesn’t work well. The way the information is presented makes it very difficult to understand what should be achieved and how to go about the process.

To make you aware how poor this has been structured I am apart of an MSc cohort. None have been able to grasp the fundamental mechanics of the structure from your instructions or complete the exercise without looking up answers on google or through your forum. Even with the information from your forum it is still very difficult.

Thank you for your feedback @dale.carter84, we’ll definitely consider your points.

Hello everyone @dale.carter84 @paedusan @jimohafeezco @kailin.tong,

We have just added a small section explaining how to use the different parts of a custom message in your program. Please feel free to check it out and lets us know what you think about it. As always, thanks for your feedback.

Best,

1 Like