This project is all about flying robots, AKA Quadcopters. There’s a wide range of copters out there and each one has its advantages and disadvantages. Like you see in the image below, I used a 6 rotors copter.
My goals are showing some basic quad-copters programming, talking about copters flight concepts and showing some of the autonomous flight algorithm which navigates the copter between GPS points while avoiding obstacles in its path (completely on its own).
- Asctec firefly copter – hexacopter
- GPS module
- Hokuyo Laser – indoor or outdoor (although I used the indoor outside)
- Linux environment with ROS (robots operating system) installed
Basic Quadcopter Flight Concepts
Each air vehicle is able to fly in 3 different axes, the vehicle position may vary according to the current gravitation axis.
Yaw – The yaw axis is defined to be perpendicular to the body of the wings with its origin at the center of gravity and directed towards the bottom of the aircraft. A yaw motion is a movement of the nose of the aircraft from side to side.
Pitch – The lateral axis passes through the plane from wingtip to wingtips. Rotation about this axis is called pitch. Pitch changes the vertical direction the aircraft’s nose is pointing.
Roll – The longitudinal axis passes through the plane from nose to tail. Rotation about this axis is called bank or roll. Roll changes the orientation of the aircraft’s wings with respect to the downward force of gravity.
Designing The Obstacle Detection Algorithm
My goal is to design an algorithm which will control the copter flight and will take decisions regarding nearby obstacles. The algorithm should be able to navigate the copter from one GPS waypoint to another while avoiding obstacles in its path, when an obstacle is detected, the copter needs avoid it and still continue moving toward the current waypoint.
After writing the requirements, it’s clear that we need to separate the program into a couple of modules:
- Laser data analyzer – this module analyzes all the data streams from the laser and announces where do we have obstacles around us. This module runs in a loop and gives samples continuously.
- Flight control – this module is in charge of reading the ‘laser data analyzer’ output and taking decisions according to its output. i.e. if we detect an obstacle ahead of us – we can stop immediately and recalculate the new path.
- Waypoint Navigator – this is a simple module which is in charge of completing the task successfully by making sure we visit all the waypoints. Each time, a single waypoint is considered to be the ‘target’, anytime we arrive in a waypoint we replace the ‘target’ value with a new value. All the other modules should not be familiar with the waypoints and only need to take care of the flight itself.
Laser Data Analyzer Pseudo Code
1. read laser data 2. define left bin of size 15 degrees - count dirty cells (cells which were detected with obstacle) 3. define middle bin of size 30 degrees - count dirty cells 4. define right bin of size 15 degrees - count dirty cells 5. set threshold to 20% 6. if #dirty-cells-middle < threshold 6.1. set middle path is clear 7. else 7.1. if #dirty-cells-left < #dirty-cells-right 7.1.1. set pass-obstacle-from-left 7.2. else 7.2.1. set pass-obstacle-from-right 8. iterate bins at -31 deg -> -29 deg and calculate average laser values 8.1. if average < 1 8.1.1. set critical-obstacle-from-right 9. iterate bins at 29 deg -> 31 deg and calculate average laser values 9.1. if average < 1 9.1.1. set critical-obstacle-from-left
Flight Control Pseudo Code
1. read laser data from the 'Laser Data Analyzer' 2. if distance-to-target <= goal-radius (we define the goal as a 2D point with dimensions) 2.1. stop yaw velocity 3. else 3.1. clip yaw value 4. set x and y velocities to zero 5. if distance-to-goal > goal-radius 5.1. if critical-obstacle-from-right == true && critical-obstacle-from-left == false 5.1.1. move left and reduce velocity 5.1.2. return 5.2. else if critical-obstacle-from-left == true && critical-obstacle-from-right == false 5.2.1. move right and reduce velocity 5.2.2. return 5.3. else if critical-obstacle-from-left == true && critical-obstacle-from-right == true 5.3.1. reduce velocity 5.3.2. return 6. if no critical obstacles found 6.1. if distance-to-goal < 2m 6.1.1. reduce speeds 6.2. update velocities 7. else 7.1. minimize distance to target from left or right and navigate to edge of obstacle 7.2. update velocities
The algorithm developed and tested in a real outdoor flight zone, many of the parameters were adjusted according to real flights results on the field. The outdoor environment includes problems you usually won’t consider when working inside a lab. Things like wind, heat, direct sunlight, mechanical issues happen more often and must be considered and taken care of in the implementation.