ROS2 Basics in 5 Days (Python), Part 4 Services, quiz, create service /turn

Hello,

In the quiz of section 4 the instruction is to create the service Turn.srv
image

I’ve created the file turn.srv inside the folder srv inside the pkg services_quiz_srv

when searching for the service

image

I don’t see /turn

I know I’m missing something but I can’t put my finger on it.

Any ideas

Thank you

@TAURD ,

Did you make/build the package after adding the service message?
I believe this makes the service message “available” for access with service list command. (Although, I may be wrong.)

— Girish

1 Like

What creates the service is the service server. Which should be a script in your services_quiz directory. If you have not made that, or if you have and you are not running it, the service should not appear.

What should appear though is the Turn.srv interface when doing ros2 interface list.

As Girish says, also remember to build the package with colcon build from the ros2_ws directory in the shell.

2 Likes

Hello,

Thank you for your answer but I’m concerned this is not it.
I don’t remember when I’ve first created the pkg services_quiz and the service Turn.srv in services_quiz_srv but I built it before and after the command ros2 service list

For other services built was not necessary (see the beginning of section 4)
colcon build is not here but services are presented

image

Any other ideas about what I’m missing here?

Hello,

Thank you for your answer but I’m concerned this is not it.

I did ros2 interface list and looked in the entire list.

before and after colcon build for the entire src folder.

Nothing

I’m missing something for sure cause the code works but gradebot failed me because no /turn service

of course when I do the following I see the service

image

Any other options please?

Could you show the results of a ros2 interface list | grep services_quiz_srv please? If Turn.srv does not appear there, I do not know how to help you.

Hi @TAURD

let me clarify one thing first:

  • When you ask for a list of services available (ros2 service list) you are getting a list of services that are running at present. This means, nodes that are running right now in the computer and that have a service server. If you have a node that has a service server, and that node is not running, then the service of that node will not appear. Only the nodes running are taken into account when asking for services available. Actually, we should not say services available but running services.

  • Another thing is the message (also called interface) of a service. The message/interface of a service is the structure of data that the service will use to exchange information between the server and the client. So, if you do a ros2 interface list you will get a list of ALL THE MESSAGES/INTERFACES THAT EXIST IN THAT COMPUTER. However, in order for a service message/interface to appear in the list, you must have sourced the ROS2 workspace that contains the definition of that message/interface.

Having understood the previous two points, now we can solve your problem:

  • you need to source the ROS2 workspace that contains the definition of Turn.srv. That workspace is ros2_ws.

So you need to do:

source ~/ros2_ws/install/setup.bash

That source, includes already a source of /opt/ros/foxy/setup.bash in the inside, so you don’t need to source again the Foxy directory.

Now, you can list the messages/interfaces available with:

ros2 interface list

You should see your message in the list of services.

image

Thank you @rtellez for your answer

I understood both points

(Now I have a new question which is who made other services to running services?)

I did the source command

done!

done

image

No /turn here

Also no /age

image

(I complied and sourced before taking any action above)

Can you clarify

Thank you

It looks like you have a problem with your sources mixing ROS1 and ROS2.

Try this to clean everything:

  1. Go to ~/ros2_ws and delete build, install and log directories
  2. Restart ALL the terminals (by clicking on the red cross icon of EACH terminal)
  3. On one of the restarted terminals, go to ~/ros2_ws
  4. Source /opt/ros/foxy/setup.bash
  5. Recompile the ros2_ws

This should have generated a new fresh code which only sources ROS2.

Now, what do you get from the list of interfaces?

Hello

Thank you for your answer @rtellez

Here are the step I performed:

step 1:

before

after

step 2:

Done

step 3:

Done
image

step 4:

Done

step 5:

Done
image

then
ros2 interface list or ros2 service list

No turn in the list :pensive:

What am I doing wrong here??

Any other options

Thank you

Hello

Thank you @rtellez @GasPatxo @girishkumar.kannan and my student @benjamin32561 for the help

This was the error

Since I did copy-paste from movement_pkg

Now I have

and here its is (after launching the launch file)

image

1 Like

This topic was automatically closed after 12 hours. New replies are no longer allowed.