Building an Autonomous Drone- Detailed step-by-step instructions

Sethuramantv
17 min readDec 26, 2022

--

A gentle guide to building an autonomous drone with radar capabilities

Any questions, please feel free to contact: Sethuraman T V, CS Ph.D. @ UIUC <st34@illinois.edu>

Also please feel free to refer Blog for further details.

Drones, also known as unmanned aerial vehicles (UAVs), are becoming increasingly popular for a wide range of applications, including aerial photography, mapping, inspection, and delivery. Building a drone can be a fun and educational project that allows you to customize your drone to meet your specific needs. In this report, we will provide an overview of the steps involved in building a drone, as well as some tips and recommendations for selecting the right components and assembling your drone.

Aim: Constructing an autonomous drone equipped with both radar and camera for aerial sensing of forest vegetation.

Step 1: Gather necessary components.

Building an autonomous drone with a Pixhawk flight controller and radar capability can be a complex project, as it involves a number of different components and technologies. So it’s essential to gather the right components.

  1. Number of motors:

We Choose: A quadcopter with four motors was chosen for the drone due to its good stability in all four axes and ability to facilitate easy movement in all directions with a lighter weight. This was also chosen to ensure the stability of the drone when one of the motors fails.

The number of motors on a drone is typically determined by the type of drone and its intended use. Here are some factors to consider when deciding on the number of motors for your drone:

  • Type of drone: Different types of drones have different requirements for the number of motors. For example, a quadcopter (a drone with four motors) is a common choice for many applications because it is stable and relatively easy to fly. Other types of drones, such as hexacopters (six motors) and octocopters (eight motors), may be more suitable for certain applications because they have more lift and stability.
  • Payload capacity: The weight and size of the payload you want to carry on your drone will affect the number of motors you need. In general, a drone with more motors will be able to carry a heavier payload, but it will also be larger and more expensive.
  • Flight characteristics: The number of motors can also affect the flight characteristics of your drone, such as its stability, agility, and speed. For example, a quadcopter may be more stable and easier to fly than a hexacopter, but a hexacopter may be able to lift a heavier payload and perform better in windy conditions.
  • Cost: The number of motors you choose will also affect the cost of your drone. In general, a drone with more motors will be more expensive due to the additional hardware and complexity.
  • Power requirements: The number of motors you choose will also affect the power requirements of your drone. A drone with more motors will need more power to run, which will impact the size and weight of the battery you need to use.

Ultimately, the right number of motors for your drone will depend on a variety of factors, including the type of drone, payload capacity, flight characteristics, cost, and power requirements. It’s important to carefully consider these factors and choose the number of motors that is best suited to your specific needs and goals.

  1. Frame Type: There are several options available , like “Plus” shaped frame, H copter , X copter etc.

We choose : X copter

However, while choosing a frame for your drone, there are several factors to consider:

  • Size and weight: Make sure the frame is large enough to accommodate all the components you want to include on your drone, such as the flight controller, sensors, and power system. However, be aware that a larger frame may result in a heavier drone, which could affect its flight characteristics and performance.
  • Payload capacity: Consider the weight of the payload (in our case radar and camera) you want to carry on your drone. Make sure the frame is strong enough to support the weight of the payload and any other components you are adding.
  • Material: Different materials have different properties that can affect the performance of your drone. For example, carbon fiber is lightweight and strong, but it can be more brittle than other materials. Aluminum is another popular choice, as it is strong and durable, but it is also relatively heavy.
  • Compatibility: Make sure the frame is compatible with the other components you are using, such as the flight controller and sensors. This includes the physical size and mounting points, as well as the electrical connections.
  • Price: Consider the cost of the frame, as well as any additional costs such as shipping or taxes. Be sure to balance the cost with the performance and durability of the frame.
  • Reputation: Perhaps the last , but research the reputation of the manufacturer or seller to ensure you are getting a high-quality product. Look for reviews or ask for recommendations from other drone enthusiasts or professionals.
  1. Frame Length : Choosing the right frame length is very crucial for drones functioning .

