關於安裝ros和執行tuetlebot3的錯誤

斑码丶發表於2024-04-19

https://blog.csdn.net/qq2650326396/article/details/124801005

安裝ros

wget http://fishros.com/install -O fishros && . fishros

安裝conda

wget https://repo.anaconda.com/archive/Anaconda3-2021.11-Linux-x86_64.sh
bash Anaconda3-2021.11-Linux-x86_64.sh

安裝vim 更新源

apt-get update
apt install vim

關於報錯 這裡是找不到對應的安裝包 但是其已經有了pytorch1.0 在py2.yaml中刪掉無法定位的包就可以了

(base) root@f281de310469:~/turtlebot3_DQN# conda env create -f py2.yaml
Collecting package metadata (repodata.json): done
Solving environment: failed

ResolvePackageNotFound:

  • pytorch==1.4.0=py2.7_cpu_0
  • torchaudio==0.4.0=py27
  • torchvision==0.5.0=py27_cpu

在安裝好的環境下 安裝torch

pip install torch1.4.0 torchvision0.5.0

報錯

CMake Error at /opt/ros/melodic/share/catkin/cmake/test/gtest.cmake:180 (add_executable):
add_executable cannot create target "test_transform_datatypes" because
another target with the same name already exists. The existing target is
an executable created in source directory
"/root/catkin_ws/src/geometry2/tf2". See documentation for policy CMP0002
for more details.

解決辦法

cd /root/catkin_ws/src/geometry2/tf2
vim CMakeLists.txt
重新命名 53-55行

報錯

ImportError: "from catkin_pkg.package import parse_package" failed: No module named 'catkin_pkg'
Make sure that you have installed "catkin_pkg", it is up to date and on the PYTHONPATH.
CMake Error at /opt/ros/melodic/share/catkin/cmake/safe_execute_process.cmake:11 (message):
execute_process(/usr/bin/python3
"/opt/ros/melodic/share/catkin/cmake/parse_package_xml.py"
"/opt/ros/melodic/share/catkin/cmake/../package.xml"
"/root/catkin_ws/build/catkin/catkin_generated/version/package.cmake")
returned error code 1

解決辦法 連結的路徑不對

echo $PYTHONPATH 檢視當前連結的路徑
which python3 檢視python3路徑
catkin_make -DPYTHON_EXECUTABLE=/root/anaconda3/bin/python3 由於import需要使用python3 連結到python3路徑即可

報錯

AttributeError: module 'em' has no attribute 'RAW_OPT'

解決辦法 版本太高 降版本

pip install empy==3.3.4

建立工作空間

mkdir -p catkin_ws/src
cd catkin_ws/src
git clone https://gitclone.com/github.com/ros/geometry.git
git clone https://gitclone.com/github.com/ros/geometry2.git
git clone https://gitee.com/fangxiaosheng666/PPO-SAC-DQN-DDPG
cd ..
catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python3

建立工作空間

mkdir -p ws/src
cd ws/src
git clone https://gitclone.com/github.com/ROBOTIS-GIT/turtlebot3.git
git clone https://gitclone.com/github.com/ROBOTIS-GIT/turtlebot3_simulations.git
git clone https://gitclone.com/github.com/ROBOTIS-GIT/turtlebot3_msgs.git
cd ..
source /opt/ros/melodic/setup.bash
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
catkin_make

執行gazebo模擬環境 機器人的環境

source ~/ws/devel/setup.bash
export TURTLEBOT3_MODEL=burger
roslaunch turtlebot3_gazebo turtlebot3_stage_2.launch

工作空間的程式 使用的是python3

source ~/catkin_ws/devel/setup.bash
python3 PPO.py

執行dqn 使用的是python2 不能在環境變數中用python3 會產生混用的錯誤

export TURTLEBOT3_MODEL=burger
conda activate py2
cd ~/turtlebot3_DQN/DQN
python DQN2.py

export TURTLEBOT3_MODEL=burger
roslaunch turtlebot3_fake turtlebot3_fake.launch #rviz模擬
roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch #控制節點

roslaunch turtlebot3_gazebo turtlebot3_world.launch

相關網址

https://zhuanlan.zhihu.com/p/265184095

rviz

http://www.autolabor.com.cn/book/ROSTutorials/di-6-zhang-ji-qi-ren-xi-tong-fang-zhen/62-fang-zhen-urdf-ji-cheng-rviz.html

相關文章