0
$\begingroup$

I am getting error No module named roslaunch when executing a ROS 2 launch file. I know this question is already asked here but it dose not seems to solve my problem as it is for ROS 1. I know that roslaunch is for ROS 1 so getting error "No module named roslaunch" for ROS 2 seems unnecessary.

I executed this same package on one PC and it is woking fine, but because my application requires GPU, I shifted to another PC and copy pasted the package rebuilding it with colcon build --symlink-install and now I am getting this error.

Another Post mentions that the issue is related to environment variable being set to a wrong path but in my case $ROS_PACKAGE_PATH dose not prints out anything means its empty.

Also I did not understand to which path is is pointing to because ros 2 does not has any folder named "ros_stacks" as mentioned in export ROS_PACKAGE_PATH=/home/maneesh/ros_stacks:$ROS_PACKAGE_PATH

Actually the error "no module name roslaunch" is arising at 29th line of the launch file "robot_description_config = xacro.process_file(xacro_file)" and when I replace the line with " robot_description_config = Command(['xacro ', xacro_file])" the error changes to "no module named rosgraph" . "rosgraph" is also a ros1 package.

Launch File:

import os

from ament_index_python.packages import get_package_share_directory

from launch import LaunchDescription
from launch.substitutions import LaunchConfiguration
from launch.actions import DeclareLaunchArgument
from launch_ros.actions import Node
import launch_ros

from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource


import xacro


def generate_launch_description():

    # Check if we're told to use sim time
    use_sim_time = LaunchConfiguration('use_sim_time')

    # Process the URDF file
    pkg_path = os.path.join(get_package_share_directory('race_it'))
    
    #xacro_file = os.path.join(pkg_path,'description','robot.urdf.xacro')
    xacro_file = os.path.join(pkg_path,'description', 'race_car.xacro')
    
    robot_description_config = xacro.process_file(xacro_file)
    
    default_rviz_config_path = os.path.join(pkg_path, 'config/rviz/urdf_config.rviz')
    
    # Create a robot_state_publisher node
    params = {'robot_description': robot_description_config.toxml(), 'use_sim_time': use_sim_time}
    node_robot_state_publisher = Node(
        package='robot_state_publisher',
        executable='robot_state_publisher',
        output='screen',
        parameters=[params]
    )
    
    
        
    joint_state_publisher_node = launch_ros.actions.Node(
        package='joint_state_publisher',
        executable='joint_state_publisher',
        name='joint_state_publisher'
    )
    

    rviz_node = launch_ros.actions.Node(
        package='rviz2',
        executable='rviz2',
        name='rviz2',
        output='screen',
        arguments=['-d', default_rviz_config_path],
    )

    
    gazebo = IncludeLaunchDescription(
            PythonLaunchDescriptionSource([os.path.join(
            get_package_share_directory('gazebo_ros'), 'launch', 'gazebo.launch.py')]),
            launch_arguments={'world': "./src/race_it/worlds/track_4.world"}.items()
    )
    
    
    spawn_entity = launch_ros.actions.Node(
        package='gazebo_ros',
        executable='spawn_entity.py',
        arguments=['-entity', '', '-topic', 'robot_description'],
        output='screen'
    )
    
    ackermann_spawner = Node(
    package="controller_manager",
    executable="spawner",
    arguments=["asc"],
)

    # Launch!
    return LaunchDescription([
        DeclareLaunchArgument(
            'use_sim_time',
            default_value='true',
            description='Use sim time if true'),

        node_robot_state_publisher,
        joint_state_publisher_node,
        rviz_node,
        gazebo,
        spawn_entity,
        ackermann_spawner
    ])
$\endgroup$
2
  • 1
    $\begingroup$ Welcome to Robotics Stack Exchange! Please share your launch file. Also, let us know what echo $ROS_DISTRO says in your machine. $\endgroup$
    – ravi
    Feb 6 at 1:38
  • $\begingroup$ Have update the question with launch file. echo $ROS_DISTRO = foxy. Keep in mind that the same launch file is working on other pc.Thanks. $\endgroup$
    – Pratham
    Feb 6 at 4:27

2 Answers 2

1
$\begingroup$

Well unfortunately I can't comment (as the stupid rule is to have more than 50 rep) so here I am commenting in answer.

Can you share the result of the $ env | grep ros after sourcing the bash shell properly? For me, it seems to be an issue of PYTHONPATH (not sure)

If you have multiple version of ros installed on the same system, you can try this .bash_aliases to manage the environment variables. Its for ros-noetic and ros-foxy but you can configure for other.

If not, you can have a look at this function to remove all the ros-related variables from the environment and then source everything again.