We choose : 400 mm

An easy way to choose this is to use online simulators like www.ecalc.ch and test if the drone is getting the necessary 80% thrust at least. Also, ensure that the edge length of the X frame is greater than the 2x radius of the propeller.

However, theoretically choosing the right frame depends on

  • Payload capacity: The length of the frame can affect the payload capacity of your drone. A longer frame may be able to accommodate a heavier payload, but it may also be more difficult to transport and may affect the stability of the drone.
  • Compatibility: Make sure the length of the frame is compatible with the other components you are using, such as the flight controller, sensors, and power system. The frame should be long enough to accommodate all the components, but not so long that it becomes unwieldy or difficult to control.
  • Flight characteristics: The length of the frame can also affect the flight characteristics of your drone, such as its stability, agility, and speed. A longer frame may provide more stability, but it may also be more prone to swaying or oscillating in windy conditions.
  • Size and weight: Consider the size and weight of the frame when selecting the length. A larger, heavier frame may be more difficult to transport and may affect the performance of the drone.
  • Cost: The length of the frame can also affect the cost of your drone. A longer frame may be more expensive due to the additional materials and labor required to manufacture it.
  1. Motors: Choosing the right motors is crucial to provide the right thrust to weight ratio which should be equal to 2:1 for a comfortable maneuver.

We choose: 1100 kV motors . Ensure that the motors are BLDC motors.

Note: Buy a compatible propellers which comes with the motor or fits the diameter of the motor shaft

Note: This can also be selected with the help of www.ecalc.ch

Theoretically, it depends on :

  • Payload capacity: The weight and size of the payload you want to carry on your drone will affect the motors you need. In general, motors with a higher lift capacity will be able to carry a heavier payload, but they may also be larger and more expensive.
  • Flight characteristics: The motors you choose can also affect the flight characteristics of your drone, such as its stability, agility, and speed. For example, motors with a higher KV rating (rotations per minute per volt) may provide more power and faster acceleration, but they may also be less efficient and generate more heat and consume more power.
  • Size and weight: Consider the size and weight of the motors when selecting them. Larger, heavier motors may be able to lift a heavier payload, but they may also increase the overall weight and size of your drone.
  • Cost: The cost of the motors is another important factor to consider. Be sure to balance the cost with the performance and durability of the motors you choose.
  • Reputation: Research the reputation of the manufacturer or seller to ensure you are getting high-quality motors. Look for reviews or ask for recommendations from other drone enthusiasts or professionals.
  1. Electronic Speed Controller: An electronic speed controller (ESC) is a key component of a drone that controls the speed of the motors. The ESC (Electronic Speed Controller) is needed to control the speed of the motor as it is a 3 phase motor. The considerations to be made before selecting an ESC are the motors power requirements and battery cell capacity.

We choose: 30 A ESC for powering our 1100 kV motor.

Note: This can also be selected with the help of www.ecalc.ch

Theoretically , this choice would depend on:

  • Compatibility: Make sure the ESC is compatible with the type of motors you are using. Some ESCs are designed to work with specific types of motors, such as brushless motors or brushed motors.
  • Current rating: The current rating of the ESC should be sufficient to handle the current draw of the motors. If the current rating is too low, the ESC may not be able to provide enough power to the motors, which could cause performance issues or damage to the components.
  • Size and weight: Consider the size and weight of the ESC when selecting it. A smaller, lighter ESC may be more convenient to use, but it may not be able to handle as much current as a larger, heavier ESC.
  • Cost: The cost of the ESC is another important factor to consider. Be sure to balance the cost with the performance and durability of the ESC you choose.
  • Reputation: Research the reputation of the manufacturer or seller to ensure you are getting a high-quality ESC. Look for reviews or ask for recommendations from other drone enthusiasts or professionals.
  1. Battery: Battery is the most important component of the drone. Hence, let me give an example of how to choose one for a 2 KG drone.

