Exercise 3.1 Failed to call service

Hello! I can’t seem to complete Exercise 3.1, I checked my code and it is the same as the solution. Below is the error message:

This is my launch file and CPP file:


I believe we dont need to have the service running right? Because in my launch file of this exercise, the include file (find…) line is to start the service first so the /trajectory_by_name service is already running once I roslaunch my launch file, all we need is to call the service so the robot moves. Please let me know what I am missing here. Thank you!

Hi @aw3645,

Did you remember to add trajectory_by_name_srv as a dependency when you created the package? If so, this should reflect in your CMakeLists.txt and package.xml:

user:~/catkin_ws/src$ catkin_create_pkg service_client_pkg roscpp trajectory_by_name_srv

Hello, @bayodesegun thank you for your reply. I checked my CMakeList and package file they both seem correct but my error message persists. Here are screenshots of my CMakeList and Package File, please let me know how else I can check. Thank you!

Hi Anthony,
the problem of the call is not related to neither your code nor your CMakeLists.txt. The problem is that the service you are trying to call ( the /trajectory_by_name) is not running.

Check carefully the description of the exercise, it says:

Keep in mind that, in order to be able to call the /trajectory_by_name service, you need to have it running.

This means that you have to launch it prior to launching your own program, otherwise, your program will not find the service ready.

Now, how to launch that service? You have the answer in the Exercise 3.4. I don’t want to give you the answer straight because I want you to check by yourself so you will store better in your brain those concepts. You will need that later to debug errors in ROS programs.

Let us know if that works for you

hi @rtellez I get what you are saying. when I have the service running already, my program will work. However, if you look at my launch file, I included the line to include the start service launch file so that line is supposed to take care of launching the trajectory by name service right? Let me know if I am thinking wrong please. Thanks

Hey @aw3645 you are right, your launch file is including the launch of the service (I did not check your launch file before :wink: ). So your service should be started and hence the call work properly. Then, why is the program failing?

The reason is that you are calling the service too fast, so even if you launched the service, it was not ready when you call it. This is also very common situation. How do you avoid that? Use the function rospy.wait_for_service. It is explained later in the course, so I will leave to you to figure out the details :wink:

Very good questions! Keep pushing like that!

2 Likes

in c++ this would work for you
os::service::waitForService("/trajectory_by_name");