Launching Erle-Copter simulation

Get the real vehicle here



REMINDER: configure your environment before starting this tutorial.


source ~/simulation/ros_catkin_ws/devel/setup.bash
cd ~/simulation/ardupilot/ArduCopter
../Tools/autotest/sim_vehicle.sh -j 4 -f Gazebo

In another terminal

source ~/simulation/ros_catkin_ws/devel/setup.bash
roslaunch ardupilot_sitl_gazebo_plugin erlecopter_spawn.launch

Go to the first terminal

# once MAVProxy has launched completely, load the parameters
param load /[path_to_your_home_directory]/simulation/ardupilot/Tools/Frame_params/Erle-Copter.param
# NOTE: replace [path_to_your_home_directory] with the actual path to your home directory.
# Example: param load /home/john/simulation/ardupilot/Tools/Frame_params/Erle-Copter.param



Figure 1 - General view of the simulation. The building corresponds to the first floor of Erle Robotics' office.



Figure 2 - Erle-Copter model in Gazebo simulator


Make the copter take off. In the first terminal execute:

# in the MAVProxy prompt:
mode GUIDED
arm throttle
takeoff 2

or overriding the RC:

# in the MAVProxy prompt:
mode LOITER
arm throttle
rc 3 1600
rc 3 1500

To add a sonar sensor to the gazebo model it's necessary to add the following lines to erlecopter.xacro and relaunch the simulation. It's quite easy to modify the width and height of the image with the params res_x and res_y, the name of the topic with ros_topic or the update rate with update_rate.

  <!-- Downward facing camera -->
  <xacro:include filename="$(find ardupilot_sitl_gazebo_plugin)/urdf/sensors/generic_camera.urdf.xacro" />
  <xacro:generic_camera
    name="erlecopter/bottom"
    parent="base_link"
    ros_topic="image_raw"
    cam_info_topic="camera_info"
    update_rate="60"
    res_x="640"
    res_y="360"
    image_format="R8G8B8"
    hfov="81"
    framename="erlecopter_bottomcam">
    <origin xyz="0.14 0.0 -0.02" rpy="0 ${M_PI/2} 0"/>
  </xacro:generic_camera>  

Execute in a terminal (make sure it have installed image_view)

rosrun image_view image_view image:=/erlecopter/front/image_front_raw


Figure 3 - Frontal image


To add a sonar sensor to the gazebo model it's necessary to add the following lines to erlecopter.xacro and relaunch the simulation. It's quite easy to modify the maximum and minimum range with the values max_rangeand min_range, change the udpate rate with update_rate (10Hz in this case), etc.

    <!-- Frontal range sensor -->
  <xacro:sonar_sensor
    name="sonar2"
    parent="base_link"
    ros_topic="sonar_front"
    update_rate="10"
    min_range="0.01"
    max_range="50.0"
    field_of_view="${1*M_PI/180}"
    ray_count="1"
    sensor_mesh="lidar_lite_v2_withRay/meshes/lidar_lite_v2_withRay.dae">
    <origin xyz="0.13 0.0 0.02" rpy="0 0 0"/>
  </xacro:sonar_sensor>

It possible to get the measurement from the sonars (front and down). Use the topics sonar_front or sonar_down.

rostopic echo /sonar_down
---
header:
  seq: 30284
  stamp:
    secs: 76
    nsecs: 750000000
  frame_id: sonar_link
radiation_type: 0
field_of_view: 0.0174532998353
min_range: 0.00999999977648
max_range: 50.0
range: 1.98501801491
---

To add a laser 2D to the gazebo model it's necessary to add the following lines to erlecopter.xacro and relaunch the simulation. It's quite easy to modify the maximum and minimum range with the values max_rangeand min_range, cahnge the udpate rate with update_rate (10Hz in this case), the horizontal an vertical field of view with field_of_view_horizontal and field_of_view_vertical, the number of rays in vertical and horizontal with ray_count_horizontal and ray_count_horizontal or the position relative to the copter.

  <xacro:include filename="$(find ardupilot_sitl_gazebo_plugin)/urdf/sensors/lidar_sensor.urdf.xacro" />
   <xacro:lidar_sensor
    name="sonar2"
    parent="base_link"
    ros_topic="sonar_front"
    update_rate="10"
    min_range="0.01"
    max_range="10.0"
    field_of_view_horizontal="${70*M_PI/180}"
    field_of_view_vertical="${1*M_PI/180}"
    ray_count_horizontal="140"
    ray_count_vertical="1"
    sensor_mesh="lidar_lite_v2_withRay/meshes/lidar_lite_v2_withRay.dae">
    <origin xyz="0.13 0.0 0.02" rpy="0 0 0"/>
  </xacro:lidar_sensor>


Figure 4 - Laser 2D


The following code show how to visualize the shape of the laser:

#!/usr/bin/env python
import rospy

import cv2
import numpy as np
import math

from sensor_msgs.msg import LaserScan

def callback(data):
    frame = np.zeros((500, 500,3), np.uint8)
    angle = data.angle_min
    for r in data.ranges:
        x = math.trunc( (r * 30)*math.cos(angle + (-90*3.1416/180)) )
        y = math.trunc( (r * 30)*math.sin(angle + (-90*3.1416/180)) )
        cv2.line(frame,(250, 250),(x+250,y+250),(255,0,0),2)
        angle= angle + data.angle_increment

    cv2.circle(frame, (250, 250), 2, (255, 255, 0))
    cv2.imshow('frame',frame)
    cv2.waitKey(1)

def laser_listener():
    rospy.init_node('laser_listener', anonymous=True)
    rospy.Subscriber("/scan", LaserScan,callback)
    rospy.spin()

if __name__ == '__main__':
    laser_listener()


Figure 5 - Laser shape



If besides simulation, you're interested in translating these behaviors to real scenarios you can purchase the real vehicle at