建议采用清华的源,如果采用阿里的源后面很多依赖会报错,换源之后记得更新,建议勾选源代码
sudo apt-get update
解决:
sudo apt-get install --reinstall libappstream4
sudo apt-get update
sudo apt-get install git
sudo apt-get install g++
sudo apt-get install gcc
我是自己去官网下载的3.22.1版本cmake,如果是sudo apt-get install cmake版本较低
//方法一
sudo apt-get install cmake
//方法二
sudo apt-get install build-essential
tar -zxvf cmake-3.22.1.tar.gz
cd cmake-3.22.1/
./bootstrap
Could not find OpenSSL.
解决:
sudo apt-get install libssl-dev
j8代表八个线程同时运行,可以加快速度,根据创建虚拟机设定自行更改
make -j8
sudo make install
cmake --version
cmake安装完成!
sudo apt-get install libglew-dev
sudo apt-get install cmake
sudo apt-get install libboost-dev libboost-thread-dev libboost-filesystem-dev
cd Pangolin
mkdir build
cd build
cmake ..
make -j8
sudo make install
cd /examples/HelloPangolin
mkdir build
cd build
cmake ..
make
./HelloPangolin
出现小方块表示安装成功!
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
解决办法:
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt-get update
sudo apt-get install libjasper-dev
我选择的是open3.4.15版本,可以去官网下载
cd opencv-3.4.15/
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j8
sudo make install
将opencv的库添加到路径
sudo gedit /etc/ld.so.conf.d/opencv.conf
在文件中加入
/usr/local/lib
//保存后退出,运行下行代码使环境生效
sudo ldconfig
配置bash
sudo gedit /etc/bash.bashrc
// 在文件末尾加入下面代码
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
保存退出,执行命令使得配置生效:
source /etc/bash.bashrc
cd opencv-3.4.15/samples/cpp/example_cmake/
mkdir build
cd build
cmake ..
make
./opencv_example
出现如下图,安装成功
cd eigen-3.3.7/
mkdir build
cd build
cmake ..
sudo make install
//移动头文件
sudo cp -r /usr/local/include/eigen3/Eigen /usr/local/include
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.ustc.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
sudo apt-get update
sudo apt install ros-melodic-desktop-full
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
4.3.2安装其他工具
sudo apt install python-rosdep
sudo apt install python-rosinstall
sudo apt install python-rosinstall-generator
sudo apt install python-wstool
sudo apt install build-essential
sudo gedit /etc/hosts
输入185.199.108.133 raw.githubusercontent.com
保存退出
终端输入rosdep init,建议这一步执行的时候用手机热点
sudo rosdep init
如果直接执行 rosdep update,大概率是失败的。
方法:
git clone https://github.com/ros/rosdistro.git
1.将下载的包改名为rosdistro
2.
找到rosdistro,我的文件就在/home/dxf/rosdistro,将下载的文件复制到系统文件/etc/ros。
sudo cp -r /home/xxx/rosdistro /etc/ros
// "xxx"改成你自己的地址,我的就是sudo cp -r /home/dxf/rosdistro /etc/ros
(1)修改/usr/lib/python2.7/dist-packages/rosdep2/rep3.py
文件
cd /usr/lib/python2.7/dist-packages/rosdep2
sudo gedit rep3.py
将REP3_TARGETS_URL = ‘https://raw.githubusercontent.com/ros/rosdistro/master/releases/targets.yaml’ 替换成 REP3_TARGETS_URL = 'file:///etc/ros/rosdistro/releases/targets.yaml'
(2)修改/usr/lib/python2.7/dist-packages/rosdistro/__init__.py
文件
cd /usr/lib/python2.7/dist-packages/rosdistro
sudo gedit __init__.py
将原来文件中的 DEFAULT_INDEX_URL = ‘https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml’ 替换成 DEFAULT_INDEX_URL = 'file:///etc/ros/rosdistro/index-v4.yaml'
(3)配置20-default.list
文件
sudo gedit /etc/ros/rosdep/sources.list.d/20-default.list
修改其中内容,全部删掉后改用以下内容
# os-specific listings first
yaml file:///etc/ros/rosdistro/rosdep/osx-homebrew.yaml osx
# generic
yaml file:///etc/ros/rosdistro/rosdep/base.yaml
yaml file:///etc/ros/rosdistro/rosdep/python.yaml
yaml file:///etc/ros/rosdistro/rosdep/ruby.yaml
gbpdistro file:///etc/ros/rosdistro/releases/fuerte.yaml fuerte
# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead
3.执行命令:
rosdep update
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
第一次启动ROS时,需要进行环境变量配置,执行如下命令
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
1.打开一个终端运行:
roscore
2.打开第二个终端运行:
rosrun turtlesim turtlesim_node
3.打开三个终端运行:
rosrun turtlesim turtle_teleop_key
用上下左右键,可以控制小乌龟移动。
mkdir -p ~/catkin_ws/src //创建文件目录
cd ~/catkin_ws/src //进入src
catkin_init_workspace //初始化文件夹
这样就在src文件中创建了一个 CMakeLists.txt 的文件,目的是告诉系统,这个是ROS的工作空间。
cd ~/catkin_ws/
catkin_make
编译完成后,会发现catkin_ws中多了两个文件 build 和 devel
echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc
source ~/.bashrc
查看环境变量
echo $ROS_PACKAGE_PATH
第一个是我们刚才创建的catkin_ws的,第二个是ros系统的。
catkin_create_pkg learning_communication std_msgs roscpp rospy
std_msgs:包含常见消息类型
roscpp:使用C++实现ROS各种功能
rospy:使用python实现ROS各种功能
cd ~/catkin_ws
catkin_make
进入catkin_ws/src文件下,执行下面命令
git clone https://github.com/raulmur/ORB_SLAM2.git ORB_SLAM2
cd ORB_SLAM2
chmod +x build.sh
./build.sh
报错:error: ‘usleep’ was not declared in this scope usleep(5000);
解决方法:
找到文件夹中的system.h加入以下代码,直接在文件夹下搜索这个文件就能找到
#include
重新执行./build.sh
进入ORB-SLAM2文件夹,运行以下代码
./Examples/Monocular/mono_euroc Vocabulary/ORBvoc.txt Examples/Monocular/EuRoC.yaml /home/dxf/catkin_ws/src/MH_04_difficult/mav0/cam0/data Examples/Monocular/EuRoC_TimeStamps/MH04.txt
代码路径可能不同,可以根据以下图片相应修改,数据集我是网上下载的
cd catkin_ws/src
git clone https://github.com/bosch-ros-pkg/usb_cam.git
cd ..
catkin_make
source ./devel/setup.bash
cd usb_cam
mkdir build
cd build
cmake ..
make
打开一个终端,运行:
roscore
打开第二个终端,运行:
cd catkin_ws/src/usb_cam/launch/
roslaunch usb_cam-test.launch
报错:Cannot identify '/dev/video0': 2, No such file or directory
解决办法:
1、执行以下命令
roscore
sudo apt-get install ros-melodic-usb-cam
2、点击下图所示"虚拟机",选择设置,点击USB控制器,右侧兼容性选择3.1
3、进行如下设置,最后一步点击“连接”
选择是
重新执行:
cd catkin_ws/src/usb_cam/launch/
roslaunch usb_cam-test.launch
相机安装成功!
摄像头标定工具安装
sudo apt-get install ros-melodic-camera-calibration
执行以下命令进行相机标定
打开一个终端,执行:
roscore
打开第二个终端执行:
cd catkin_ws/src/usb_cam/launch/
roslaunch usb_cam-test.launch
打开第三个终端执行:
rosrun camera_calibration cameracalibrator.py --size 8x6 --square 0.0245 image:=/usb_cam/image_raw camera:=/usb_cam
都变成绿色位置了就按下CALIBRATE按钮,等一段时间就可以完成标定。完成后点击SAVE保存标定使用的图像以及标定结果,会显示保存地址,可以打开查看,然后再COMMIT退出程序,标定完成。找到标定结果文件后,按照其数据修改Examples/ROS/ORB_SLAM2目录下Asus.yaml。
1.确保在system.h文件夹中加入了
#include
2.进入如图所示文件夹
找到ros_mono.cc,ros_mono_ar.cc(这个在该文件夹的AR文件夹里面),两个都要改哦!
将以下代码
//单目
ros::Subscriber sub = nodeHandler.subscribe("/camera/image_raw", 1, &ImageGrabber::GrabImage,&igb);
替换为:
ros::Subscriber sub = nodeHandler.subscribe("/usb_cam/image_raw", 1, &ImageGrabber::GrabImage,&igb);
回到ORB-SLAM2文件夹,编译
chmod +x build_ros.sh
./build_ros.sh
报错:
解决方法:进入/Examples/ROS/ORB_SLAM2文件夹,打开CMakeLists.txt文件,在下面图片位置加入-lboost_system
重新编译
chmod +x build_ros.sh
./build_ros.sh
成功!
第一个终端输入以下命令
roscore
第二个终端输入:
cd catkin_ws/src/usb_cam/launch/
roslaunch usb_cam-test.launch
进入ORBSLAM2文件夹,新建第三个终端输入:
rosrun ORB_SLAM2 Mono Vocabulary/ORBvoc.txt Examples/ROS/ORB_SLAM2/Asus.yaml
至此,Ubuntu18.04可实习ORB-slam2在ROS下的实时运行。
本文只作为本人运行slam过程记录
如有错误,请各位大佬批评指正