天天看點

FileNotFoundError turtlebot3 gazebo dqn models

在調試turtlebot3 machine learning的時候,啟動py的時候出現這個錯誤:

一度以為搞不下去了,結果自己靈機一動,發現原來是路徑的問題,果斷去找根源檔案,turtlebot3_dqn/turtlebot3_dqn/dqn_gazebo/dqn_gazebo.py,在Line 46行,原因是turtlebot3_ws裡面的目錄路徑和py檔案裡面不對應,導緻model.sdf炸不到,原來是:

self.entity_dir_path = self.entity_dir_path.replace(
'turtlebot3_machine_learning/turtlebot3_dqn/turtlebot3_dqn/dqn_gazebo',
'turtlebot3_simulations/turtlebot3_gazebo/models/turtlebot3_dqn_world/goal_box')
           

修改成:

self.entity_dir_path = self.entity_dir_path.replace(
'turtlebot3_machine_learning/turtlebot3_dqn/turtlebot3_dqn/dqn_gazebo',
'turtlebot3/turtlebot3_simulations/turtlebot3_gazebo/models/turtlebot3_dqn_world/goal_box')
           

詳細參見:

https://github.com/shanpenghui/turtlebot3_fixed.git
           

假如出現這個錯誤:

Traceback (most recent call last):
  File "/home/sph/turtlebot3_ws/install/turtlebot3_dqn/lib/turtlebot3_dqn/dqn_gazebo", line 33, in <module>
    sys.exit(load_entry_point('turtlebot3-dqn==2.0.0', 'console_scripts', 'dqn_gazebo')())
  File "/home/sph/turtlebot3_ws/install/turtlebot3_dqn/lib/python3.6/site-packages/turtlebot3_dqn/dqn_gazebo/dqn_gazebo.py", line 158, in main
    dqn_gazebo = DQNGazebo(args)
  File "/home/sph/turtlebot3_ws/install/turtlebot3_dqn/lib/python3.6/site-packages/turtlebot3_dqn/dqn_gazebo/dqn_gazebo.py", line 48, in __init__
    self.entity = open(self.entity_path, 'r').read()
FileNotFoundError: [Errno 2] No such file or directory: '/home/sph/turtlebot3_ws/install/turtlebot3_dqn/lib/python3.6/site-packages/turtlebot3_dqn/dqn_gazebo/model.sdf'
           

原因是編譯的時候隻是複制,相關連結沒配置好,在colcon build的時候添加–symlink-install選項就好,Use symlinks instead of copying files where possible

應該重新用下面指令去編譯:

colcon build --symlink-install
           

繼續閱讀