6.8 Example does not work!

Hello

I am currently stucked with the example 6.8.
I already read here in the community, but I still can not make it work.
Here in this image you can see all the screenshots in which I am referring in my request.

So I followed the instruction

Created the package with catkin_create_pkg my_custom_srv_msg_pkg rospy
Then inside the package I did mkdir srv and created the MyCustomServiceMessage.srv file

And edited the CMakeLists.txt (screenshot 1)

And the package.xml (screenshot 2)

Then I went to the catkin_ws directory and did the catkin_make and source devel/setup.bash (screenshot 3)

It says in the notebook that I should see something like Generating Python code from SRV my_custom_srv_msg_pkg/MyCustomServiceMessage which I dont.

But when I do rossrv list | grep MyCustomServiceMessage I see that the message exists (screenshot 4)

So I tried to run the example custom_service_server.py (screenshot 5)

But then I get the error that it can’t find the module (screenshot 6)

I’ve read in the community forum and they say that you have to make the catkin_make and source command. I did both already multiple times, but it does still not work.

So I am really running out of ideas. So any help would be appreciated.

Thanks in advance

Hi @Dkae ,

Welcome to this Community!

I think you are using the wrong command to run the program.
You should use:

rosrun <package_name> <program_name.py>

instead of:

python <program_name.py>   # see below for more info

Also, you get this module not found error for custom message if you have not compiled it properly.
To make sure that the custom message package is properly compiled, run this command

cd ~/catkin_ws
catkin_make --only-pkg-with-deps my_custom_srv_msg_pkg
source devel/setup.bash

Once you have executed the above commands, then do the rosrun ... command on the same terminal.

That should fix your problem. Let me know if that does not work.

Why you cannot use python <program_name.py>:
When you have custom messages, you cannot use the python command. That is because the custom message that you have created is neither a python package nor an installed library with python pip.
Therefore, you can only use rosrun command and not python command. Python will NOT detect that import as a library or as a module. Thus you get a python error instead of ROS error.

Regards,
Girish

Hi @girishkumar.kannan, thanks for your fast reply. I tried it now with the catkin_make --only-pkg-with-deps my_custom_srv_msg_pkg and rosrun and it worked!

Thanks a lot for your help