We choose: 3300 mAh with 35 to 50C burst current.

Note: This can also be selected with the help of www.ecalc.ch

  • Capacity: For a 2kg drone, you will want a battery with a capacity of at least 4,000mAh. This will give you a decent flight time, typically around 20–30 minutes depending on the specific characteristics of your drone and how it is being used.
  • Voltage: Most drones require a battery with a voltage of 11.1V or 14.8V. Check the specifications of your drone to determine the correct voltage for your battery.
  • Size and weight: Pay attention to the size and weight of the battery, as you will want to ensure that it fits in your drone without affecting its performance or stability. A battery that is too large or heavy may cause your drone to become unbalanced or difficult to control.
  • Compatibility: Make sure that the battery you choose is compatible with your specific drone model. Some batteries may not be compatible with certain drones, so it’s important to check before making a purchase.
  • Price: Consider the price of the battery as well. While it may be tempting to go for the cheapest option, keep in mind that the quality of the battery can affect the performance and reliability of your drone. It may be worth it to invest in a higher-quality battery that will last longer and provide better performance.
  1. Propellers: The propellers should provide enough thrust , at the same time should not draw much current and fry the ESC.

Also while selecting the propellers , ensure that you select the right pitch which is crucial for better navigation.

We choose: 8 inch , 4’5 pitch propellers

Note: This can also be selected with the help of www.ecalc.ch

Theoretically , consider the following factors to choose the right propellers:

  • Motor size and power: The size and power of the motors on your drone will determine the maximum size and pitch of the propellers you can use. Larger motors can typically handle larger and more aggressive pitch propellers, while smaller motors may be limited to smaller, lower pitch propellers.
  • Weight and payload: The weight of your drone and any payload it will be carrying will also impact the size and pitch of the propellers you should use. Larger, higher pitch propellers may be able to provide more lift, but they will also require more power to spin, which may not be practical for heavy drones or drones carrying a large payload.
  • Flight performance: The size and pitch of the propellers will also affect the flight performance of your drone. Larger, lower pitch propellers may provide more stability and longer flight times, but they may also be slower and less agile. Smaller, higher pitch propellers may offer faster acceleration and a higher top speed, but they may also be less stable and have shorter flight times.
  • Operating environment: The operating environment of your drone should also be considered when selecting propellers. For example, if you will be flying your drone in high wind conditions, you may want to use larger, lower pitch propellers to provide additional stability.
  1. Flight controller: The major component to navigate the UAV is the flight controller. This handles all the flight commands dynamically without explicit instructions to do so.

We choose: Pixhawk Mini

The Pixhawk is a popular flight controller used in many drones, particularly those used for aerial photography and mapping, as well as in some research and commercial applications. There are several reasons why the Pixhawk is often considered a top choice for a flight controller:

  • Flexibility: The Pixhawk is designed to be highly flexible and can be used with a wide range of drone platforms and applications. It is compatible with a variety of sensors and peripherals and can be used with multiple types of autopilot software.
  • Reliability: The Pixhawk has a reputation for being a reliable and robust flight controller. It has a fail-safe system that can detect and recover from certain types of hardware and software failures, helping to ensure the safety of the drone.
  • Performance: The Pixhawk has a powerful 32-bit processor and a range of advanced features that allow it to handle complex flight tasks and algorithms. It can perform high-precision navigation, real-time data processing, and other demanding tasks.
  • Community support: The Pixhawk has a large and active user community, which provides a wealth of knowledge and support for users. There are also many resources available online, including documentation, tutorials, and forums, that can help users get the most out of their Pixhawk flight controller.

Overall, the Pixhawk is a popular choice for a flight controller due to its flexibility, reliability, performance, and community support

The remaining components include :

8. Lidar — To measure the altitude from the ground.

We choose: Lidar tf mini -SPI

