Author Topic: PIC Quadrocopter Stabilization  (Read 8966 times)

0 Members and 1 Guest are viewing this topic.

Offline danielksTopic starter

  • Contributor
  • Posts: 19
  • Country: my
  • Newbie from Malaysia
PIC Quadrocopter Stabilization
« on: July 27, 2011, 08:49:25 pm »
Can anyone teach me how to write the coding for the 3-axis gyro stabilization using PIC microcontroller.  :-\

I'll be using 3 single axis analog gyro from this Murata Gyros
eBay auction: #http://cgi.ebay.com.my/ws/eBayISAPI.dll?ViewItem&item=130541084339

Can anyone tell me what PIC is suitable for my project ? I'll be needing 4PWM output ESC, 4 input for RC receiver module, 3analog input for gyro and 2-3 bi-directional port for other uses.  :-\
 

Offline RCMR

  • Frequent Contributor
  • **
  • Posts: 405
Re: PIC Quadrocopter Stabilization
« Reply #1 on: July 27, 2011, 10:29:52 pm »
That ebay listing goes nowhere (for me).

Make sure you're using a good MEMS gyro otherwise drift will kill you.

The Minsoo Kim (KK) blue boards use cheap gyros and although they work, they drift like mad.

When it comes to processor -- use a big fat 32bit MCU rather than a wimpy 8-bit.  It will make things like Kalman filtering much easier to implement and thus give better results.  You won't have to spend so much time optimizing your code -- just let the grunt of the processor take care of the speed side of things until you're quite a way down the track.

Remember you're going to have to read four PPM inputs and create four PPM outputs.  The standard PWM capabilities of the PIC range don't operate at the 20mS cycle rate that the ESCs will be expecting so there's a bit of interrupt-based coding to be done.  Best to look around and see what other silicon you can find that will deliver the results without too much hard work.

It can be done with an 8-bit PIC but life would be easier with a more powerful architecture.  I built a full fixed-wing GPS-based autopilot using the 18F4550 but I had to do some serious optimization and now I would say "what was I thinking?"


 

Online IanJ

  • Supporter
  • ****
  • Posts: 1686
  • Country: scotland
  • Full time EE & Youtuber
    • IanJohnston.com
Re: PIC Quadrocopter Stabilization
« Reply #2 on: July 28, 2011, 09:09:20 pm »
Hi,

Go over to AeroQuad's website.......it's an open source Arduino based design and as such the code is there for you to see............... http://www.aeroquad.com

It's pretty advanced with the following features:-

3-axis accel.
3-axis gyro.
3-axis mag (optional)
Barometer (altitude)
Telemetry
Altitude hold
Heading hold
Auto descend
GPS (under development)
Aerobatic mode
Several stable modes

Ian.


« Last Edit: July 28, 2011, 09:32:26 pm by IanJ »
Ian Johnston - Original designer of the PDVS2mini || Author of the free WinGPIB app.
Website - www.ianjohnston.com
YT Channel (electronics repairs & projects): www.youtube.com/user/IanScottJohnston, Twitter (X): https://twitter.com/IanSJohnston
 

Offline sacherjj

  • Frequent Contributor
  • **
  • Posts: 993
  • Country: us
Re: PIC Quadrocopter Stabilization
« Reply #3 on: August 01, 2011, 07:12:03 pm »
I would definitely not buck the crowd, unless you have tons of time on your hands.  The Aeroquad software has been a long time in the making.
 

Offline bruce273

  • Contributor
  • Posts: 39
  • Country: gb
Re: PIC Quadrocopter Stabilization
« Reply #4 on: August 01, 2011, 07:39:35 pm »
I'm not sure if a PIC would be up to that, most designs I've seen use the ARM cortex-m3 chips as you require very low latency to control the speed controllers in real time. Most control applications require a multply acumulator in the processor to achieve the correct data rate. You could try the DsPIC if you want to stip with microchip as they would be slightly more suited but I can't tell you of the top of my head whether they will have the IO you require.

I've attatched a link below it's an open source project for a quadrocopter with the source available which should hopefully be some help to understand how something like this is implemented.

http://uavp.ch/moin/Download
 

Offline bruce273

  • Contributor
  • Posts: 39
  • Country: gb
Re: PIC Quadrocopter Stabilization
« Reply #5 on: August 01, 2011, 07:46:22 pm »
My mistake should have read the site properly first  :P, these guys are doing what you want with a PIC16f
 

Offline danielksTopic starter

  • Contributor
  • Posts: 19
  • Country: my
  • Newbie from Malaysia
Re: PIC Quadrocopter Stabilization
« Reply #6 on: August 01, 2011, 07:48:50 pm »
Ya...I did read the UAVP website...and I'm curious about the RC receiver signal which input to the PIC.. I cant find any pins on the PIC that use for that purposes...
 

