rosservice package for ros2
Hi. Sorry for all mistakes, English is not my native language. I'm in procces of migrating my project to ROS2 Foxy. In my ROS1 project I have following launch file:
<?xml version="1.0"?>
<launch>
<arg name="enable" default="true"/>
<node pkg="rosservice" type="rosservice" name="enable_limiter" args="call --wait /minicar/control/enable_limiter $(arg enable)" />
</launch>
How can I use rosservice in such way in ROS2? I found ros2service package in /opt/ros/foxy/lib/python3.8/site-packages/ros2service path, but, strangely, couldn't find executable for it so I'm not sure, how this launch file should look in ROS2. Appreciate any help.
Asked by Edvard on 2022-11-16 01:28:30 UTC
Answers
Hello @Edvard,
Try out this code,
from launch import LaunchDescription
from launch_ros.actions import Node
from launch.substitutions import LaunchConfiguration
from launch.actions import DeclareLaunchArgument
from launch.substitutions import TextSubstitution
def generate_launch_description():
enable_launch_arg = DeclareLaunchArgument(
"enable", default_value=TextSubstitution(text="true")
)
node_1 = Node(
package='rosservice',
executable='rosservice',
name='enable_limiter',
arguments=["call","--wait","-b","/minicar/control/enable_limiter",],
parameters=[{
"enable": LaunchConfiguration('enable'),
}]
)
return LaunchDescription([
enable_launch_arg,
node_1,
])
Execution of code:
ros2 launch <path_to_launch_file> enable:=false
Asked by Ranjit Kathiriya on 2022-11-16 03:29:24 UTC
Comments
Thank you very much for your help. This is what I get
raise PackageNotFoundError(
ament_index_python.packages.PackageNotFoundError: "package 'rosservice' not found, searching: ['/home/mikita/ros2_ws/install/rqt_minicar_control', '/home/mikita/ros2_ws/install/magical_ros2_conversion_tool', '/home/mikita/ros2_ws/install/roscompile', '/home/mikita/ros2_ws/install/ros_introspection', '/home/mikita/ros2_ws/install/minicar_teleop', '/home/mikita/ros2_ws/install/minicar_slam', '/home/mikita/ros2_ws/install/minicar_simulator', '/home/mikita/ros2_ws/install/minicar_rviz', '/home/mikita/ros2_ws/install/minicar_navigation', '/home/mikita/ros2_ws/install/minicar_master', '/home/mikita/ros2_ws/install/minicar_hw', '/home/mikita/ros2_ws/install/minicar_description', '/home/mikita/ros2_ws/install/minicar_control', '/home/mikita/ros2_ws/install/minicar_bluetooth', '/home/mikita/ros2_ws/install/explore_lite', '/opt/ros/foxy']"
Maybe you have any though?
Asked by Edvard on 2022-11-16 03:44:52 UTC
rosservice : Ros2 does not find your package. Have you added your rosservice package into setup.py
file?
Asked by Ranjit Kathiriya on 2022-11-16 06:51:20 UTC
Thank you again, that you trying to help me. No, maybe I'm wrong, but following this tutorial I thought, that setup.py file adds in package if package itself contains only python files, but my package contains C++ nodes. Also, as far as I know, rosservice is ROS1 package and couldn't find in my system at all. I managed to find ros2service, but there are no executable in it.
Asked by Edvard on 2022-11-16 08:06:35 UTC
I am sorry. Yes, you are right you have to use CMakeLists.txt if you are using cpp. You are still getting same error?
Note: You need to change nodes and execution based on your package and node names.
feel free to drop a comment in case you are facing any issue.
Asked by Ranjit Kathiriya on 2022-11-16 08:39:28 UTC
I'm think that I managed to solve this issue, node is launched successfully for now. I launch this node independently, but because this node is part of bigger project and I for now managed port and start half of packages form which project consist I'll add comment regarding to this question than I manage to launch all parts of the project and test, if it works the way as it should. Thank you for your help
Asked by Edvard on 2022-11-17 01:26:08 UTC
Comments