Added true airspeed measurement

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download
Post Reply
KaiK
Posts: 58
Joined: Thu Jul 28, 2011 8:32 pm
Contact:

Added true airspeed measurement

Post by KaiK »

Hi guys,

I implemented reading true airspeed (differential pressure) using the MPXV7002 sensor, which is part of e.g. the DIY drones airspeed kit.
I partially orientated on the ardupilot code (averaging, zeroing).
The measured airspeed is transferred in cm/s via debug[3] and MSP_MISC (2nd entry) currentyl. Any GUI/app then can recalculate in m/s, ft/s, km/h, mph etc.

I think this is a nice feature especially for airplane user. In future it maybe can be used for auto-throttle, landing etc...

Just see it as a first shot...
You can find it in my branch: http://code.google.com/p/multiwii/sourc ... hes%2FKaiK

User avatar
Hamburger
Posts: 2578
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: Added true airspeed measurement

Post by Hamburger »

good.
Problem with branches is, they are outdated so fast. From past experience this means you will not get many testers/users, unless you keep that branched version updated over long time. Not desirable, imho.

Can you provide
- the version which you started with and modified
- a diff file

It would then be easier to grasp the changes/additions, estimate possible side effects (if any) and merge into the _shared branch. (Of course, you might do the merge yourself.)
Did you modify the GUI already to take advantage of the new data?

KaiK
Posts: 58
Joined: Thu Jul 28, 2011 8:32 pm
Contact:

Re: Added true airspeed measurement

Post by KaiK »

Thank you for your comments, Hamburger!

I started with Revision 1113, as stated in folder naming. Please see the differences below. Any feedback, especially regarding speed (improvement) and type cast (int -> float -> int) are welcome.

I will add this to shared if some of you give a ok...

I didnt modify the gui, but will do this after adding to shared...

Code: Select all

config.h

849a852,872
>   /********************************************************************/
>   /****                      airspeed sensor                       ****/
>   /********************************************************************/
>   
>   /* Airspeed sensor will initialize in one second on bootup of controler. Take care not letting the wind blow into pitot tube! */
>   
>     #define AIRSPEED              // uncomment this line to activate the airspeed code
>     #define AIRSPEED_PIN A4       // Analog PIN 4
>     #define AIRSPEED_FACTOR 11.96  // Calculation see bottom annotations
>     
>        /* Background for calculation of AIRSPEED_FACTOR
>        v [m/s]= sqrt(2 * roh * delta-pressure[Pa])
>               
>        1 increment (Analog read) = VCC/1024 = 5V/1024 = 0.0048828125 = 0.00488V = 4.88mV
>        Datasheet of MPXV7002: 1 = 1kPa -> 1mV = 1Pa
>        roh(@15 �C, 1bar air pressure) = 1,225 kg/m�
>       
>        -> 1 increment = 4.88mV = 4.88Pa
>        -> v [m/s] = sqrt(2 * roh * delta-pressure[Pa]) = sqrt(2 * roh * 4.88 * AnalogReadIncrements)
>        AIRSPEED_FACTOR = 2 * roh * 4.88
>        */
850a874
>     
993c1017
< /*************************************************************************************************/
---
> /*************************************************************************************************/

MultiWii.ino