Offline bruce273

  • Contributor
  • Posts: 39
  • Country: gb
Re: PIC Quadrocopter Stabilization
« Reply #7 on: August 01, 2011, 10:01:06 pm »
they are using pin 13. the rx using PPM only sends a position signal to each of the channels one at a time so they've mixed the signals and programmed the microcontroller to decode what comes in. This would meen you have to use a PPM output RX but fortunatly they are the cheaper ones.
 

Offline danielksTopic starter

  • Contributor
  • Posts: 19
  • Country: my
  • Newbie from Malaysia
Re: PIC Quadrocopter Stabilization
« Reply #8 on: August 02, 2011, 05:08:19 am »
Well.PPM signal is quite hard for me to decode and I have no idea how to code it..Unless I'm using PWM signal and convert it into analog signal using RC circuit and feed into the analog input pin of PIC for every channel.

But it looks that using RC circuit may cause some lag or inaccuracy to the respond..Anyone have any better ideas ?  :D

I'm doing this project for my diploma final year.Duration will be around 4months. My task is just to stabilize the Quad and I dint add other stuff , I scared I might not able to finish it in time.  :-\
 

Offline EEVblog

  • Administrator
  • *****
  • Posts: 38335
  • Country: au
    • EEVblog
Re: PIC Quadrocopter Stabilization
« Reply #9 on: August 02, 2011, 05:33:03 am »
I've been meaning to do a quadcopter design for some time, with some additional feature I don't think have been done before:

1) just use the main rotors for lift and maximum stability (on a very wide arm base), and use two additional propellers to push the copter forward. I'm guessing this would give it a much better stable video platform.

2) Fully autonomous, able to maintain a (rough) height of several meters above the ground, and away from side walls.

3) Have large foam floats on the base for possible water landings

The goal is to have it autonomously navigate a canyon (and film it). hence no GPS reception, little radio reception, and basically start it at the entrance to the canyon and have to come out the other end intact, without having to follow it on the ground (which is hard and maybe dangerous)

Dave.
 

Offline RCMR

  • Frequent Contributor
  • **
  • Posts: 405
Re: PIC Quadrocopter Stabilization
« Reply #10 on: August 02, 2011, 08:31:54 am »
I've been meaning to do a quadcopter design for some time, with some additional feature I don't think have been done before:

1) just use the main rotors for lift and maximum stability (on a very wide arm base), and use two additional propellers to push the copter forward. I'm guessing this would give it a much better stable video platform.
Actually that becomes quite difficult because you'll need a reversing brushless motor controller in order to stop.  Also, you'll still have to provide a mechanism for tilting the copter in order to turn.  Simply yawing by using two forward thrust motors and differential control will see your quad skating sideways instead of changing direction very well -- a bit like a hovercraft is very poor at negotiating turns.

A better way is to do what the Chinese do with the T580 quad and that's to use the accelerometers and gyros to not only provide a stable platform but to also automatically tilt the camera platform to compensate for any tilting of the quad itself.  If you tilt the quad forwards to travel forwards, the stabilized camera platform automatically tilts up so as to ensure the camera remains horizontal.

Quote
2) Fully autonomous, able to maintain a (rough) height of several meters above the ground, and away from side walls.
That's also been done.  Even the cheap T580 has a barometric altitude hold capability and the FyTech 91Q has inbuilt GPS and magnetometer to provide directional hold and position hold.  As for staying away from walls -- there are some cheap Chinese hovering toys that do this too, using either ultrasonics or LED proximity detectors.

Quote
3) Have large foam floats on the base for possible water landings
Haven't seen that yet.

Quote
The goal is to have it autonomously navigate a canyon (and film it). hence no GPS reception, little radio reception, and basically start it at the entrance to the canyon and have to come out the other end intact, without having to follow it on the ground (which is hard and maybe dangerous)
Now you're getting into cruise-missile territory with terrain-following.  Uncle-Sam will kick your arse if he catches you doing that, even though you're an Aussie.  Look at what they did to me for building a cruise missile in my garage!

 

Offline ejeffrey

  • Super Contributor
  • ***
  • Posts: 3859
  • Country: us
Re: PIC Quadrocopter Stabilization
« Reply #11 on: August 02, 2011, 11:11:26 am »
Actually that becomes quite difficult because you'll need a reversing brushless motor controller in order to stop.  Also, you'll still have to provide a mechanism for tilting the copter in order to turn.  Simply yawing by using two forward thrust motors and differential control will see your quad skating sideways instead of changing direction very well -- a bit like a hovercraft is very poor at negotiating turns.