9. Raspberry Pi — To send commands to the pixhawk and act as an onboard computer to send commands to the radar and other I/O devices.

We choose: Rpi 4b/3b+

10. Propeller guards — To guard propellers from any potential impact.

11. Buck down converter — Down convert the high voltage current from the battery to deliver to the raspberry pi.

12. Battery monitor: To monitor the battery voltage during the flight time and ensure that the voltage does not fall below the minimum limit.

13. Compatible Radio transmitter and receiver : To facilitate the communication between the drone and manual controller.

Other minor components include — Heat Sink , Heat Shrink , M2M wires, M2F wires, F2F wires , Nylon Spacers , power distribution board, Neo 8m GPS (Do not use any other GPS) etc.

Step 2: Assemble the components the right away

  1. Assemble the frames together using the correct screws and make the X copter and check for the steadiness
  2. Assemble the motors and screw them tight
  3. Assemble the propellers and ensure that they are screwed tight with the right lock in place
  4. Assemble the power distribution board(PWB) in the center of the drone and ensure that it is well insulated from the surrounding.
  5. Solder the ESC I/O to the PWB well and paste insulation tapes on the soldered ends.
  6. Now attach the ESCs in the frame and zip tag them well.
  7. Here at step 6, ensure that the direction of the wires (+, -, ~) are correct according to the manual since this could change the direction of the motor spinning.
  8. Connect the motors to the other end of the ESCs I/O.
  9. Assemble the pixhawk above the PDB and connect the wires from the PDB.
  10. Post that, connect the wires from the lidar to the SPI of pixhawk (check the following figure).
  1. Connect the Receiver to the pixhawk.
  1. After connecting, try to bind the receiver and transmitter.
  2. Long press the button on the receiver and bind the transmitter by putting the transmitter in the binding mode.
  3. Connect the raspberry pi to pixhawk in telem 2

Set up the configuration by following the following link : https://ardupilot.org/dev/docs/raspberry-pi-via-mavlink.html

  1. Connect the Neo 8M GPS and mount it higher than the drone surface to prevent it from any potential electrical interference.

Step 3: Calibration and setting up

Post assembling the drone, start installing the mission planner or QGC to set up and configure the drone. Follow the instructions in the links below.

Baud rate: 115200

Post the proper setup , and verify this by monitoring the status in the mission planner tab.

Post this, perform :

  1. ESC Calibration
  2. Compass Calibration
  3. Frame type configuration
  4. Accelerometer calibration
  5. GPS calibration
  6. Motor Testing
  7. Transmitter and Receiver channel overrides.

Follow this link to perform the above step by step : https://ardupilot.org/copter/docs/configuring-hardware.html

Step 4: Set up fail safe mechanisms

  1. Set up the channel 8 or 7 as a fail safe in the transmitter and set the corresponding command as the Return to land and if that fails to immediate disarm
  2. Set up the same in do while loop in the code which would work via the mavlink by using vehicle.rtl() , vehicle . disarm().
  3. Ensure that both the fail-safe methods work when the communication is lost as well and in fact that fail-safe gets triggered when the communication fails.

Step 5: Software Configuration

We use the drone kit API to call the pre-built functions to control the drone autonomously. This is well supported with the APM and px4 framework we typically use and has great community support as well.

https://dronekit.io/ — Had the detailed documentation.

We customized the code that we would need for our purpose. The link to the code file with detailed comments : Link

Step 6: Battery

The most important thing concerning the battery is to ensure that the minimum voltage per cell doesn’t drop below 2.7 V. This means if you are using a 4S battery, it should not drop below 4 * 2.7= 10.8 volt.

If one or multiple cells happen to fall below this temperature by any chance, do not connect or charge the battery normally.

Instead, start the battery mAh/1000 A in NiCD mode and wait till it reached the Number of cells* 2.7 V. Then switch to lipo charging mode.

Caution: This has to be done with care, or else the battery could burst as lipos are prone to catching fire. When not in use, save the battery in the Lipo battery cover always even while charging.

