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

foxy can't launch gazebo11 model and report SyntaxError.

asked 2022-04-26 21:08:43 -0500

zhangys gravatar image

updated 2022-04-30 13:16:27 -0500

lucasw gravatar image

hello, I'm trying to use the foxy to launch the simulation environment(gazebo11) on the ubuntu20.04,but can not load the robot model and report an error. The error is as follows:

 [spawn_entity.py-4] Traceback (most recent call last):
[spawn_entity.py-4]   File "/opt/ros/foxy/lib/gazebo_ros/spawn_entity.py", line 27, in <module>
[spawn_entity.py-4]     from gazebo_msgs.msg import ModelStates
[spawn_entity.py-4]   File "/opt/ros/foxy/lib/python3.8/site-packages/gazebo_msgs/msg/__init__.py", line 1, in <module>
[spawn_entity.py-4]     from gazebo_msgs.msg._contact_state import ContactState  # noqa: F401
[spawn_entity.py-4]   File "/opt/ros/foxy/lib/python3.8/site-packages/gazebo_msgs/msg/_contact_state.py", line 11, in <module>
[spawn_entity.py-4]     import rosidl_parser.definition  # noqa: E402, I100
[spawn_entity.py-4]   File "/opt/ros/foxy/lib/python3.8/site-packages/rosidl_parser/definition.py", line 426
[spawn_entity.py-4]     raise ValueError(f"No '{name}' annotation")
[spawn_entity.py-4]                                              ^
[spawn_entity.py-4] SyntaxError: invalid syntax
[ERROR] [spawn_entity.py-4]: process has died [pid 4442, exit code 1, cmd '/opt/ros/foxy/lib/gazebo_ros/spawn_entity.py --ros-args -r __node:=urdf_spawner'].

I want to use String.format(name) solve the problem,but it will report more error。such as :

[spawn_entity.py-4]     import rclpy
[spawn_entity.py-4]   File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/__init__.py", line 50, in <module>
[spawn_entity.py-4]     from rclpy.utilities import get_default_context
[spawn_entity.py-4]   File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/utilities.py", line 98
[spawn_entity.py-4]     f'The RMW implementations {missing_rmw_implementations}

and

[spawn_entity.py-4]     from rclpy.node import Node
[spawn_entity.py-4]   File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/node.py'',line 146
[spawn_entity.py-4]     self.__subcriptions: List[Subcription]=[]
[spawn_entity.py-4]     SyntaxError: invalid syntax

my laucnh file code:


import os

from ament_index_python.packages import get_package_share_directory

from launch import LaunchDescription

from launch.actions import DeclareLaunchArgument, ExecuteProcess,IncludeLaunchDescription

from launch.substitutions import LaunchConfiguration

from launch_ros.actions import Node

from launch.launch_description_sources import PythonLaunchDescriptionSource

from launch_ros.substitutions import FindPackageShare

def generate_launch_description():

  use_sim_time = LaunchConfiguration('use_sim_time', default='false')

  urdf_file_name = '/home/zys/ros2_prj/AGV_SIM_WS/src/urdf_tutorial_r2d2/urdf/agv_car.urdf'

  package_name = 'urdf_tutorial_r2d2'

  pkg_gazebo_ros = get_package_share_directory('gazebo_ros')

  print("urdf_file_name : {}".format(urdf_file_name))

  urdf = os.path.join(
      get_package_share_directory('urdf_tutorial_r2d2'),
      urdf_file_name)

  with open(urdf, 'r') as infp:
        robot_desc = infp.read()

  return LaunchDescription([

        DeclareLaunchArgument(
            'use_sim_time',
            default_value='false',
            description='Use simulation (Gazebo) clock if true'),

        ExecuteProcess(
            # cmd=['gazebo', '--verbose', '-s', 'libgazebo_ros_factory.so'],
            cmd=['gazebo', '--verbose', '/home/zys/ros2_prj/AGV_SIM_WS/src/urdf_tutorial_r2d2/sim_world/box_house.world'],
            output='screen'),

        Node(
            package='robot_state_publisher',
            executable='robot_state_publisher',
            name='robot_state_publisher',
            output='screen',
            parameters=[{'use_sim_time': use_sim_time,'robot_description': robot_desc}],
            arguments=[urdf]),

        Node(
            package='joint_state_publisher',
            executable='joint_state_publisher',
            name='joint_state_publisher',
            parameters=[{'use_sim_time': use_sim_time, 'robot_description': robot_desc}],
            output='screen',
            ),

        Node(
            package='gazebo_ros',
            executable='spawn_entity.py',
            name='urdf_spawner',
            output='screen',
            # arguments=["-topic", "/robot_description", "-entity", -f"AGV_CAR"])
            # arguments=['-entity',
            #        'mobot',
            #        '-x', '3.5', '-y', '1.0', '-z', '0.1',
            #        '-file', urdf
            #          ]

            )
  ])

my running enviroment:


Linux ubuntu20.04

gazebo11

ROS_VERSION=2

ROS_PYTHON_VERSION=3

ROS_LOCALHOST_ONLY=0

ROS_DISTRO=foxy

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2022-04-28 03:58:08 -0500

Joe28965 gravatar image

raise ValueError(f"No '{name}' annotation")

I think the gazebo_ros spawn_entity.py wants a name. You have a name in there, which you commented out. It uses -entity to request a name.

However, you have it in there twice. first as "-entity", -f"AGV_CAR" which I am not quite sure how to interpret that.

And second

    # arguments=['-entity',
    #        'mobot',

Which would spawn a robot called mobot.

I'm not sure why you commented those lines out? I don't think spawn_entity uses -file anymore. It used to be possible to use -file to give the URDF file, but it has switched to using a topic (for instance robot_description as you have used, but you might want to remove the /).

I hope this helps, otherwise drop a comment.

edit flag offensive delete link more

Comments

Thanks,you are right ! My launch file's arguments have some error,but I had modified.but it still gives an error.Fortunately,The reason I found this error is because I installed conda virtual environment.

zhangys gravatar image zhangys  ( 2022-04-28 10:48:28 -0500 )edit

Glad to help, do I understand correctly that you still have an error in your launch file?

Joe28965 gravatar image Joe28965  ( 2022-04-29 01:29:20 -0500 )edit

oh,no, The erro had be updated.There has no error in may launch file now!

zhangys gravatar image zhangys  ( 2022-04-29 04:17:11 -0500 )edit

Question Tools

Stats

Asked: 2022-04-26 21:08:43 -0500

Seen: 306 times

Last updated: Apr 30 '22