Or an airplane without ailerons.  You need to generate a centripetal force to turn at non-zero forward speed.  Airplanes and rotorcraft do this by tilting their lift surfaces so that the main lift has a sideways component.  You could also do it with additional rotors, but now you would need a total of 8 rotors: 4 on the top, 2 for forward motion and yaw, and 2 to provide the centripital force for turning.  The other options are to completely stop before turning and let the main quad rotor provide small amounts of roll to provide lateral stability, or to "over-turn" and use the thrust rotors to provide the centripetal force, a bit like a vector thrust rocket.  This is probably worse for the camera than the original problem.

Quote
A better way is to do what the Chinese do with the T580 quad and that's to use the accelerometers and gyros to not only provide a stable platform but to also automatically tilt the camera platform to compensate for any tilting of the quad itself.  If you tilt the quad forwards to travel forwards, the stabilized camera platform automatically tilts up so as to ensure the camera remains horizontal.

The key here is that you need gyros, not just accelerometers.  In a properly functioning aircraft, apparent gravity is always down relative to the airframe.  The centrifugal fictitious force, added to gravity should exactly counter the tilt angle with respect to earth.  If not, you are side slipping.  This is a bit annoying with MEMS devices since AFAIK they are all rate gyros, not true gyros. Thus you need some fixed reference to eliminate drift problems.  A magnetometer should do the trick: it will let you tell the difference between a slow balanced turn and straight-and-level flight.

Quote from: EEVblog
3) Have large foam floats on the base for possible water landings

Deployable airbags so you don't have  the aerodynamic drag during flight.   You can use your mouse-trap trigger to deploy them :)

 

Offline bruce273

  • Contributor
  • Posts: 39
  • Country: gb
Re: PIC Quadrocopter Stabilization
« Reply #12 on: August 02, 2011, 07:30:46 pm »
PPM is just a series of pulse where the distance between them determines the position of the servo. To decode it you will just have to time the gap between each falling (though this could be rising) edge of the signal. On a PIC you would do this by using the falling edge interupt on the pin you are inputting the signal into.

While doing this you will need to have a timer running in the background which resets every 6ms (as this is triple the time period of each channel).

In the interrupt routine for the edge detect you will need to pause the timer and take the reading from it and then reset it to zero (or the value required in the reload registers to maintain a timer period of 6ms). Then you will only need to scale the reading from the timer to figure out the position value.
You will also need to have a timer interrupt routine which will let your microcontroller know that the transmission sequence has started again (as there is a time period with no transitions)

There is a reasonable description of PPM transmission on this webpage
http://adamone.rchomepage.com/guide1.htm

That should get the PPM into your micro, you'll have the fun of sorting the PID or whatever control you decide to use after that to keep it stable.  ;)
 

Offline RCMR

  • Frequent Contributor
  • **
  • Posts: 405
Re: PIC Quadrocopter Stabilization
« Reply #13 on: August 02, 2011, 07:36:02 pm »
Or an airplane without ailerons.  You need to generate a centripetal force to turn at non-zero forward speed.  Airplanes and rotorcraft do this by tilting their lift surfaces so that the main lift has a sideways component.  You could also do it with additional rotors, but now you would need a total of 8 rotors: 4 on the top, 2 for forward motion and yaw, and 2 to provide the centripital force for turning.  The other options are to completely stop before turning and let the main quad rotor provide small amounts of roll to provide lateral stability, or to "over-turn" and use the thrust rotors to provide the centripetal force, a bit like a vector thrust rocket.  This is probably worse for the camera than the original problem.
Yep, the T580 simply has two servo outputs that drive the camera platform to compensate for the tilt of the airframe when turning or moving forwards/backwards.  It works really well and requires no extra circuitry.

Quote
The key here is that you need gyros, not just accelerometers.  In a properly functioning aircraft, apparent gravity is always down relative to the airframe.  The centrifugal fictitious force, added to gravity should exactly counter the tilt angle with respect to earth.  If not, you are side slipping.  This is a bit annoying with MEMS devices since AFAIK they are all rate gyros, not true gyros. Thus you need some fixed reference to eliminate drift problems.  A magnetometer should do the trick: it will let you tell the difference between a slow balanced turn and straight-and-level flight.
The problem with a magnetometer is that it also needs some way of determining tilt -- since a measure of compensation has to be applied to the magnetometer reading when it is not perfectly level.  That's fine if the craft is stationary but, as you rightly point out, when in a coordinated turn (due to centrifugal/centripedal force) the craft's accelerometers  will report "level" when in fact it may be at a significant angle of bank.

Most "self-righting" multi-rotor controllers use rate-gyros to handle deviation from level and accelerometers primarily as a method of measuring and compensating for the drift that invariably affects those rate-gyros.  There are gyro-only controller boards but they won't self-right from a deliberately tilted position or when the gyros themselves drift.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf