ROS2 Rolling下无法使用YDLidar X4的问题求助
一、ROS2启动驱动节点崩溃问题
报错信息
[INFO] [launch]: All log files can be found below /home/ohmin/.ros/log/2023-02-27-02-37-46-155449-ohmin-13510 [INFO] [launch]: Default logging verbosity is set to INFO [INFO] [ydlidar_ros2_driver_node-1]: process started with pid [13511] [INFO] [static_transform_publisher-2]: process started with pid [13513] [static_transform_publisher-2] [WARN] [1677433066.231842522] []: Old-style arguments are deprecated; see --help for new-style arguments [ydlidar_ros2_driver_node-1] [INFO] [1677433066.236957516] [ydlidar_ros2_driver_node]: [YDLIDAR INFO] Current ROS Driver Version: 1.0.1 [ydlidar_ros2_driver_node-1] terminate called after throwing an instance of 'rclcpp::exceptions::UninitializedStaticallyTypedParameterException' [ydlidar_ros2_driver_node-1] what(): Statically typed parameter 'fixed_resolution' must be initialized. [static_transform_publisher-2] [INFO] [1677433066.238474174] [static_tf_pub_laser]: Spinning until stopped - publishing transform [static_transform_publisher-2] translation: ('0.000000', '0.000000', '0.020000') [static_transform_publisher-2] rotation: ('0.000000', '0.000000', '0.000000', '1.000000') [static_transform_publisher-2] from 'base_link' to 'laser_frame' [ERROR] [ydlidar_ros2_driver_node-1]: process has died [pid 13511, exit code -6, cmd '/home/ohmin/ydlidar_ros2_ws/install/ydlidar_ros2_driver/lib/ydlidar_ros2_driver/ydlidar_ros2_driver_node --ros-args -r __node:=ydlidar_ros2_driver_node --params-file /home/ohmin/ydlidar_ros2_ws/install/ydlidar_ros2_driver/share/ydlidar_ros2_driver/params/ydlidar.yaml'].
解决方法
修正参数名错误
报错明确指出fixed_resolution参数未初始化,但你的ydlidar.yaml里写的是resolution_fixed: true,参数名拼写颠倒了。修改yaml文件,将resolution_fixed改为fixed_resolution:ydlidar_ros2_driver_node: ros__parameters: port: /dev/ttyUSB0 frame_id: laser_frame ignore_array: "" baudrate: 128000 lidar_type: 1 device_type: 0 sample_rate: 5 abnormal_check_count: 4 fixed_resolution: true # 原参数名resolution_fixed改为fixed_resolution reversion: true inverted: true auto_reconnect: true isSingleChannel: false intensity: false support_motor_dtr: false angle_max: 180.0 angle_min: -180.0 range_max: 10 range_min: 0.12 frequency: 10.0 invalid_range_is_inf: false修改后重新编译并安装包:
cd ~/ydlidar_ros2_ws colcon build --packages-select ydlidar_ros2_driver source install/setup.bash消除static_transform_publisher警告(可选)
警告提示旧版参数格式已废弃,可将launch文件中的static_transform_publisher参数改为新版格式:
将原来的arguments列表替换为:arguments=['--x', '0', '--y', '0', '--z', '0.02', '--qx', '0', '--qy', '0', '--qz', '0', '--qw', '1', '--frame-id', 'base_link', '--child-frame-id', 'laser_frame']
二、YDLidar-SDK tri_test报错"Device Tremble"问题
报错信息
0. ydlidar 1. ydlidar3 Please select the lidar port:1 Baudrate: 0. 115200 1. 128000 2. 150000 3. 153600 4. 230400 5. 460800 6. 512000 Please select the lidar baudrate:1 Whether the Lidar is one-way communication[yes/no]:yes [YDLIDAR] SDK initializing [YDLIDAR] SDK has been initialized [YDLIDAR] SDK Version: 1.1.4 [YDLIDAR] Lidar successfully connected [YDLIDAR] Lidar running correctly! The health status: good [YDLIDAR] Lidar init success, Elapsed time 624 ms [YDLIDAR] Start to getting intensity flag [YDLIDAR] Auto set intensity 0 [YDLIDAR] End to getting intensity flag [YDLIDAR] Create thread 0x265FF640 [YDLIDAR] Successed to start scan mode, Elapsed time 1174 ms timeout count: 1 timeout count: 2 timeout count: 1 0x265FF640 thread has been canceled [YDLIDAR] Failed to turn on the Lidar, because the lidar is [Device Tremble]. Fail to start Unknown error
解决方法
由于plot_tof_test.py运行正常,说明雷达机械结构无故障,问题出在测试程序配置或硬件连接上:
统一单通道配置
你在tri_test中选择了单通道通信(yes),但yaml里isSingleChannel: false,两者不一致。将yaml中的isSingleChannel改为true,或者在tri_test中选择no(如果雷达是双通道)。检查串口权限
尝试用sudo运行tri_test,避免串口权限不足:sudo ./tri_test也可以添加udev规则永久解决权限问题:
创建文件/etc/udev/rules.d/ydlidar.rules,写入:SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", MODE:="0666", GROUP:="dialout"然后重启udev服务:
sudo udevadm control --reload-rules && sudo udevadm trigger排查供电问题
YDLidar X4需要稳定的5V/1A供电,USB供电不足可能导致电机抖动检测误判。尝试使用带外接电源的USB hub,或直接连接到电脑主板的USB端口(避免使用前置USB)。调整异常检测阈值
在yaml中调大abnormal_check_count参数(比如改为8),降低异常检测的敏感度:abnormal_check_count: 8
内容的提问来源于stack exchange,提问作者the DEV

