Shop OBEX P1 Docs P2 Docs Learn Events
Performing Serious equations on the Propeller(Altitude) — Parallax Forums

Performing Serious equations on the Propeller(Altitude)

James LongJames Long Posts: 1,181
edited 2007-05-02 07:28 in Propeller 1
Ok....I have tried....but I'm not sure of my math....or of the implementation of such.

Here is the equation I'm trying to perform...included

Could someone write the equation out.....I'm lost as to how to implement it properly.

James L
·

Post Edited (James Long) : 3/31/2007 7:18:57 PM GMT

Comments

  • ellizardellizard Posts: 106
    edited 2007-03-31 17:29
    HI, James

    Sometimes with microcontrollers it is convenient to treat the data not as math value but as a table reference to point to.

    If for exmple some of that numbers in the eqation where the readings of sensors, given that a sensor has a finite amount of data and a finite precision, it could be worthy
    to relate the readings to a table with the resulting values already in.
    Or even only a part of the eqation could be treated this way...............

    Only reflections on your post............

    Best regards
    Stefano

    P.S. Sometimes dividing the equation into smaller trunks helps.......

    Have a Look at www.emesystems.com/BS2index.htm

    Doctor Tracy Allen done a great job on math with microcontrollers, althoug it's pointed to Basic Stamps, it's useable with other micros, i've used with SX (SX/B).

    Post Edited (ellizard) : 3/31/2007 5:47:19 PM GMT
  • SkogsgurraSkogsgurra Posts: 231
    edited 2007-03-31 18:01
    I am not sure if I have opened your "equation", but if I have, it isn't. All you need to do is calculate the value of h - and as far as I can see, it is about raising 91.035/102.49 to -[noparse][[/noparse](6.5*287.5 /1000)/9.80665] and then mutiply by 15+273.15. After you have done that, you subtract (15+273.15). That's all. No equation. Just reduce your terms and do it. But don't do it in a processor.

    Or is this one point on a curve (looks like an NTC thermistor to me)? If so, where is the variable?

    Anyhow, if you need to do it in the Prop, reduce your coefficients and then use the log table built into the ROM for the exponantiation. Remember that exp is anti-log. So the table mantioned by Stefano is already there for you!
  • James LongJames Long Posts: 1,181
    edited 2007-03-31 19:22
    Stefano,

    I would use a table....if this equation didn't concern Altitude......it is vitally important. So a Table would be huge.

    Skogsgurra,

    This concerns altitude.......and there are actually 3 variables in the equation.

    I haven't used the log table built into the Prop.



    This would be a good thing for Tracy Allen or someone to step in and help with. I'm really lost with this part. I'm using spin and don't know Assembly......so it could be interesting.

    It must be done mathematically in the Propeller......so I must find a way to do it.

    James L
  • SkogsgurraSkogsgurra Posts: 231
    edited 2007-03-31 19:30
    I see no variable. Just a lot of constants? Where are the variables? Is this the ICAO altitude equation?
  • SkogsgurraSkogsgurra Posts: 231
    edited 2007-03-31 19:41
  • James LongJames Long Posts: 1,181
    edited 2007-03-31 19:49
    The variables will be the barometric pressure, the height pressure, and the temperature.

    The math is more of the problem...I just don't remember all the higher end things. I know there is a log in there....and mutiples of multiply and divide.

    The altimeter will never leave the lowest level of the atmosphere.....so I don't have to work with the other equations.

    I have put this into a program.....but it doesn't work.....it gives me strange calculations.....so I know it is not right.

    James L
  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-31 20:07
    First of all, you do have to use floating point, so become a little familiar with the floating point package from the Propeller Object Exchange.
    There already is a power function "Pow(x,y)" is "x" raised to the "y" power. Also, if you have constant expressions like "1.5 / 3.3" or some such, you can use the "constant(a)" compile-time function to evaluate the expression during compilation like "constant(1.5 / 3.3)". This does work for floating point.
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-03-31 20:20
    If something is a variable you should put a letter in the equation not a number otherwise it just represents an instance of the equation.

    float32full contains all the functions required to perform this calculation, multiply, divide and a power.

    If you just want to find h there is no log.

    The best thing to get going is to brake it down into parts and give each part a name, remember that is what the brakets are for doing logically.

    a := Fdiv(p,p1)
    b := Fdiv(Fmul(-a,r),g)

    then I can combine those

    c := Pow(a,b)

    c := Fmul(c,T1)

    To finish off I could just go for broke:

    h := FAdd(FDiv(FSub(c,T1),a),h1)

    Now I have not checked this and don't intend to. If its a matter of remembering the higher end things then look them up and don't just wait for Tracy to do the work for you.

    Graham
  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-31 20:22
    Try this
    CON
      R = 287.05  ' Ideal gas constant (Joules per kg per degree Kelvin)
      g = 9.80665  ' Acceleration due to gravity (meters per second squared)
      T1 = 15.0  ' Starting temperature of region (degrees Centigrade)
      h1 = 0.0  ' Altitude constant for region (lower troposphere - Table 2)
      p1 = 101325.0  ' Pressure constant for region (lower troposphere - Table 2)
    
    PRI height_calculation(p,a)
      return FAdd(FDiv(FSub(FMul(Pow(FDiv(p,p1),FMul(constant(-R/g),a)),T1),T1),a),h1)
    
    
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-03-31 20:32
    Yes I get the same if I substitute my simpler equations (excluding the clever R/g constant).
  • James LongJames Long Posts: 1,181
    edited 2007-03-31 21:03
    Graham, Mike,

    Very interesting.....this is very similar to what I have......but different. I didn't use the constant method.

    I'll try Mikes version to see if I'm still getting the strange results.

    i know my pressure and Temperature is correct, as I'm displaying them in raw form.

    Let me check and see where the differences lie.....and see what I'm doing wrong.



    James L
  • Tracy AllenTracy Allen Posts: 6,660
    edited 2007-03-31 21:12
    Hi James,

    The stuff I've done for the Stamp is an effort to do things with integer math. For altitude calculations from pressure, I resorted to a table lookup using a standard atmosphere, followed by stratigically placed corrrections for measured values. Excel is a big help in this kind of exploration, to try out the effect of different approximations and to generate DATA tables for use with the microcontoroller.

    There are lots of resources on the web about barometry in different contexts. I still have trouble understanding the assumptions underlying altimeter settings, but it is important to remember that altimeter settings as such developed from a much cruder technology, aneroid barometers, which as beautifully as they may be constructed, are not capable of complex calculations.

    I've found lots of helpful information from the Portland State Aerospace Society, and this tutorial:
    psas.pdx.edu/PSAS/RocketScience/PressureAltitude_Derived.pdf

    The statement "I would use a table....if this equation didn't concern Altitude......it is vitally important." is a concern. Yes, but the caveat is that the equation that you have there also has HUGE assumptions behind it. For example, the lapse rate (rate of change of temperature with altitude, approximated as -6.5 degrees Celsius per Kilometere) is not only variable from day to night, but in reality it varies dynamically with altitude. Lacking a cloud of smart dust sondes to actually probe the atmosphere, we will not know enough to make a really accurate thermodynamic altitude determination. So whatever equation or table you come up with, it can indeed be useful, but should never become too much "vitally important".

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-31 21:24
    James,
    I didn't check to see if the units are correct. That's always a great way to check an equation (plug them into the equation and see if they come out correctly).
  • James LongJames Long Posts: 1,181
    edited 2007-03-31 22:19
    Tracy,

    Yes you have a point......there are things that are not totally expressable in the equation. Or for that matter...any equation.

    I'm downloading the pdf you reference. It may help me understand more of what is behind the equation.

    I have done a lot of research(internet reading)....but most of it is extremely complex......and very "high end".

    I think Mike Green's help put the equation in the correct syntax, but i will have to research the values of the equation. (BTW it seems to be pretty accurate accoring to my information, although testing will tell.

    I do appreciate the help Mike....and may hav eone other equation to help "sort" out. ( it is the airspeed equation)

    But thanks to all who have helped.......Tracy thanks for the resource....I'll try to make head or tails of it.

    James L
  • James LongJames Long Posts: 1,181
    edited 2007-03-31 22:22
    Oh...and also on a side note.....anyone who is considering using the VTI SPC1000 series pressure chip....I highly recommend it. It is extremely accurate...and very easy to use once the programming is written correctly. It was a major pain to hand place for reflow......( had one I messed up) but if you can get it on straight....it works well.

    James L
  • Tracy AllenTracy Allen Posts: 6,660
    edited 2007-04-01 04:40
    I empathize about the "high end" complexity of these analyses--They quickly get into water vapor content, parital pressures, and the partial differential equations. All that, albeit refined, and it is still just a model. But even the simple model can be just as practical.

    There are the responses to a question a professor somewhere asked about how to use a barometer to measure the height of a tower. Among them were, "throw it out the window and time how long it takes to hit the ground", and "attach it to a string, let it out until it touches the ground, and measure the string".

    You said, "The altimeter will never leave the lowest level of the atmosphere...". Could that mean only up to the stratosphere, and no more than twice the height of Mt. Everest, or could it mean nothing higher than Denver? It is most important to consider how to deal with calibration points. For example, how you enter sea level temperature and pressure, and what you do when you pass a marker that you know to be true, say, 1000 meters.

    Readings can be great for a short trip over a short time interval, but I have never been happy with a barometric alitimeter on a backpacking trip. Conditions change too fast. It is fine when you reach certain landmarks like a lake and you can use that to reset for the next stage of a trip. But is is frustrating when you arrive at a lake and the instrument is substantially off what you expect. Is it the right lake?! Am I lost? (Okay, GPS!)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • James LongJames Long Posts: 1,181
    edited 2007-04-01 14:01
    Tracy,
    I empathize about the "high end" complexity of these analysis--They quickly get into water vapor content, parital pressures, and the partial differential equations. All that, albeit refined, and it is still just a model. But even the simple model can be just as practical.
    I actually have two things working against me when dealing with an equation like the above listed. First I did not pay attention in high school ( I admit....it was my fault....and hard to fix) I didn't go to college.......Two I'm not the most versed programmer.......so that is why I value the forums so much.

    I can decipher most anything....but I get paralyzed trying to get it to work sometimes.

    I'm not complaining.....or giving excuses.....just the simple fact. I'm self taught (with others help) so I incur obstacles sometimes. Most people here I find are similar in nature....so I think it is great.
    There are the responses to a question a professor somewhere asked about how to use a barometer to measure the height of a tower. Among them were, "throw it out the window and time how long it takes to hit the ground", and "attach it to a string, let it out until it touches the ground, and measure the string".
    Yep......best way.......but I think that would be difficult in a large amount of situations......and definitely has no "neat" factor.

    But I do remember that expression.
    You said, "The altimeter will never leave the lowest level of the atmosphere...". Could that mean only up to the stratosphere, and no more than twice the height of Mt. Everest, or could it mean nothing higher than Denver? It is most important to consider how to deal with calibration points. For example, how you enter sea level temperature and pressure, and what you do when you pass a marker that you know to be true, say, 1000 meters.
    It will never leave the Troposphere........I sometimes do not express things in·the correct manner. Mike can vouch for that.
    Readings can be great for a short trip over a short time interval, but I have never been happy with a barometric altimeter on a backpacking trip. Conditions change too fast. It is fine when you reach certain landmarks like a lake and you can use that to reset for the next stage of a trip. But is is frustrating when you arrive at a lake and the instrument is substantially off what you expect. Is it the right lake?! Am I lost? (Okay, GPS!)
    I agree.....there are problems with most things like an altimeter. There· is no perfect way to do it......but I do appreciate your insight to the situation. I know you deal with a large amount of projects like this.


    Thanks for all the discussion........I'll let you know how I fair.

    James L

    Post Edited (James Long) : 4/1/2007 2:08:11 PM GMT
  • James LongJames Long Posts: 1,181
    edited 2007-04-02 04:28
    OK.....I have faired (to what i believe) pretty well.

    I have some questions about the possibility of integrating Temperature into the above equations.

    The SPC 1000 gives me the current temperature (at whatever altitude it is currently at)

    Since i will never be a calculation wiz.....could that be integrated to help with accuracy.

    I've looked over the PDF file Tracy linked.....and my current formula is somewhat different than that listed in the PDF.

    I know there are multiple ways of calculating any situation, I just want to lessen the error as much as possible.



    Any suggestions or thoughts?



    James L
  • rjo_rjo_ Posts: 1,825
    edited 2007-05-02 03:48
    James,

    What's up?

    I read your comments about being self taught... and looked at your current interests and I just had to say something.

    Even people who go to college are essentially self taught... No-one can cram something into another persons brain.
    Fortunately, we have some natural teachers who are willing to jump in.

    The general comments in this thread about models are really important. It doesn't matter if you understand the math or not... what matters is that no-one ever seems to state the underlying assumptions that they use to create a mathematical model.

    I think what Tracy was essentially saying...but also trying not to bust your balloon... was that even if you went for a deeper mathematical model... one with fewer assumptions (more variables... and more logic) you would probably still end up with a mathematical model that couldn't be depended upon.

    One of my best friends was physical chemist and a teacheer... and he loved to pick apart "laws"... the gas laws for instance ... really don't apply to anything very interesting... they are nice.. but they are also wrong. One of the things that you gain from a formal education...is a natural instinct for how much we don't know... and when you see something like a three variable model for an altimeter... you know it isn't going to work... nothing in nature is actually that simple.

    Why not GPS?... Bean from Hitt consulting has a nice board coming out that will let you do both GPS and video overlays and with a slightly illegal transmitter (which I am sure everyone would be more than interested in helping you with[noparse]:)[/noparse] you could beam back live data with a picture of Mother Earth in all Her Glory.

    Rich
  • rjo_rjo_ Posts: 1,825
    edited 2007-05-02 04:06
    James,

    The other thing... I once studied how to use a contact lens lathe...to reshape the cornea. The inventor of the technique used a little program to set up everything on the lathe... and the "computer" was a programmable Texas Instrument Calculator... There were at least 13 variables (I forget exactly).

    Just for the fun of it, I put all of the interconnected calculations into a single formula... which covered the front and back of a 4X6 blackboard... I've never seen a bigger equation... ever.

    If someone gave that equation to a mathematician... it would take him a couple of hours to untangle the exact meaning and write another program to do the same thing... Maybe less. Without a lot of practice and study... and equation in that form would be meaningless to just about everyone.

    But to understand the equation... you just had to understand the instructions on a Texas Instrument Calculator...each step was really simple.

    1. You can actually write simple programs... which cannot be easily expressed mathematically.

    2. At the core of every complicated looking equation... there is one or more very simple ideas... figuring out what those ideas might be can be very, very difficult. But with the internet and a little persistance, the average person can now figure out just about anything... if they stick to it.

    Never give up.


    Rich
  • Capt. QuirkCapt. Quirk Posts: 872
    edited 2007-05-02 04:36
    I know this is a month old, but I am curious too.

    After reading the entire thread' I don't understand why you didn't use the formulae for "Density Altitude" instead?.
  • James LongJames Long Posts: 1,181
    edited 2007-05-02 06:09
    Rjo,

    I'm sorry....somehow I missed the postings on this.

    The reason I do not use GPS.....GPS can be off as much as 50 meters. If you read any GPS infomation....the altitude is the hardest part for any GPS to get right. I need the unit to be much closer.

    I know I can include more variable with true data to make the calculation be closer to·true altitude. I also know there will be a point of negative return. (The time spent will not warrant the minute change of accuracy.)

    I was just trying to get the altitude display to work partially....which it does....but there is still some problem which alludes me.

    Capt,

    I was looking for the basis for altitude...and got the equation to work some what.

    I still haven't totally figured out what is going on. I can get a pretty stable reading....(if my·altitude and barometric·are pretty close .....about 250 ft of difference.)

    But if the pressures·are around 800 ft of difference......the reading bounces all over the place. The altitude reading....not the pressure reading.

    I've had to do some redesign of the unit....so I haven't revisited the equation.

    I don't understand the bounce......600 ft of difference between the readings shouldn't make the altitude reading bounce so much. The curve is not that steep. I understand the curve gets steeper as pressure decreases......but I'm at a loss on this problem at the moment.

    I'm currently using the version Mike posted....but like I said....I'm having a severe bounce. I don't think it is any thing with the equation, just my implementation of it.

    This was an evolution situation. I wanted to get a stable reading first....

    I was also worried, that I didn't understand the math....which seems not to be the case. I was performing the math correctly, as was shown with Mike's formula......that is why I'm still baffled.



    James L


    Post Edited (James Long) : 5/2/2007 6:22:15 AM GMT
  • Capt. QuirkCapt. Quirk Posts: 872
    edited 2007-05-02 07:28
    James,

    I figured out you were looking for a baseline, so I was going to erase the thread. But you saw it before I could.

    I mentioned the Density Altitude because I use it to make jetting changes to what ever we are racing with. In California, sometimes I need 5 different carb jettings to be competitive·thru-out the day. On a normal hot day I'll see a 4500' change in altitude between morning and aprox. 2:00 pm, and the pressure drops to the low 29's (I use absolute pressure so the pressure @sea level and 65' is 29.92 or 29.93 at whatever humidity?)

    On a day that there is in area of high pressure in the upper atmosphere I'll get readings in the low 27's. This is why I was wondering about that equation.(I noticed it didn't require a pressure input)

    Is the difference you are talking about, the difference between the baseline calculations and actual pressure readings?

    Bill

    I found this page while I was searching for something else http://www.jbgizmo.com/page27.htm·It might help

    Post Edited (Capt. Quirk) : 5/3/2007 6:13:18 AM GMT
Sign In or Register to comment.