The passed service type is invalid (ROS2 Basics in 5 Days (Python))

I’m working on the Unit 4 of ROS2 Basics in 5 Days (Python) quiz. I’m testing that my service is working correctly by submitting the following command:

user:~/ros2_ws$ ros2 service call /turn services_quiz_srv/srv/Turn "{direction: 'left', angular_velocity: 0.5, time: 5}"
The passed service type is invalid

What I’ve tried:

To ensure the “turn” service is running:

user:~/ros2_ws$ ros2 service list
/camera_driver/describe_parameters
/camera_driver/get_parameter_types
/camera_driver/get_parameters
/camera_driver/list_parameters
/camera_driver/set_parameters
/camera_driver/set_parameters_atomically
/gazebo/describe_parameters
/gazebo/get_parameter_types
/gazebo/get_parameters
/gazebo/list_parameters
/gazebo/set_parameters
/gazebo/set_parameters_atomically
/moving
/moving_service/describe_parameters
/moving_service/get_parameter_types
/moving_service/get_parameters
/moving_service/list_parameters
/moving_service/set_parameters
/moving_service/set_parameters_atomically
/pause_physics
/reset_simulation
/reset_world
/robot_state_publisher/describe_parameters
/robot_state_publisher/get_parameter_types
/robot_state_publisher/get_parameters
/robot_state_publisher/list_parameters
/robot_state_publisher/set_parameters
/robot_state_publisher/set_parameters_atomically
/service/describe_parameters
/service/get_parameter_types
/service/get_parameters
/service/list_parameters
/service/set_parameters
/service/set_parameters_atomically
/set_camera_info
/stop
/turn
/turn_server/describe_parameters
/turn_server/get_parameter_types
/turn_server/get_parameters
/turn_server/list_parameters
/turn_server/set_parameters
/turn_server/set_parameters_atomically
/turtlebot3_diff_drive/describe_parameters
/turtlebot3_diff_drive/get_parameter_types
/turtlebot3_diff_drive/get_parameters
/turtlebot3_diff_drive/list_parameters
/turtlebot3_diff_drive/set_parameters
/turtlebot3_diff_drive/set_parameters_atomically
/turtlebot3_imu/describe_parameters
/turtlebot3_imu/get_parameter_types
/turtlebot3_imu/get_parameters
/turtlebot3_imu/list_parameters
/turtlebot3_imu/set_parameters
/turtlebot3_imu/set_parameters_atomically
/turtlebot3_joint_state/describe_parameters
/turtlebot3_joint_state/get_parameter_types
/turtlebot3_joint_state/get_parameters
/turtlebot3_joint_state/list_parameters
/turtlebot3_joint_state/set_parameters
/turtlebot3_joint_state/set_parameters_atomically
/turtlebot3_laserscan/describe_parameters
/turtlebot3_laserscan/get_parameter_types
/turtlebot3_laserscan/get_parameters
/turtlebot3_laserscan/list_parameters
/turtlebot3_laserscan/set_parameters
/turtlebot3_laserscan/set_parameters_atomically
/unpause_physics

To ensure I’m inputting the correct type:

user:~/ros2_ws$ ros2 service type /turn
services_quiz_srv/srv/Turn

Turn.srv ( ~/ros2_ws/src/services_quiz_srv/srv ):

string direction               # Direction to spin (right or left)
float64 angular_velocity       # Angular Velocity (in rad/s)
int32 time                     # Duration of the spin (in seconds)
---
bool success                   # Did it achieve it?

CMakeLists.txt ( ~/ros2_ws/src/services_quiz_srv ):

cmake_minimum_required(VERSION 3.8)
project(services_quiz_srv)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(rosidl_default_generators REQUIRED)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # comment the line when a copyright and license is added to all source files
  set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # comment the line when this package is in a git repo and when
  # a copyright and license is added to all source files
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

rosidl_generate_interfaces(${PROJECT_NAME}
	"srv/Turn.srv"
)

ament_package()


package.xml ( ~/ros2_ws/src/services_quiz_srv ):

<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
  <name>services_quiz_srv</name>
  <version>0.0.0</version>
  <description>TODO: Package description</description>
  <maintainer email="user@todo.todo">user</maintainer>
  <license>TODO: License declaration</license>

  <buildtool_depend>ament_cmake</buildtool_depend>

  <depend>rclcpp</depend>
  <depend>std_msgs</depend>

  <build_depend>rosidl_default_generators</build_depend>
  <exec_depend>rosidl_default_runtime</exec_depend>
  <member_of_group>rosidl_interface_packages</member_of_group>

  <test_depend>ament_lint_auto</test_depend>
  <test_depend>ament_lint_common</test_depend>

  <export>
    <build_type>ament_cmake</build_type>
  </export>
</package>

I’ve also deleted the folders “services_quiz” and “services_quiz_srv” from the install and build folders in ~/ros2_ws/. What am I missing here?

Thanks.

I don’t know what’s changed since I logged in earlier, but now I can’t successfully launch the service.

user:~/ros2_ws$ ros2 launch services_quiz services_quiz_server.launch.py
[INFO] [launch]: All log files can be found below /home/user/.ros/log/2024-02-13-00-29-09-580581-3_xterm-7669
[INFO] [launch]: Default logging verbosity is set to INFO
[ERROR] [launch]: Caught exception in launch (see debug for traceback): executable 'turn_server' not found on the libexec directory '/home/user/ros2_ws/install/services_quiz/lib/services_quiz'

Now when trying to build the services_quiz_srv package, I get this:

user:~/ros2_ws$ colcon build --packages-select services_quiz_srv
[1.314s] WARNING:colcon.colcon_core.package_selection:Some selected packages are already built in one or more underlay workspaces:
        'services_quiz_srv' is in: /home/user/ros2_ws/install/services_quiz_srv
If a package in a merged underlay workspace is overridden and it installs headers, then all packages in the overlay must sort their include directories by workspace order. Failure to do so may result in build failures or undefined behavior at run time.
If the overridden package is used by another package in any underlay, then the overriding package in the overlay must be API and ABI compatible or undefined behavior at run time may occur.

If you understand the risks and want to override a package anyways, add the following to the command line:
        --allow-overriding services_quiz_srv

This may be promoted to an error in a future release of colcon-override-check.
Starting >>> services_quiz_srv
Finished <<< services_quiz_srv [1.98s]

Summary: 1 package finished [2.65s]

The second error is telling you there is a compilation issue that should be fixed by cleaning your workspace before compiling again:

cd ~/ros2_ws
rm -rf build/ install/
colcon build && source install/setup.bash

The first error is probably due to the way you have your terminal sourced. It should include ros2_ws, maybe it got “unsourced” accidentally at some point. Try it with

source ~/ros2_ws/install/setup.bash
ros2 service call...

If that still doesn’t work then it’s strange, since I can see that the service exists. Sometimes ROS 2 is quite picky in how you need to fillout the message data, so try pressing Tab after typing the opening ". You can then type the first character, press Tab again, and it should be autocompleted.

Hello @pharva ,

I was checking your package and the problem is within your setup.py file. You have to specify a comma to separate the 2 executables, here:


entry_points={
        'console_scripts': [
        'turn_server = services_quiz.turn_server:main',
        'turn_client = services_quiz.turn_client:main'
        ],
    },

Otherwise, the executable is not properly generated, hence it cannot be found, which is the 2nd error you are getting.

Both of these solutions helped. Thank you for the quick reply.

@roalgoal
This solution’s purpose was to just wipe all the builds and installs to start fresh.

@albertoezquerro
This solution helped and what was missing from my setup.py file.

The service works now and when I call with this service, it works as intended.

user:~$ ros2 service call /turn services_quiz_srv/srv/Turn "{direction: 'left', angular_velocity: 0.5, time: 5}"
waiting for service to become available...
requester: making request: services_quiz_srv.srv.Turn_Request(direction='left', angular_velocity=0.5, time=5)

response:
services_quiz_srv.srv.Turn_Response(success=True)

I’ve noticed this warning come up when building the services_quiz_srv package, but it hasn’t stopped anything from working.

user:~/ros2_ws$ colcon build --packages-select services_quiz_srv
[1.433s] WARNING:colcon.colcon_core.package_selection:Some selected packages are already built in one or more underlay workspaces:
        'services_quiz_srv' is in: /home/user/ros2_ws/install/services_quiz_srv
If a package in a merged underlay workspace is overridden and it installs headers, then all packages in the overlay must sort their include directories by workspace order. Failure to do so may result in build failures or undefined behavior at run time.
If the overridden package is used by another package in any underlay, then the overriding package in the overlay mustbe API and ABI compatible or undefined behavior at run time may occur.

If you understand the risks and want to override a package anyways, add the following to the command line:
        --allow-overriding services_quiz_srv

This may be promoted to an error in a future release of colcon-override-check.
Starting >>> services_quiz_srv
Finished <<< services_quiz_srv [2.19s]

Summary: 1 package finished [2.89s]

None of the other packages issued this warning during their builds. After cleaning the workspace and rebuilding and reinstalling everything, is there another method to address this warning?

@pharva The warning is telling you that you are building a package that is already built in your workspace (ros2_ws). This can be more tricky when working with multiple workspaces, and if the package was built into another underlay workspace (let’s say another_ros2_ws), which would result in overriding packages. In this case, you can safely ignore it.

@albertoezquerro Thanks for the explanation and the help. Marking solved.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.