170a171,176
> #if defined(AIRSPEED)
> static float airpressureRaw = 0;
> static uint16_t airpressureOffset = 0;
> #endif
> static uint16_t airspeedSpeed = 0; //needs to be set anyway, as it is called in serial communication and therefore needs to be defined.
>
600a607,609
>   #if defined(AIRSPEED)
>     Airspeed_init();
>   #endif
979c988
<     switch (taskOrder++ % 5) {
---
>     switch (taskOrder++ % 6) {
1006a1016,1021
>         break;
>       case 5:
>      #if defined(AIRSPEED)
>         Airspeed_update();
>       debug[3] = airspeedSpeed;
>       #endif



Sensors.ino

1556a1557,1583
> #if defined(AIRSPEED)
> /* Inspired by ArduPilot code. Thanks guys! */
>
> void Airspeed_update() {
>   airpressureRaw = ((float)analogRead(AIRSPEED_PIN) * .10) + (airpressureRaw * .90); //Think about smoothing
>   
>   if(airpressureRaw - airpressureOffset<0) {
>     airspeedSpeed = 0;
>   }
>   else {
>     airspeedSpeed = sqrt((airpressureRaw - airpressureOffset) * AIRSPEED_FACTOR)*100; // m/s * 100 = cm/s
>   }
> }
>
> void Airspeed_init() {
>   /* Reading airspeedRaw for some cycles/1s and storing as zero value */
>   
>   airpressureRaw = (float)analogRead(AIRSPEED_PIN);
>   
>   for(int airspeedI=0; airspeedI < 50; airspeedI++){
>     delay(20);
>     airpressureRaw = ((float)analogRead(AIRSPEED_PIN) * .10) + (airpressureRaw * .90); //Think about smoothing
>   }
>   airpressureOffset = airpressureRaw;
> }
>
> #endif

Serial.ino

46c46
< #define MSP_MISC                 114   //out message         powermeter trig + 8 free for future use
---
> #define MSP_MISC                 114   //out message         powermeter trig + Airspeed + 7 free for future use
375a376
>      serialize16(airspeedSpeed);

timecop
Posts: 1880
Joined: Fri Sep 02, 2011 4:48 pm

Re: Added true airspeed measurement

Post by timecop »

unified diff is much easier to read and apply manually

User avatar
Hamburger
Posts: 2578
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: Added true airspeed measurement

Post by Hamburger »

KaiK wrote:I started with Revision 1113, as stated in folder naming.

my bad :)
Not to say I know how to code well, but for the MWii project Alex has stated some guidelines like
- avoid float if possible
Also the loop with delay() for initialization, cannot this happen automagically when power attached and not yet armed?

Soem possible changes


Code: Select all

config.h
// no float
>     #define AIRSPEED_FACTOR 1196  // Calculation see bottom annotations



// no float
>   airpressureRaw = (analogRead(AIRSPEED_PIN) * 10) + (airpressureRaw * 90) / 100; //Think about smoothing

// no float, the other *10 is in the sqrt(constant*100)
>     airspeedSpeed = sqrt((airpressureRaw - airpressureOffset) * AIRSPEED_FACTOR)*10; // m/s * 100 = cm/s

Alexinparis
Posts: 1630
Joined: Wed Jan 19, 2011 9:07 pm

Re: Added true airspeed measurement

Post by Alexinparis »

Hi,
Adding a new sensor type might be a good thing.
But the purpose of this sensor needs to be clearly explain before adding code.
I see no interest for a multi rotor.

I suppose it could be useful for fix wing configs and navigation purpose.
To my mind, a code prototype of the final purpose should exist before merging it in _shared.

PatrikE
Posts: 1976
Joined: Tue Apr 12, 2011 6:35 pm
Location: Sweden
Contact:

Re: Added true airspeed measurement

Post by PatrikE »

It would be perfect for airplanes!
To replace the TPA function with a Speed PA function.

Decreas PID's with speed instead of throttle!

User avatar
Hamburger
Posts: 2578
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: Added true airspeed measurement

Post by Hamburger »

I think having your speedgun onboard is cool for multicopters too.

User avatar
Quadraf
Posts: 68
Joined: Fri Jan 21, 2011 12:55 am
Location: Deurne Holland
Contact:

Re: Added true airspeed measurement

Post by Quadraf »

uhmm... speed in cm/sec. Does this mean one can create in conjunction with other sensors (zero speed) non drifting multicopter? That would be great 8-)

copterrichie
Posts: 2261
Joined: Sat Feb 19, 2011 8:30 pm

Re: Added true airspeed measurement

