ROS中给turtlebot加hokuyo传感器,roslaunch报错Traceback (most recent call last)

ROS中给turtlebot加hokuyo传感器,roslaunch报错 Traceback (most recent call last):

按照该教程配置的各文件ROS中给turtlebot加两个传感器:kinect+hokuyo,进行gazebo仿真(二)

运行roslaunch turtlebot_gazebo turtlebot_word1.launch

错误信息如下

dhh@dhh-HP:~/catkin_ws$ roslaunch turtlebot_gazebo turtlebot_word1.launch 
... logging to /home/dhh/.ros/log/e6c7d2f4-5f5d-11e9-832b-7429afe196bb/roslaunch-dhh-HP-17477.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

Traceback (most recent call last):
  File "/opt/ros/kinetic/lib/xacro/xacro", line 33, in <module>
    xacro.main()
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/xacro/__init__.py", line 1073, in main
    out.write(doc.toprettyxml(indent='  '))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 9574-9575: ordinal not in range(128)
while processing /home/dhh/catkin_ws/src/turtlebot_simulator/turtlebot_gazebo/launch/includes/kobuki.launch.xml:
Invalid <param> tag: Cannot load command parameter [robot_description]: command [/opt/ros/kinetic/lib/xacro/xacro --inorder '/home/dhh/catkin_ws/src/turtlebot/turtlebot_description/robots/kobuki_hexagons_hokuyo.urdf.xacro'] returned with code [1]. 

Param xml is <param command="$(arg urdf_file)" name="robot_description"/>
The traceback for the exception was written to the log file

解决方法(修改Python本环境永久有效)

在Python的Lib\site-packages文件夹下新建一个sitecustomize.py文件,
路径为:/home/dhh/catkin_ws/devel/lib/python2.7/dist-packages
内容为:

#coding=utf8

import sys

reload(sys)

sys.setdefaultencoding('utf8')

再次运行roslaunch turtlebot_gazebo turtlebot_word1.launch会多出一个sitecumstomize.pyc文件,不用管。
ROS中给turtlebot加hokuyo传感器,roslaunch报错Traceback (most recent call last)_第1张图片
重启Python解释器,发现编码已被设置为utf8,系统在Python启动的时候,自行调用该文件,设置系统的默认编码,而不需要每次都手动加上解决代码,属于一劳永逸的解决方法。

解決方法來自
UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position xxx ordinal

你可能感兴趣的:(ROS中给turtlebot加hokuyo传感器,roslaunch报错Traceback (most recent call last))