$\endgroup$
9
  • $\begingroup$ output of "$ env | grep ros": Before sourcing my workspace name "race_it" AMENT_PREFIX_PATH=/opt/ros/foxy PYTHONPATH=/opt/ros/foxy/lib/python3.8/site-packages LD_LIBRARY_PATH=/opt/ros/foxy/opt/yaml_cpp_vendor/lib:/opt/ros/foxy/opt/rviz_ogre_vendor/lib:/opt/ros/foxy/lib/x86_64-linux-gnu:/opt/ros/foxy/lib:/usr/lib/cuda/lib64: PATH=/home/pratham/.local/bin:/opt/ros/foxy/bin:/home/pratham/go/bin:/usr/local/go/bin:/home/pratham/anaconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/go/bin $\endgroup$
    – Pratham
    Feb 6 at 10:38
  • $\begingroup$ After sourcing my workspace name "race_it" PWD=/home/pratham/Desktop/Pratham/misc/race_it/ros2_acker AMENT_PREFIX_PATH=/home/pratham/Desktop/Pratham/misc/race_it/ros2_acker/install/temp_teleop:/home/pratham/Desktop/Pratham/misc/race_it/ros2_acker/install/race_it:/opt/ros/foxy CMAKE_PREFIX_PATH=/home/pratham/Desktop/Pratham/misc/race_it/ros2_acker/install/race_it COLCON_PREFIX_PATH=/home/pratham/Desktop/Pratham/misc/race_it/ros2_acker/install $\endgroup$
    – Pratham
    Feb 6 at 10:39
  • $\begingroup$ ## IN CONTINUATION TO "After sourcing my workspace name "race_it""## PYTHONPATH=/home/pratham/Desktop/Pratham/misc/race_it/ros2_acker/build/temp_teleop:/home/pratham/Desktop/Pratham/misc/race_it/ros2_acker/install/temp_teleop/lib/python3.8/site-packages:/opt/ros/foxy/lib/python3.8/site-packages LD_LIBRARY_PATH=/opt/ros/foxy/opt/yaml_cpp_vendor/lib:/opt/ros/foxy/opt/rviz_ogre_vendor/lib:/opt/ros/foxy/lib/x86_64-linux-gnu:/opt/ros/foxy/lib:/usr/lib/cuda/lib64: $\endgroup$
    – Pratham
    Feb 6 at 10:42
  • $\begingroup$ ## IN CONTINUATION TO "After sourcing my workspace name "race_it""## PATH=/home/pratham/.local/bin:/opt/ros/foxy/bin:/home/pratham/go/bin:/usr/local/go/bin:/home/pratham/anaconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/go/bin $\endgroup$
    – Pratham
    Feb 6 at 10:42
  • $\begingroup$ Hmm. I couldn't find any problem here. Also from your question, ROS_PACKAGE_PATH should not bother you in ros2. afaik its a concept of ros1. Ideally ros2launch should have been delivered with the installation. But you can confirm with ros2 pkg list | grep launch. Also, have you tried launching another file from another package? May be something that you can download with apt-get and try launching it? $\endgroup$
    – aarsht7
    Feb 6 at 15:44
1
$\begingroup$

I have found the solution. The problem was that I didn't installed ros2 properly. I figured out the solution by uninstall ros2 from the system when my launch file was working and reinstalling ros2 which started giving the same error.

After installing ros2 from the official site "https://docs.ros.org/en/humble/Installation/Ubuntu-Install-Debians.html" a few additional modules need to be installed.

Steps to install ros2 properly:

  • Step 1 --> Install ros2 using: https://docs.ros.org/en/humble/Installation/Ubuntu-Install-Debians.html
  • Step 2 --> sudo apt install ros-humble-xacro
  • Step 3 --> sudo apt install ros-humble-joint-state-publisher-gui
  • Step 4 --> sudo apt install ros-humble-gazebo-ros-pkgs
  • Step 5 --> sudo apt install ros-humble-ros2-control
  • Step 6 --> sudo apt install ros-humble-ros2-controllers
  • Step 7 --> sudo apt install ros-humble-gazebo-ros2-control
  • Step 8 --> sudo apt install ros-humble-controller-manager
  • Step 9 --> sudo apt install ros-humble-joint-trajectory-controller
  • Step 10 --> sudo apt install ros-humble-joint-state-broadcaster
  • Step 11 --> sudo apt install ros-humble-joint-state-publisher-gui

Just replace "humble" with the distro of ros you have installed. For example for foxy, you could write "sudo apt install ros-foxy-xacro".

After installing ros2 from the official site, I ran my launch file and got error "No module named Xacro". To solve it I did "pip install xacro" which what I feel installed xacro for ros1. Due to this this, xacro which belong to ros1 was looking for roslaunch which wasn't present as I installed ros2. To correct it, I did "pip uninstall xacro", and installed xacro for my ros distro using "sudo apt install ros-humble-xacro".

I got this command from this youtube channel: "https://www.youtube.com/@ArticulatedRobotics". It didnt specifically mentions this issue but, tells which modules to install as it proceeds with the series of videos. It has great content anyone starting with robotics.

Hope it helps others.

Thanks.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.