Post by copterrichie »

Well, the copters can move sideways and backwards, don't believe forward speed will help in these situations.

Sebbi
Posts: 478
Joined: Sun Jul 08, 2012 1:08 am
Location: Germany
Contact:

Re: Added true airspeed measurement

Post by Sebbi »

You just need four of those sensors ;-)

KaiK
Posts: 58
Joined: Thu Jul 28, 2011 8:32 pm
Contact:

Re: Added true airspeed measurement

Post by KaiK »

I hope Multiwii will be more popular for using with planes in the future and will developed in this direction, too, to get a full "Airdrone suite" :-)
So I think its a interesting sensor, espacially for autothrottle and landing...

User avatar
Quadraf
Posts: 68
Joined: Fri Jan 21, 2011 12:55 am
Location: Deurne Holland
Contact:

Re: Added true airspeed measurement

Post by Quadraf »

6 of them and you get 1 cm drift and 1cm altitude hold. I can live with that :lol:
The question is: who can make such a sensor... :geek:

Sebbi
Posts: 478
Joined: Sun Jul 08, 2012 1:08 am
Location: Germany
Contact:

Re: Added true airspeed measurement

Post by Sebbi »

Quadraf wrote:6 of them and you get 1 cm drift and 1cm altitude hold. I can live with that :lol:
The question is: who can make such a sensor... :geek:


You realize that this would only work with no wind? ;-)

User avatar
Quadraf
Posts: 68
Joined: Fri Jan 21, 2011 12:55 am
Location: Deurne Holland
Contact:

Re: Added true airspeed measurement

Post by Quadraf »

Sebbi wrote:
Quadraf wrote:6 of them and you get 1 cm drift and 1cm altitude hold. I can live with that :lol:
The question is: who can make such a sensor... :geek:


You realize that this would only work with no wind? ;-)



Nope... In that case incapsulate it with foam. ;)

copterrichie
Posts: 2261
Joined: Sat Feb 19, 2011 8:30 pm

Re: Added true airspeed measurement

Post by copterrichie »

Sebbi wrote:
Quadraf wrote:6 of them and you get 1 cm drift and 1cm altitude hold. I can live with that :lol:
The question is: who can make such a sensor... :geek:


You realize that this would only work with no wind? ;-)


GPS reports ground speed. Hmmm.

copterrichie
Posts: 2261
Joined: Sat Feb 19, 2011 8:30 pm

Re: Added true airspeed measurement

Post by copterrichie »

Sebbi wrote:You just need four of those sensors ;-)


Might be able to get away with using two, flying backwards would report a negative number if using a differential pressure sensor. And for the Roll axis, positive right and negative for left. That is, if they can be shielded from the prop wash. ;)

msev
Posts: 186
Joined: Thu Apr 14, 2011 11:49 am

Re: Added true airspeed measurement

Post by msev »

Airspeed sensor would be of great use on fixed wing platforms, so that the plane could "hold" a true airspeed against the wind and not stall... Its quite an essential sensor used in many other projects, now with the recent advances in PatrikE's fixed wing branch I would think it would be cool to have this sensor support.

crashlander
Posts: 506
Joined: Thu May 05, 2011 8:13 am
Location: Slovenia

Re: Added true airspeed measurement

Post by crashlander »

msev wrote:Airspeed sensor would be of great use on fixed wing platforms, so that the plane could "hold" a true airspeed against the wind and not stall... Its quite an essential sensor used in many other projects, now with the recent advances in PatrikE's fixed wing branch I would think it would be cool to have this sensor support.

+1

Mentioned, discussed, wanted many times in Airplane RTH thread...

Regards
Andrej

Sebbi
Posts: 478
Joined: Sun Jul 08, 2012 1:08 am
Location: Germany
Contact:

Re: Added true airspeed measurement

Post by Sebbi »

Agreed ... needs official support. I bought one to try it out ;-)

Post Reply