Programming Autonomous Arduino Quadcopter

Hello All!

I'm building an autonomous Arduino quadcopter. I'm using an Arduino Nano RP2040 Connect (with accelerometer), 4 drone motors, 4 drone ESCs, and an I2C GPS module.

For my first test, I want the drone to hover at a set height (for example 2m/6ft). I plan on using the GPS for altitude and the accelerometer to stabilize the quadcopter.

My programming question is that I am not sure how to get started writing this code. I have some experience with programming and Arduino, however I'm still stumped on how to get started with this challenge. Can anyone offer me knowledge/guidance or point me in the right direction?

I'm almost done building the drone and I think that these basic autonomous manuvers would be awesome!

-Bob

ALWAYS begin with the simplest part. That would be the ESCs. control one and then two and then 4, independently. Then the GPS., Then the accelerometers.

GPS altitude is very poorly determined, several times worse than the horizontal accuracy. Expect errors of up to 50m or worse, depending on satellite configuration, obstructions, etc.

Edit: Garmin is even more pessimistic, worse than my experience! Maybe they are trying to avoid lawsuits.

GPS elevation readings from your Garmin device are a good tool for approximating elevation when you are unsure of the actual current elevation.

Accuracy of GPS Elevation

Elevation calibrated by GPS is accurate to +/-400 feet with a strong GPS signal.

Thank you for your points. I didn't think the GPS would be that inaccurate? If so, then how come my DJI Mavic Drone can hover perfectly? Different kind of GPS?

I might just try pointing an ultrasonic sensor downward and try hovering at only a few feet in range of the sensor. If I try this, how would the closed loop feedback system work. The first challenge is to use the accelerometer to keep the drone stable... Would this just be a bunch of functions and if statements or is there a smarter way? I have some coding experience but I am by no means a pro.

Get out your GPS unit and judge for yourself.

Here is a 24 hour recording of the altitude (in feet, points taken every 10 seconds) at an outdoor location near my home, using a typical consumer grade GPS module with a clear view of the sky.

Capture

I think most drones use barometric pressure for altitude. Due to weather conditions, you should calibrate your altitude before each flight.

EDIT:
For very low altitudes (under a few meters), they sometimes use ultrasonic or infrared rangefinders.

writing the code for an autonomius drone from scratch is a very ambigious task.

There are a lot of things to learn:

  • how to use very fast gyroscopic sensors
  • how to use very fast g-force-sensors ( I estimate the standard I2C-IMUs are too slow)
  • how to code cascaded position, velocity, acceleration PID-control algorithms
    (do you at least undestand what PID is?)

How big is your budget for spare-parts after each crash or each fly-away caused by code-bugs while testing autonomious flying?

alternatively
Did you design a crash-proof prototype that can drop out of the sky from any height without beeing damaged?

Do you have signed all insurances and licences for developping your own UAV?
What regulations are valid in the country your living in?

If it is really your dream my words will not discourage you.
If my words make you start thinking maybe doing the same basic thing with a car or a boat will be much easier as controlling the whole thing will be much easier

best regards Stefan

Don’t dismiss the controllers that are out there - very powerful and easier to set up ( some are open source )
You could try one if those to get your flying part right ( eg the automatic bits ), then decide if you want to then build your own.

Have a look what is out there , and any regulations applicable .

Very difficult project …Example , about $12. 100MHz, 32bit processor

Ambitious too.

I'm with @hammy. Get a real flight controller. If you are interested to see the flight control software, there are many good open source projects where you can read the code and see the kind of fun you'd have writing your own.

Google

Betaflight
Ardupilot
Silverware quadcopter

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.