当先锋百科网

首页 1 2 3 4 5 6 7

【rotors】多旋翼无人机仿真(一)——搭建rotors仿真环境
【rotors】多旋翼无人机仿真(二)——设置飞行轨迹
【rotors】多旋翼无人机仿真(三)——SE3控制
【rotors】多旋翼无人机仿真(四)——参数补偿和PID控制
【rotors】多旋翼无人机仿真(五)——多无人机仿真

本贴内容参考两位博主的内容:
月照银海似蛟
Reed Liao

1、前言

上一节中,我们讲解了参数补偿和PID控制,但这都是单无人机,本节讲解如何创建多个无人机仿真。

2、无人机仿真

在ROS和gazebo仿真中,想创建多个机器人十分简单,ctrl C+ ctrl V即可,只不过要注意不同机器人之间的namespace需要不同,不然会产生冲突。

~/UAV_rotors/src/rotors_simulator/rotors_gazebo/launch文件夹下创建multiple_UAV.launch,内容为:

<launch>
  <arg name="mav_name" default="firefly"/>
  <arg name="world_name" default="basic"/>
  <arg name="enable_logging" default="false" />
  <arg name="enable_ground_truth" default="true" />
  <arg name="log_file" default="$(arg mav_name)" />

  <env name="GAZEBO_MODEL_PATH" value="${GAZEBO_MODEL_PATH}:$(find rotors_gazebo)/models"/>
  <env name="GAZEBO_RESOURCE_PATH" value="${GAZEBO_RESOURCE_PATH}:$(find rotors_gazebo)/models"/>
  <!-- 启动gazebo -->
  <include file="$(find gazebo_ros)/launch/empty_world.launch">
    <arg name="world_name" value="$(find rotors_gazebo)/worlds/$(arg world_name).world" />
    <!-- <arg name="debug" value="true"/> -->
    <arg name="paused" value="true"/>
    <!-- <arg name="gui" value="false"/> -->
    <!-- <arg name="verbose" value="true"/> -->
  </include>

  <!-- 修改ns -->
  <group ns="$(arg mav_name)_0">
    <!-- 导入无人机模型 -->
    <include file="$(find rotors_gazebo)/launch/spawn_mav.launch">
      <arg name="mav_name" value="$(arg mav_name)" />
      <arg name="model" value="$(find rotors_description)/urdf/mav_with_vi_sensor.gazebo" />
      <arg name="enable_logging" value="$(arg enable_logging)" />
      <arg name="enable_ground_truth" value="$(arg enable_ground_truth)" />
      <arg name="log_file" value="$(arg log_file)"/>
      <!-- 修改namespace -->
      <arg name="namespace" default="$(arg mav_name)_0"/>
    </include>
    <!-- 启动无人机控制节点 -->
    <node name="lee_position_controller_node" pkg="rotors_control" type="lee_position_controller_node" output="screen">
      <rosparam command="load" file="$(find rotors_gazebo)/resource/lee_controller_$(arg mav_name).yaml" />
      <rosparam command="load" file="$(find rotors_gazebo)/resource/$(arg mav_name).yaml" />
      <remap from="odometry" to="odometry_sensor1/odometry" />
    </node>
    <!-- 启动无人机轨迹控制命令节点 -->
    <node name="hovering_example" pkg="rotors_gazebo" type="hovering_example" output="screen"/>
    <!-- 启动仿真关节节点 -->
    <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" />
    <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" />
  </group>

  <group ns="$(arg mav_name)_1">
    <!-- 导入无人机模型 -->
    <include file="$(find rotors_gazebo)/launch/spawn_mav.launch">
      <arg name="mav_name" value="$(arg mav_name)" />
      <arg name="model" value="$(find rotors_description)/urdf/mav_with_vi_sensor.gazebo" />
      <arg name="enable_logging" value="$(arg enable_logging)" />
      <arg name="enable_ground_truth" value="$(arg enable_ground_truth)" />
      <arg name="log_file" value="$(arg log_file)"/>
        <!-- 无人机初始位置 -->
      <arg name="x" value="3.0"/>
      <arg name="y" value="3.0"/>
      <arg name="z" value="0.1"/>
      <arg name="namespace" default="$(arg mav_name)_1"/>
    </include>
    <!-- 启动无人机控制节点 -->
    <node name="lee_position_controller_node" pkg="rotors_control" type="lee_position_controller_node" output="screen">
      <rosparam command="load" file="$(find rotors_gazebo)/resource/lee_controller_$(arg mav_name).yaml" />
      <rosparam command="load" file="$(find rotors_gazebo)/resource/$(arg mav_name).yaml" />
      <remap from="odometry" to="odometry_sensor1/odometry" />
    </node>
    <!-- 启动无人机轨迹控制命令节点 -->
    <node name="hovering_example" pkg="rotors_gazebo" type="hovering_example" output="screen"/>
    <!-- 启动仿真关节节点 -->
    <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" />
    <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" />
  </group>

  <group ns="$(arg mav_name)_2">
    <!-- 导入无人机模型 -->
    <include file="$(find rotors_gazebo)/launch/spawn_mav.launch">
      <arg name="mav_name" value="$(arg mav_name)" />
      <arg name="model" value="$(find rotors_description)/urdf/mav_with_vi_sensor.gazebo" />
      <arg name="enable_logging" value="$(arg enable_logging)" />
      <arg name="enable_ground_truth" value="$(arg enable_ground_truth)" />
      <arg name="log_file" value="$(arg log_file)"/>
      <arg name="x" value="0.0"/>
      <arg name="y" value="3.0"/>
      <arg name="z" value="0.1"/>
      <arg name="namespace" default="$(arg mav_name)_2"/>
    </include>
    <!-- 启动无人机控制节点 -->
    <node name="lee_position_controller_node" pkg="rotors_control" type="lee_position_controller_node" output="screen">
      <rosparam command="load" file="$(find rotors_gazebo)/resource/lee_controller_$(arg mav_name).yaml" />
      <rosparam command="load" file="$(find rotors_gazebo)/resource/$(arg mav_name).yaml" />
      <remap from="odometry" to="odometry_sensor1/odometry" />
    </node>
    <!-- 启动无人机轨迹控制命令节点 -->
    <node name="hovering_example" pkg="rotors_gazebo" type="hovering_example" output="screen"/>
    <!-- 启动仿真关节节点 -->
    <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" />
    <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" />
  </group>

  <group ns="$(arg mav_name)_3">
    <!-- 导入无人机模型 -->
    <include file="$(find rotors_gazebo)/launch/spawn_mav.launch">
      <arg name="mav_name" value="$(arg mav_name)" />
      <arg name="model" value="$(find rotors_description)/urdf/mav_with_vi_sensor.gazebo" />
      <arg name="enable_logging" value="$(arg enable_logging)" />
      <arg name="enable_ground_truth" value="$(arg enable_ground_truth)" />
      <arg name="log_file" value="$(arg log_file)"/>
      <arg name="x" value="3.0"/>
      <arg name="y" value="0.0"/>
      <arg name="z" value="0.1"/>
      <arg name="namespace" default="$(arg mav_name)_3"/>
    </include>
    <!-- 启动无人机控制节点 -->
    <node name="lee_position_controller_node" pkg="rotors_control" type="lee_position_controller_node" output="screen">
      <rosparam command="load" file="$(find rotors_gazebo)/resource/lee_controller_$(arg mav_name).yaml" />
      <rosparam command="load" file="$(find rotors_gazebo)/resource/$(arg mav_name).yaml" />
      <remap from="odometry" to="odometry_sensor1/odometry" />
    </node>
    <!-- 启动无人机轨迹控制命令节点 -->
    <node name="hovering_example" pkg="rotors_gazebo" type="hovering_example" output="screen"/>
    <!-- 启动仿真关节节点 -->
    <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" />
    <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" />
  </group>
</launch>

运行即可:

roslaunch rotors_gazebo multiple_UAV.launch

在这里插入图片描述
说明一下每个无人机都需要有自己的控制节点lee_position_controller_node,但无人机轨迹控制命令节点hovering_example可以大家共用一个