0
$\begingroup$

I am trying to launch a simulation in Gazebo through ROS2 and I keep getting an error message stating that 'NoneType' object has no attribute 'get_launch_arguments_with_include_launch_description_actions'. I've made two launch files through following a tutorial, but I've seen many people make do with just one launch file (perhaps you only need one?). Anyways, here are my two launch.py files:

# room.launch.py   
#!/usr/bin/python3

import os

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource

pkg_name = "gazebo_simcontrol"
world_file = "room.world"

def generate_launch_description():

    pkg_gazebo_ros = get_package_share_directory(pkg_name)
    pkg_intro = get_package_share_directory(pkg_name)

    # launch Gazebo by including its definition
    gazebo = IncludeLaunchDescription(
        PythonLaunchDescriptionSource(
            os.path.join(pkg_gazebo_ros, 'launch', 'gazebo.launch.py'),
        )
    )

     # load the world file
    world_arg = DeclareLaunchArgument(
          'world',
          default_value=[os.path.join(pkg_intro, 'world', world_file), ''],
          description='SDF world file')
    
    return LaunchDescription([
        gazebo,
        world_arg
    ])

and then my second launch.py, named gazebo.launch.py:

#!/usr/bin/python3

import os
import sys
import rclpy
from gazebo_msgs.srv import SpawnEntity
from ament_index_python.packages import get_package_share_directory

package_name = 'gazebo_simcontrol'

def main(args=None):
    rclpy.init(args=args)

    node = rclpy.create_node('minimal_client')
    cli = node.create_client(SpawnEntity, '/spawn_entity')

    sdf_file_path = (os.path.join(get_package_share_directory(package_name), 'urdf', 'simpleMotor.urdf')),
    model = open(sdf_file_path[0], 'r').read()

    print("MODEL %s" %model)

    req = SpawnEntity.Request(
        name = "simpleMotor",
        xml = model,
        robot_namespace = "motor",
        reference_frame = "world",
    )

    while not cli.wait_for_service(timeout_sec=1.0):
        node.get_logger().info('service not available, waiting again...')

    future = cli.call_async(req)
    rclpy.spin_until_future_complete(node, future)

    if future.result() is not None:
        node.get_logger().info(
            'Result ' + str(future.result().success) + " " + future.result().status_message)
    else:
        node.get_logger().info('Service call failed %r' % (future.exception(),))

    node.destroy_node()
    rclpy.shutdown()

def generate_launch_description():

    pkg_simulation = get_package_share_directory(package_name)

    robot_description_path =  os.path.join(
        pkg_simulation,
        "urdf",
        "simpleMotor.urdf",
    )

    robot_description = {"robot_description"}


if __name__ == '__main__':
    main()

What am I doing wrong, and how can I fix this so that I can use ros2 nodes to simulate things in Gazebo? Would a .xml launch file be better?

$\endgroup$

1 Answer 1

0
$\begingroup$

Your gazebo.launch.py isn't actually returning anything in generate_launch_description. Remember that in Python that functions will implicitly return None if the function ends without another return statement. So when launching the function in your error is trying to be run on the output of generate_launch_description, however it's None, instead you need to make sure you're returning a valid launch description. Note you'll need to adjust this as needed for your specific use case:

def generate_launch_description():

    pkg_simulation = get_package_share_directory(package_name)

    robot_description_path =  os.path.join(
        pkg_simulation,
        "urdf",
        "simpleMotor.urdf",
    )

    robot_description = {"robot_description": robot_descrption_path}
    return LaunchDescription([robot_description])
$\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.