安装rotors

rotors是ETH(苏黎世联邦理工大学)研究团队开发的一个ROS包,GITHUB地址,安装的过程参考官方的介绍

首先安装依赖包

sudo apt-get install ros-noetic-desktop-full ros-noetic-joy ros-noetic-octomap-ros python-wstool python-catkin-tools protobuf-compiler
sudo apt-get install libgeographic-dev ros-noetic-geographic-msgs  # Required for mavros.

这里我们用的是noetic,所以要把官方的indigo替换掉。

创建文件夹并初始化工作空间

mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
catkin_init_workspace  
wstool init

将下来开始Git代码

cd ~/catkin_ws/src
 git clone git@github.com:ethz-asl/rotors_simulator.git
 git clone git@github.com:ethz-asl/mav_comm.git
 git clone git@github.com:ethz-asl/glog_catkin.git
 git clone git@github.com:catkin/catkin_simple.git

注意一点,git这里需要提前登录github账号,否则不能正常git

开始编译

cd ~/catkin_ws/
 catkin init  # If you haven't done this before.
 catkin build

编译一切正常会输出如下结果

pytorch 无人机 python无人机模块_自动驾驶

运行rotors

rotors中有许多种机型,包括固定翼、多旋翼等,这里以四旋翼为例,进行仿真,在终端运行下面命令:

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

执行之后,gazebo会自动启动,出现下面的画面,则表示大功告成:

pytorch 无人机 python无人机模块_pytorch 无人机_02


下面我们来试一下修改四旋翼的位置:

用下面命名我们来看一下有哪些消息可以订阅和发送

rostopic list

pytorch 无人机 python无人机模块_pytorch 无人机_03


可以看见此时已经运行了很多消息,我们要改变四旋翼位置需要用到的话题是第三个/firefly/command/pose,现在来发送改变位置的命令:

rostopic pub -1 /firefly/command/pose geometry_msgs/PoseStamped "header:
  seq: 0
  stamp:
    secs: 0
    nsecs: 0
  frame_id: ''
pose:
  position:
    x: 0.0
    y: 1.0
    z: 1.0
  orientation:
    x: 0.0
    y: 0.0
    z: 0.0
    w: 0.0"

这里我设置的位置是(0,1,1),执行之后,可以看见四旋翼开始移动

如果能做到这一步,就说明已经可以基本完成四旋翼仿真了,将消息用一个节点来发送,就可以实现更多的工作,感兴趣的可以去探索一下。