Quick points to remember:

Important checks before take-off:

  1. Reboot after making any changes to the parameters in the mission planner or the code.
  2. Ensure to flush the previous code always.
  3. Check if you are using lidar in SPI or i2c and configure the “advanced params” accordingly — for instance, the address of the i2c bus
  4. Check if the propellers are in the right direction and orientation
  5. Check if the batteries have full charge if you have not connected the battery power monitor (if the charge is below the minimum threshold, follow the instructions in the battery section)
  6. Do a motor test via QGC/Mission planner before every flight
  7. Do not turn off any pre-arm checks until unless necessary
  8. Check GPS and compass alignment before every flight in the mission planner or QGC
  9. The ability to remove the Lipo in case of emergency is crucial
  10. Ensure the battery is charged before Take off, each cell should not fall below 2.7 V
  11. Check if the RC is connected before every flight
  12. Always have drone kit in guided mode while performing a mission until unless you need a specific mode
  13. Ensure that an RC channel is configured to change the flight mode
  14. Check the right Frame of reference while entering altitude (for eg: In the NED frame positive altitudes are entered as negative “Down” values. So if down is “10”, this will be 10 meters below the home altitude.)

Post this ssh into the raspberry pi and navigate to the drone directory. Run the ‘drone_autonomous_fly.py script’ and monitor the terminal till it takes off.

Modify the code for task-specific navigation.

Other important checks with respect to autonomous flight

DroneKit-Python communicates with vehicle autopilots using the MAVLink protocol, which defines how commands, telemetry, and vehicle settings/parameters are sent between vehicles, companion computers, ground stations, and other systems on a MAVLink network.

Some general considerations of using this protocol are:

  • Messages and message acknowledgments are not guaranteed to arrive (the protocol is not “lossless”).
  • Commands may be silently ignored by the Autopilot if it is not in a state where it can safely act on them.
  • Command acknowledgment and completion messages are not sent in most cases (and if sent, may not arrive).
  • Commands may be interrupted before completion.
  • Autopilots may choose to interpret the protocol in slightly different ways.
  • Commands can arrive at the autopilot from multiple sources.
  • Check calibration before every flight and recalibrate if needed

So we should code defensively :

The best practice is to follow the following launch sequence (during take off):

  • Poll on Vehicle.is_armable until the vehicle is ready to arm.
  • Set the Vehicle.mode to GUIDED
  • Set Vehicle.armed to True and poll on the same attribute until the vehicle is armed.
  • Call Vehicle.simple_takeoff with a target altitude.
  • Poll on the altitude and allow the code to continue only when it is reached.
  • Important: ensure that commands are always cleared before starting a new flight

Why should we do this?

The approach ensures that commands are only sent to the vehicle when it is able to act on them (e.g. we know Vehicle.is_armable is True before trying to arm, and we know Vehicle.armed is True before we take off). It also makes debugging takeoff problems a lot easier.

If low-latency is critical, we recommend you verify that the update rate is achievable and perhaps modify script behavior if Vehicle.last_heartbeat falls outside a useful range.

Sleep script when not needed:

Sleeping your script can reduce CPU overhead.

For example, at low speeds, you might only need to check whether you’ve reached a target every few seconds. Using time.sleep(2) between checks will be more efficient than checking more often.

To avoid prior memory issues that we discussed yesterday:

Scripts should call Vehicle.close() before exiting to ensure that all messages have flushed before the script completes:

If IMU is Needed for other applications:

Use create new attribute functionality

The new class uses the Vehicle.on_message() decorator to set a function that is called to process a specific message, copy its values into an attribute, and notify observers. An observer is then set on the new attribute using Vehicle.add_attribute_listener().

Use cache() to check the values of the sensors only when needed

I appreciate you taking the time to read this. If you have any suggestions or recommendations, please feel free to share them with me.

--

--

No responses yet