MAVROS2运行px4.launch文件报错ValueError无法启动的解决方法
- 问题描述
- 解决方法
环境:
Ubuntu :20.04 LTS
ROS :ROS2 Foxy
PX4 :1.13.0
问题描述
在使用命令ros2 launch mavros px4.launch
命令启动MAVROS2与PX4之间的连接时报错,无法启动MAVROS2,报错信息如下。
hccwb@ThinkPad-X1:~$ ros2 launch mavros px4.launch
/opt/ros/foxy/bin/ros2:6: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.htmlfrom pkg_resources import load_entry_point
[INFO] [launch]: All log files can be found below /home/hccwb/.ros/log/2024-04-08-10-33-52-422681-ThinkPad-X1-2141
[INFO] [launch]: Default logging verbosity is set to INFO
Task exception was never retrieved
future: <Task finished name='Task-2' coro=<LaunchService._process_one_event() done, defined at /opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py:226> exception=ValueError('$(var log_output) is not a valid standard output config i.e. "screen", "log" or "both"')>
Traceback (most recent call last):File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py", line 228, in _process_one_eventawait self.__process_event(next_event)File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py", line 248, in __process_eventvisit_all_entities_and_collect_futures(entity, self.__context))File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 45, in visit_all_entities_and_collect_futuresfutures_to_return += visit_all_entities_and_collect_futures(sub_entity, context)File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 45, in visit_all_entities_and_collect_futuresfutures_to_return += visit_all_entities_and_collect_futures(sub_entity, context)File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 45, in visit_all_entities_and_collect_futuresfutures_to_return += visit_all_entities_and_collect_futures(sub_entity, context)[Previous line repeated 3 more times]File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 38, in visit_all_entities_and_collect_futuressub_entities = entity.visit(context)File "/opt/ros/foxy/lib/python3.8/site-packages/launch/action.py", line 108, in visitreturn self.execute(context)File "/opt/ros/foxy/lib/python3.8/site-packages/launch_ros/actions/node.py", line 453, in executeret = super().execute(context)File "/opt/ros/foxy/lib/python3.8/site-packages/launch/actions/execute_process.py", line 826, in executelaunch.logging.get_output_loggers(self.__name, self.__output)File "/opt/ros/foxy/lib/python3.8/site-packages/launch/logging/__init__.py", line 409, in get_output_loggersoutput_config = _normalize_output_configuration(output_config)File "/opt/ros/foxy/lib/python3.8/site-packages/launch/logging/__init__.py", line 339, in _normalize_output_configurationraise ValueError((
ValueError: $(var log_output) is not a valid standard output config i.e. "screen", "log" or "both"
解决方法
分析原因是ROS2 Foxy中MAVROS2的版本问题,Foxy中的MAVROS2 2.4.0版本会有这个问题,但MAVROS2 2.7.0修复了这个问题,所以比较好的解决方案就是自己创建工作空间用MAVROS2 2.7.0搭建环境。
创建ROS2工作空间。
mkdir -p ~/mavros2_ws/src
cd ~/mavros2_ws
下载MAVLink和MAVROS2源码。
source /opt/ros/foxy/setup.bash
rosinstall_generator --format repos mavlink | tee /tmp/mavlink.repos
rosinstall_generator --format repos --upstream mavros | tee -a /tmp/mavros.repos
vcs import src < /tmp/mavlink.repos
vcs import src < /tmp/mavros.repos
rosdep install --from-paths src --ignore-src -y
安装依赖数据集。
sudo ./src/mavros/mavros/scripts/install_geographiclib_datasets.sh
从github官网下载MAVROS2的ros2分支的最新版本代码,替换mavros2_ws/src文件夹中的mavros文件夹。
MAVROS2
编译工作空间。
source ~/mavros2_ws/install/setup.bash
colcon build
新建一个终端,测试MAVROS2能否正常启动。
source /opt/ros/foxy/setup.bash
source ~/mavros2_ws/install/setup.bash
ros2 launch mavros px4.launch
参考资料:
How to use mavros2