ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

rosservice package for ros2

asked 2022-11-16 00:28:30 -0500

Edvard gravatar image

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-11-16 02:29:24 -0500

Ranjit Kathiriya gravatar image

updated 2022-11-16 02:34:33 -0500

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

edit flag offensive delete link more

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?

Edvard gravatar image Edvard  ( 2022-11-16 02:44:52 -0500 )edit

rosservice : Ros2 does not find your package. Have you added your rosservice package into setup.py file?

Ranjit Kathiriya gravatar image Ranjit Kathiriya  ( 2022-11-16 05:51:20 -0500 )edit

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.

Edvard gravatar image Edvard  ( 2022-11-16 07:06:35 -0500 )edit

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.

Ranjit Kathiriya gravatar image Ranjit Kathiriya  ( 2022-11-16 07:39:28 -0500 )edit

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

Edvard gravatar image Edvard  ( 2022-11-17 00:26:08 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2022-11-16 00:28:30 -0500

Seen: 94 times

Last updated: Nov 16 '22