Problem with importing custom srv files - Exercise 6.3 - ROS in 5 Days

Hello. I am facing an Import Error when I try to launch/run my custom srv message file. It gives me the following error:

I have already done:

  • catkin_make and source devel/setup.bash in the terminal I am using
  • changed the CMakeLists.txt and package.xml file according to the instructions (there might be issues here tho)

Can someone please help me out?

Thanks :blush:

Hi @n.pradhan,
What’s your output for rossrv ?
Do you get something like this

rossrv show package_name/MyCustomServiceMessage         
[package_name/MyCustomServiceMessage]:   
int32 duration
---
bool success
2 Likes

Hello. Yes I get the following:

@n.pradhan, that looks good.
Please go through this post(attached below) if you haven’t already it deals with the same issue, if going through the post doesn’t resolve your problem, maybe you can post your package.xml and CMakeLists.txt files here so that we can check if something is missing there.

Post Link: No module named my_custom_srv_msg_pkg.srv how to resolve this error?

1 Like

@textzip Thanks for the help. I already tried everything in the post you linked. Removing the build folder and rebuilding it gave me a “Invoking cmake failed” error. Here is my CMakeList.txt and package.xml files:

Hi,
Try adding message_runtime to ur catkin_package() like this, redo catkin_make, source and then check.

catkin_package(
    CATKIN_DEPENDS rospy message_runtime  
)

I know the notebook from the course doesn’t add message_runtime but the ROS wiki page here shows that we should, http://wiki.ros.org/catkin/CMakeLists.txt#Messages.2C_Services.2C_and_Action_Targets

1 Like

@textzip I tried that but still got the same ImportError

Hmm, I’m not really sure where the error is maybe one of the moderators can help you better.
@bayodesegun

1 Like

@textzip ooh ok. Thank you very much for your time tho :blush:

Hi, did you delete your build/ and devel/ folders before compiling again?

1 Like

@roalgoal Hi. Yea I tried copying the build/ and devel/ folders outside the catkin_ws/ folder into a new temporary backup folder (because I didn’t want to delete it completely) then using catkin_make in the catkin_ws/ folder but I got a “Invoking cmake failed” error which I could not get rid of.

Screen Shot 2021-01-05 at 10.34.14 AM

Here is the error:

CMake Warning at /opt/ros/kinetic/share/catkin/cmake/catkinConfig.cmake:76 (find_package):
Could not find a package configuration file provided by “odometry_pkg” with
any of the following names:

odometry_pkgConfig.cmake
odometry_pkg-config.cmake

Add the installation prefix of “odometry_pkg” to CMAKE_PREFIX_PATH or set
“odometry_pkg_DIR” to a directory containing one of the above files. If
“odometry_pkg” provides a separate development package or SDK, be sure it
has been installed.
Call Stack (most recent call first):
odometry_pkg/CMakeLists.txt:10 (find_package)

– Could not find the required component ‘odometry_pkg’. The following CMake error indicates that you either need to install the package with the same name or change your environment so that it can be found.
CMake Error at /opt/ros/kinetic/share/catkin/cmake/catkinConfig.cmake:83 (find_package):
Could not find a package configuration file provided by “odometry_pkg” with
any of the following names:

odometry_pkgConfig.cmake
odometry_pkg-config.cmake

Add the installation prefix of “odometry_pkg” to CMAKE_PREFIX_PATH or set
“odometry_pkg_DIR” to a directory containing one of the above files. If
“odometry_pkg” provides a separate development package or SDK, be sure it
has been installed.
Call Stack (most recent call first):
odometry_pkg/CMakeLists.txt:10 (find_package)

– Configuring incomplete, errors occurred!
See also “/home/user/catkin_ws/build/CMakeFiles/CMakeOutput.log”.
See also “/home/user/catkin_ws/build/CMakeFiles/CMakeError.log”.
Invoking “cmake” failed

Hi,

Don’t worry about copying the build/ and devel/ folders to a backup folder, that’s probably what’s causing the error. Those folders are created every time you run catkin_make, and when you move them, the system can’t create new ones because the dependencies for the old folders are still there since you haven’t deleted them. Do this instead:

cd catkin_ws
rm -rf build/
rm -rf devel/
catkin_make
2 Likes

I was having the same problem, I removed the /build and /devel folders and I am now able to launch the service, however I’m not able to call the service:
ERROR: Unable to load type [my_custom_srv_msg_pkg/MyCustomServiceMessage].
Have you typed ‘make’ in [my_custom_srv_msg_pkg]?

I verified that the my_custom_srv_msg_pkg was there, but when I try to get information about the service I get:

Any ideas?
Thanks in advance

1 Like

Hi @lucas.gallindo.costa, It’s most probably because you didn’t source your setup.bash in all the terminals where your using the rosservice call.

Once you logout of your course and come back later you will have to source your terminals again.

3 Likes

Hello,

Doing this solved the ImportError:

cd catkin_ws
rm -rf build
catkin_make --only-pkg-with-deps <your_package_name>
source devel/setup.bash

Thanks everyone for the help.

2 Likes