How to build your own autonomous drone from scratch
A gentle guide to building a completely autonomous drone
Here we build one of the first autonomous drones with a robotic arm on the top of the drone.
Building machines and devices to ease human tasks and increase safety has been a priority since the beginning of time. Drones in particular have done exceptionally well in carrying out such tasks ranging from the most simplest to the ultra-difficult, in a safe and cost-effective fashion. While they are being used in different areas like aerial photography, express shipping, or disaster rescue, some have even used them to give their cats a thrilling flight experience.
As fancy as they might look, they require time, suitable components, and in-depth research if they have to be built from scratch. So here I’ve documented the making of my autonomous UAV (mainly built on) in an attempt to make your lives easier.
Source code:
Supplementary Documents(Detailed Explanation with a flavor of Drone Science):
Link to Research paper Published:
Challenges addressed in the above paper(Additional Read):
- Maintaining Stability and Controlling drift.
- Coupling of the Robotic arm and the drone.
- Flight time optimization.
- Computational power for autonomous flight with Raspberry pi.
- Optimized measurements of drone components.
- Reduction in the bodyweight of the drone.
- Predicting dynamic CoG(Center of Gravity) of the drone for different link lengths.
Find a use case
Different use cases demand/requires different design and build strategies. In this experiment, the drone was mainly built to reduce risks involved in mobile tower inspection which traditionally requires humans to climb great heights through precarious ladders and scaffolds to get to the problem. The drone is also incorporated with a camera and a robotic arm to perform tasks such as tightening screws and fixing wires. By the way, I think this is the right time to show the drone I had built for this use case.
Make design decisions
Before getting into the electronics and programming aspect of the drone, I would like to highlight the importance of focusing on the core mechanical structure which would influence the choice of other electronic components. The design considerations here:
Y-Copter:
- Better yaw stability.
- Cannot stabilize the robotic arm(additional actuator) in pitch and roll axis.
Quadcopter:
- Better stability in all three axis.
- Suitable for any additional actuator motion in all directions.
Hexacopter:
- More lifting capacity.
- Larger in size.
- More obstacles for robotic arm motion to perform its actions.
Octocopter:
- More lifting capacity.
- More battery capacity is required for an increased number of motors and increased weight.
So, given the above observations, we decided on an X-Frame for our application which has a diagonal length of 400mm. Once we narrow down on the frame type, we need to decide on frame configuration.
H Frame:
- More room on top for placing components.
- Increase in material and thus adding weight.
X Frame:
- Reduced central area.
- Resulting in reduced material and thus weight.
Plus Frame:
- Easier breakage on impact.
- Causes problems in the motion of the robotic arm.
- Obstructs the field of view of the camera.
So we choose, X frame which provides a Good thrust-to-weight ratio, Easier motion of robotic arm between propellers, Better camera arc coverage. The diameter of 400 mm was chosen using an iterative optimization process using tools like CAD and ANSYS. The optimization parameters were designed to ensure the stability of the robotic arm, to avoid the interference of prop wash of propellers for effective thrust, and also to provide an effective thrust to weight ratio.
Now comes the choice of the material to build a drone.
According to the table, we choose carbon since it has the highest strength to ratio. We Choose PLA for parts not requiring structural strength and Nylon spacers for support structures were used.
Arrangements of Components
Here we have
Choosing
For any quadcopter, the diagonal motors spin in one direction, and the motors on the other diagonal spin the other direction creating the required thrust for takeoff.
Choose the components
Any drone or quadcopter has a few basic components which need to be carefully selected to ensure they work well with each other and provide the required thrust so the drone can fly. These components are namely the motors, the electronic speed controllers(ESCs), the propellers, the frame length, the battery, the flight controller.
- We first decide the maximum weight we want to lift. (weight includes the battery, arm, and all other components used).
- Accordingly, choose a suitable battery configuration.
- Choose motors and ESCs according to the maximum current drawn from the battery and thrust required to lift the drone.
- Choose appropriate propellers size and pitch according to the motor capacity and the thrust required by the drone
There are various tools and software that help make these decisions, one such is eCalc.
In specific while choosing battery (since it is one of the most important and expensive components), choose it wisely based on density -discharge plot.
An illustrative example:
For example in my case, the motors draw up to 30A, so the battery must provide a minimum of 35A to prevent them from getting damaged so according to the following plot, we can observe that 5200mAh and 6000 mAh are good options.
To choose one among them, we optimize them with a density-based selection. Density = Capacity/Weight, so higher the density better the battery( weight to power ratio maximization).
Here we can see that 5200 mAh has the highest density among the available batteries. So, I pick the optimum battery conditioning it on both the selection methods.
Add sensors and electronics-The brain
The Pixhawk 4 is a robust open hardware project that we use to control the drone. The Pixhawk flight controller is very flexible, which makes it easier to add a wide range of sensors and electronics. Alongside, it has a vivid range of internal sensors as a compact package that comes with various telemetry and logging functions. This was one of the major reasons for choosing Pixhawk as a flight controller.
The sensors that were used in this experiment are listed below:
- The GPS: To ensure the drone maintains its position and does not drift while in the air, we use a GPS module. Neo 8m GPS module has both a GPS as well as an inbuilt compass to help the drone understand where it is as well as where it wants to go. The GPS is also used extensively in the code to autonomously tell the drone where to go. The pixhawk flight controller comes with an inbuilt compass to help the drone figure out which direction it is heading in. And, the GPS module along with the compass is usually placed on a mount high above the motors and battery to ensure no interference.
- LiDAR: The Pixhawk uses a barometer for deciding its current altitude. This poses multiple issues, especially for our application. Air pressure does not change much over short heights of 2 meters which was the maximum height we set for all our demos. As a result, we needed to add an accurate range finder and the Benewake TFMini Plus suited our needs perfectly. This tiny sensor uses Light Detection and Ranging(LIDAR) to accurately measure the altitude of the drone. The module has an operating range of 10cm to 12m and has a higher accuracy in the 10cm to 6m range. With all our demos requiring the drone to fly below 6m, we had the most accurate readings of the sensor. It has a resolution of 0.5cm and a field of view of 3.6°. The module communicates with the Pixhawk over a serial communication with a 115,200 baud rate. This means that 115,200 bits of data are sent over the connection per second.
Robotic Arm
The arm has a reach of up to 10cm beyond the propeller and has 4 servo motors that allow the arm to extend and retract. The servo motors are controlled by the Raspberry Pi using the PCA9685 board which splits the single I2C port on the Raspberry Pi into 5 ports to control each of the servo motors of the arm. The arm has a gripper on the end that can be opened and closed to pick up the required tools to fix the mobile tower. In our demos, we attached a screwdriver to the end of the arm and showed it performing a simple screwing action. Other possible use cases of this design include automatic bulb replacement of lights placed high up on ceilings as well as adding a camera to the end effector to get pictures of hard-to-access places.
Each servo motor has three wires, positive power, ground, and a PWM
input. Code from the Pi sends a PWM signal that commands each servo
to go to a particular angle. The movements of the arm are calculated to provide the least disruption to the center of gravity of the arm and hence is the most stabilized motion possible.
The arm needed to be strong enough to carry the servo motors as well as the
screwdriver but light enough to be carried by the drone. This led us to use Polylactic Acid(PLA) for the arm. Multiple test flights led us to the current final design as well as the sequence of movement for the arm. If the center of gravity moved too far away from the center of the drone, it caused the drone to vibrate. As a result, we carried out more tests and used the data we recorded to design a better arm with the same reach but less disruption.
Program the brain of the drone
Given the abundance of information on the internet, the immediate confusion that might occur is “which firmware shall I choose”?
I choose APM (Ardupilot, APM 3.9.6) since they had -Huge developer base and since the community is active their forums are very helpful and APM is compatible with Dronekit API.
The Raspberry Pi is a great multipurpose single-board computer(SBC) and its versatility and small size made it the perfect choice for our drone. The Pi is the brain of the drone and is the single component that makes it autonomous. It has one UART port and one I2C port. We use the UART port to communicate between the Pi and the Pixhawk and the I2C port is connected to the PCA9685 which controls the 5 servo motors of the robotic arm. The Pi runs Raspbian Stretch, the 9th edition of the official Raspbian OS. After installing all the requirements, we are ready to fly the drone completely autonomously.
MAVLink: The communication protocol followed by the flight controller is called MAVLink. It is a very lightweight messaging protocol for communicating with drones (and between onboard drone components). MAVLink follows a modern hybrid publish-subscribe and point-to-point design pattern: Data streams are sent/published as topics while configuration sub-protocols such as the mission protocol or parameter protocol are point-to-point with re-transmission.
DroneKit API: The DroneKit API allows developers to create Python apps that communicate with vehicles over MAVLink. It provides programmatic access to a connected vehicle’s telemetry, state, and parameter information, and enables both mission management and direct control over vehicle movement and operations.