紧急通知:禁止一切关于政治&VPN翻墙等话题,发现相关帖子会立马删除封号
小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
move_group.launch文件启动时出现load_yaml()报错
-
我在调用一个从网上下载的包时,出现如下问题:
pan@pan-System-Product-Name:~/moveit_test$ ros2 launch panda_moveit_config ex_fake_control.launch.py [INFO] [launch]: All log files can be found below /home/pan/.ros/log/2022-11-23-17-28-54-850085-pan-System-Product-Name-17014 [INFO] [launch]: Default logging verbosity is set to INFO [ERROR] [launch]: Caught exception in launch (see debug for traceback): executed command showed stderr output. Command: /opt/ros/humble/bin/xacro /home/pan/moveit_test/install/panda_description/share/panda_description/urdf/panda.urdf.xacro name:=panda prefix:=panda_ gripper:=true collision_arm:=true collision_gripper:=true safety_limits:=true safety_position_margin:=0.15 safety_k_position:=100.0 safety_k_velocity:=40.0 ros2_control:=true ros2_control_plugin:=fake ros2_control_command_interface:=position gazebo_preserve_fixed_joint:=false Captured stderr output: warning: Using load_yaml() directly is deprecated. Use xacro.load_yaml() instead. warning: Using load_yaml() directly is deprecated. Use xacro.load_yaml() instead.
在翻看源码时,定位到load_yaml,作者使用的是yaml.safe_load(file) 方法,仔细阅读了源码没有查到具体问题出现在哪,所以想请大家帮忙。
源码如下:#!/usr/bin/env -S ros2 launch """Configure and setup move group for planning with MoveIt 2""" from os import path from typing import List import yaml from ament_index_python.packages import get_package_share_directory from launch import LaunchDescription from launch.actions import DeclareLaunchArgument from launch.conditions import IfCondition from launch.substitutions import ( Command, FindExecutable, LaunchConfiguration, PathJoinSubstitution, PythonExpression, ) from launch_ros.actions import Node from launch_ros.substitutions import FindPackageShare def generate_launch_description(): # Declare all launch arguments declared_arguments = generate_declared_arguments() # Get substitution for all arguments #description_package = LaunchConfiguration("description_package") #description_filepath = LaunchConfiguration("description_filepath") moveit_config_package = "panda_moveit_config" name = LaunchConfiguration("name") prefix = LaunchConfiguration("prefix") gripper = LaunchConfiguration("gripper") collision_arm = LaunchConfiguration("collision_arm") collision_gripper = LaunchConfiguration("collision_gripper") safety_limits = LaunchConfiguration("safety_limits") safety_position_margin = LaunchConfiguration("safety_position_margin") safety_k_position = LaunchConfiguration("safety_k_position") safety_k_velocity = LaunchConfiguration("safety_k_velocity") ros2_control = LaunchConfiguration("ros2_control") ros2_control_plugin = LaunchConfiguration("ros2_control_plugin") ros2_control_command_interface = LaunchConfiguration( "ros2_control_command_interface" ) gazebo_preserve_fixed_joint = LaunchConfiguration("gazebo_preserve_fixed_joint") enable_servo = LaunchConfiguration("enable_servo") enable_rviz = LaunchConfiguration("enable_rviz") rviz_config = LaunchConfiguration("rviz_config") use_sim_time = LaunchConfiguration("use_sim_time") log_level = LaunchConfiguration("log_level") # URDF _robot_description_xml = Command( [ PathJoinSubstitution([FindExecutable(name="xacro")]), " ", PathJoinSubstitution( [FindPackageShare("panda_description"), "urdf","panda.urdf.xacro",] ), " ", "name:=", name, " ", "prefix:=", prefix, " ", "gripper:=", gripper, " ", "collision_arm:=", collision_arm, " ", "collision_gripper:=", collision_gripper, " ", "safety_limits:=", safety_limits, " ", "safety_position_margin:=", safety_position_margin, " ", "safety_k_position:=", safety_k_position, " ", "safety_k_velocity:=", safety_k_velocity, " ", "ros2_control:=", ros2_control, " ", "ros2_control_plugin:=", ros2_control_plugin, " ", "ros2_control_command_interface:=", ros2_control_command_interface, " ", "gazebo_preserve_fixed_joint:=", gazebo_preserve_fixed_joint, ] ) robot_description = {"robot_description": _robot_description_xml} # SRDF _robot_description_semantic_xml = Command( [ PathJoinSubstitution([FindExecutable(name="xacro")]), " ", PathJoinSubstitution( [ FindPackageShare(moveit_config_package), "srdf", "panda.srdf.xacro", ] ), " ", "name:=", name, " ", "prefix:=", prefix, ] ) robot_description_semantic = { "robot_description_semantic": _robot_description_semantic_xml } # Kinematics kinematics = load_yaml( moveit_config_package, path.join("config", "kinematics.yaml") ) # Joint limits joint_limits = { "robot_description_planning": load_yaml( moveit_config_package, path.join("config", "joint_limits.yaml") ) } # Servo servo_params = { "moveit_servo": load_yaml( moveit_config_package, path.join("config", "servo.yaml") ) } servo_params["moveit_servo"].update({"use_gazebo": use_sim_time}) # Planning pipeline planning_pipeline = { "planning_pipelines": ["ompl"], "default_planning_pipeline": "ompl", "ompl": { "planning_plugin": "ompl_interface/OMPLPlanner", # TODO: Re-enable `default_planner_request_adapters/AddRuckigTrajectorySmoothing` once its issues are resolved "request_adapters": "default_planner_request_adapters/AddTimeOptimalParameterization default_planner_request_adapters/ResolveConstraintFrames default_planner_request_adapters/FixWorkspaceBounds default_planner_request_adapters/FixStartStateBounds default_planner_request_adapters/FixStartStateCollision default_planner_request_adapters/FixStartStatePathConstraints", # TODO: Reduce start_state_max_bounds_error once spawning with specific joint configuration is enabled "start_state_max_bounds_error": 0.31416, } } _ompl_yaml = load_yaml( moveit_config_package, path.join("config", "ompl_planning.yaml") ) planning_pipeline["ompl"].update(_ompl_yaml) # Planning scene planning_scene_monitor_parameters = { "publish_planning_scene": True, "publish_geometry_updates": True, "publish_state_updates": True, "publish_transforms_updates": True, } # MoveIt controller manager moveit_controller_manager_yaml = load_yaml( moveit_config_package, path.join("config", "moveit_controller_manager.yaml") ) moveit_controller_manager = { "moveit_controller_manager": "moveit_simple_controller_manager/MoveItSimpleControllerManager", "moveit_simple_controller_manager": moveit_controller_manager_yaml, } # Trajectory execution trajectory_execution = { "allow_trajectory_execution": True, "moveit_manage_controllers": False, "trajectory_execution.allowed_execution_duration_scaling": 1.2, "trajectory_execution.allowed_goal_duration_margin": 0.5, "trajectory_execution.allowed_start_tolerance": 0.01, } # Controller parameters declared_arguments.append( DeclareLaunchArgument( "__controller_parameters_basename", default_value=["controllers_", ros2_control_command_interface, ".yaml"], ) ) controller_parameters = PathJoinSubstitution( [ FindPackageShare(moveit_config_package), "config", LaunchConfiguration("__controller_parameters_basename"), ] ) # List of nodes to be launched nodes = [ # robot_state_publisher Node( package="robot_state_publisher", executable="robot_state_publisher", output="log", arguments=["--ros-args", "--log-level", log_level], parameters=[ robot_description, { "publish_frequency": 50.0, "frame_prefix": "", "use_sim_time": use_sim_time, }, ], ), # ros2_control_node (only for fake controller) Node( package="controller_manager", executable="ros2_control_node", output="log", arguments=["--ros-args", "--log-level", log_level], parameters=[ robot_description, controller_parameters, {"use_sim_time": use_sim_time}, ], condition=( IfCondition( PythonExpression( [ "'", ros2_control_plugin, "'", " == ", "'fake'", ] ) ) ), ), # move_group (with execution) Node( package="moveit_ros_move_group", executable="move_group", output="log", arguments=["--ros-args", "--log-level", log_level], parameters=[ robot_description, robot_description_semantic, kinematics, joint_limits, planning_pipeline, trajectory_execution, planning_scene_monitor_parameters, moveit_controller_manager, {"use_sim_time": use_sim_time}, ], ), # move_servo Node( package="moveit_servo", executable="servo_node_main", output="log", arguments=["--ros-args", "--log-level", log_level], parameters=[ robot_description, robot_description_semantic, kinematics, joint_limits, planning_pipeline, trajectory_execution, planning_scene_monitor_parameters, servo_params, {"use_sim_time": use_sim_time}, ], condition=IfCondition(enable_servo), ), # rviz2 Node( package="rviz2", executable="rviz2", output="log", arguments=[ "--display-config", rviz_config, "--ros-args", "--log-level", log_level, ], parameters=[ robot_description, robot_description_semantic, kinematics, planning_pipeline, joint_limits, {"use_sim_time": use_sim_time}, ], condition=IfCondition(enable_rviz), ), ] # Add nodes for loading controllers for controller in moveit_controller_manager_yaml["controller_names"] + [ "joint_state_broadcaster" ]: nodes.append( # controller_manager_spawner Node( package="controller_manager", executable="spawner", output="log", arguments=[controller, "--ros-args", "--log-level", log_level], parameters=[{"use_sim_time": use_sim_time}], ), ) return LaunchDescription(declared_arguments + nodes) def load_yaml(package_name: str, file_path: str): """ Load yaml configuration based on package name and file path relative to its share. """ package_path = get_package_share_directory(package_name) absolute_file_path = path.join(package_path, file_path) return parse_yaml(absolute_file_path) def parse_yaml(absolute_file_path: str): """ Parse yaml from file, given its absolute file path. """ try: with open(absolute_file_path, "r") as file: return yaml.safe_load(file) except EnvironmentError: return None def generate_declared_arguments() -> List[DeclareLaunchArgument]: """ Generate list of all launch arguments that are declared for this launch script. """ return [ # Locations of robot resources DeclareLaunchArgument( "description_package", default_value="panda_description", description="Custom package with robot description.", ), DeclareLaunchArgument( "description_filepath", default_value=path.join("urdf", "panda.urdf.xacro"), description="Path to xacro or URDF description of the robot, relative to share of `description_package`.", ), # Naming of the robot DeclareLaunchArgument( "name", default_value="panda", description="Name of the robot.", ), DeclareLaunchArgument( "prefix", default_value="panda_", description="Prefix for all robot entities. If modified, then joint names in the configuration of controllers must also be updated.", ), # Gripper DeclareLaunchArgument( "gripper", default_value="true", description="Flag to enable default gripper.", ), # Collision geometry DeclareLaunchArgument( "collision_arm", default_value="true", description="Flag to enable collision geometry for manipulator's arm.", ), DeclareLaunchArgument( "collision_gripper", default_value="true", description="Flag to enable collision geometry for manipulator's gripper (hand and fingers).", ), # Safety controller DeclareLaunchArgument( "safety_limits", default_value="true", description="Flag to enable safety limits controllers on manipulator joints.", ), DeclareLaunchArgument( "safety_position_margin", default_value="0.15", description="Lower and upper margin for position limits of all safety controllers.", ), DeclareLaunchArgument( "safety_k_position", default_value="100.0", description="Parametric k-position factor of all safety controllers.", ), DeclareLaunchArgument( "safety_k_velocity", default_value="40.0", description="Parametric k-velocity factor of all safety controllers.", ), # ROS 2 control DeclareLaunchArgument( "ros2_control", default_value="true", description="Flag to enable ros2 controllers for manipulator.", ), DeclareLaunchArgument( "ros2_control_plugin", default_value="ign", description="The ros2_control plugin that should be loaded for the manipulator ('fake', 'ign', 'real' or custom).", ), DeclareLaunchArgument( "ros2_control_command_interface", default_value="effort", description="The output control command interface provided by ros2_control ('position', 'velocity', 'effort' or certain combinations 'position,velocity').", ), # Gazebo DeclareLaunchArgument( "gazebo_preserve_fixed_joint", default_value="false", description="Flag to preserve fixed joints and prevent lumping when generating SDF for Gazebo.", ), # Servo DeclareLaunchArgument( "enable_servo", default_value="true", description="Flag to enable MoveIt2 Servo for manipulator.", ), # Miscellaneous DeclareLaunchArgument( "enable_rviz", default_value="true", description="Flag to enable RViz2." ), DeclareLaunchArgument( "rviz_config", default_value=path.join( get_package_share_directory("panda_moveit_config"), "rviz", "moveit.rviz", ), description="Path to configuration for RViz2.", ), DeclareLaunchArgument( "use_sim_time", default_value="false", description="If true, use simulated clock.", ), DeclareLaunchArgument( "log_level", default_value="warn", description="The level of logging that is applied to all ROS 2 nodes launched by this script.", ), ]
重点涉及到load_yaml部分为
def load_yaml(package_name: str, file_path: str): """ Load yaml configuration based on package name and file path relative to its share. """ package_path = get_package_share_directory(package_name) absolute_file_path = path.join(package_path, file_path) return parse_yaml(absolute_file_path) def parse_yaml(absolute_file_path: str): """ Parse yaml from file, given its absolute file path. """ try: with open(absolute_file_path, "r") as file: return yaml.safe_load(file) except EnvironmentError: return None
不知是这个用法不行,还是配置的launch文件有问题?
-
@空白 直接替换一个load_yaml函数行不?
-
@空白 我看了一下我用的ros2包
def load_yaml(package_name, *file_path): package_path = get_package_share_directory(package_name) absolute_file_path = os.path.join(package_path, *file_path) if not os.path.exists(absolute_file_path): return {} try: with open(absolute_file_path, 'r') as file: return yaml.safe_load(file) except EnvironmentError: # parent of IOError, OSError *and* WindowsError where available return {} except: return {}
不过也用到了
yaml.safe_load(file)
,这样能加载到配置文件 -
@Lorry 好的,谢谢,我试试吧。感觉本质上应该没有问题的,我查了下这个yaml的库也可以这样用,所以我有点怀疑是不是有别的地方没有配置好
-
@Lorry 解决问题了,不是这个源码上面load_yaml的问题,是我下载的功能包里面一个在panda.ros2_contral的配置中对于xacro的描述里面出现了load_yaml,将其改为xacro.load_yaml即可,这是在humble上面新出现的问题(特性),之前的功能包适用于galactic,所以没意识到,谢谢了
-
-
@空白 能解决就好