基于Ubuntu18.04的Gazebo无人机仿真实验

2023-05-16

写在前面

在这里插入图片描述

一、VMware安装Ubuntu18.04

1. 安装过程

VMware和Ubuntu可直接从官网下载。对于Ubuntu的安装也并未难点,只需按照默认的配置操作即可,首次启动会自动安装Ubuntu。

2. 遇到的问题

主要为旧版的VMare与Guard不兼容所导致的。
在这里插入图片描述
解决办法[2]:以管理员身份运行cmd,运行命令:bcdedit /set hypervisorlaunchtype off

二、Ubuntu 18.04 ROS melodic版本构建环境和无人机的指定飞行

(基于Ubuntu18.04主要是在16.04是报错较多,且长时间无法解决,所以决定使用18.04来进行编译运行代码)

1. 下载Ubuntu18.04并安装(类似于Ubuntu16.04)

文件目录
在这里插入图片描述

2. 项目环境搭建过程[1,3]

1. 安装ROS环境和Gazebo仿真器

$ sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu `lsb_release -sc` main" > /etc/apt/sources.list.d/ros-latest.list'
$ wget http://packages.ros.org/ros.key -O - | sudo apt-key add -
$ sudo apt-get update
$ sudo apt-get install ros-melodic-desktop-full ros-melodic-joy ros-melodic-octomap-ros ros-melodic-mavlink python-wstool python-catkin-tools protobuf-compiler libgoogle-glog-dev ros-melodic-control-toolbox ros-melodic-mavros python-rosdep python-roslaunch
$ sudo rosdep init 
$ rosdep update
$ source /opt/ros/melodic/setup.bash
//安装python-pip,future,lxml包 
$ sudo apt install python-pip
$ pip install future,lxml

2. control.cpp文件的书写 [7]

//以下文件为无人机路径的3D坐标
std::vector<Eigen::Vector3d> path;
path.push_back(Eigen::Vector3d(2.f,2.f,2.f));
path.push_back(Eigen::Vector3d(-2.f,2.f,2.f));
path.push_back(Eigen::Vector3d(-2.f,-2.f,2.f));
path.push_back(Eigen::Vector3d(2.f,-2.f,2.f));
path.push_back(Eigen::Vector3d(2.f,2.f,2.f));
std::cout << path.size() << std::endl;

3. 初始化UAV1工作区

$ mkdir -p ~/UAV1/src
$ cd UAV/src/ # 在UAV1/src下操作
//将rotors_simulator仓库git clone到catkin_ws/src中
//这一步很重要,如果clone最新版的代码编译出错的话,可以试下旧版本的commit。
$ catkin_create_pkg control std_msgs rospy roscpp
//修改CMakeLists.txt文件
//修改package.xml文件
//在UAV/src文件夹中创建control.cpp文件
//在UAV/src/control创建launch文件夹,并在其中添加uav.launch文件
$ catkin_init_workspace
$ wstool init
$ wget https://raw.githubusercontent.com/ethz-asl/rotors_simulator/master/rotors_hil.rosinstall
$ wstool merge rotors_hil.rosinstall
$ wstool update

4. 编译

//在UAV1文件下操作
$ catkin_make
$ echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc
$ source ~/.bashrc
$ source devel/setup.bash 

5. 测试在这里插入图片描述

$ roslaunch rotors_gazebo mav_hovering_example.launch mav_name:=firefly world_name:=basic

6. 无人机的指定飞行

在这里插入图片描述在这里插入图片描述

$ roslaunch control uav.launch

3. 遇到的问题

  1. 运行Gozebo会发生闪退现象,即虚拟机会突然卡死,然后系统会自动杀死进程
    解决方法:虚拟机内存太小(1G)进程会占满内存造成崩溃,增到虚拟机内存即可
    在这里插入图片描述
  2. 最新版本的RotorS[9]中用Gazebo 9环境,通过caktin_make编译时出现了编译问题
/home/user/catkin_ws/src/robot_tutorial_1/plugins/wb_plugin.cc:98:7: error: ‘math’ does not name a type; did you mean ‘tanh’?
       math::Quaternion pRot;
       ^~~~
       tanh
       .....

解决方法[8]:修改了如下代码,但最终决定选择低版本的RotorS[10]

#include <ignition/math/Vector3.hh>
ignition::math::Vector3d pPos;
  1. 运行Gazebo时出现如下错误,出现界面,但无法飞行
    在这里插入图片描述
    解决方法:发现为未编译成功导致。其中使用旧版本的RotorS后该问题解决。
  2. 相比于Ubuntu16.04,Ubuntu18.04还需要额外安装python-rosdep python-roslaunch

参考文章

  1. Ubuntu install of ROS Melodic
  2. http://www.win7zhijia.cn/win10jc/win10_20680.html
  3. https://github.com/ethz-asl/rotors_simulator
  4. https://blog.csdn.net/qq_39346534/article/details/108307484
  5. https://blog.csdn.net/weixin_42608885/article/details/88139888
  6. https://github.com/ros/rosdistro/issues/9721#issuecomment-309584958
  7. https://www.guyuehome.com/21614
  8. https://answers.ros.org/question/361021/i-try-to-catkin_make-with-gazebo-9-but-i-got-these-errors/
  9. https://github.com/ethz-asl/rotors_simulator/tree/ac77a8a5c3ede1d8591928c1c499cc3b26919d68
  10. https://blog.csdn.net/u013083665/article/details/104825813?utm_term=%E5%AE%89%E8%A3%85gazebo9&utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2allsobaiduweb~default-0-104825813&spm=3001.4430
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

基于Ubuntu18.04的Gazebo无人机仿真实验 的相关文章

随机推荐