Shop OBEX P1 Docs P2 Docs Learn Events
Math coprocessor Help — Parallax Forums

Math coprocessor Help

Brian CarpenterBrian Carpenter Posts: 728
edited 2005-09-09 14:34 in General Discussion
to figure the heading from one location to another there is a formula.

cos(D) = sin(latB)·sin(latA) + cos(latB)·cos(latA)·cos(lonB - lonA) sin(latB) - sin(latA)·cos(D) cos(C) =
cos(latA)·sin(D)A - origin B - destination D = angular distance along path C = true bearing from the origin to the destination measured from north. If the value for sin(lonb - lona) is positive; otherwise, the true bearing is 360° - C. If latA is 33.980222 in degreesand LonA is 111.447331and latb is 33.031375and lonb is 111.386647·i made the code for the coprocessor but i can not store these variables in the BS2. to big and floating point. any pointers?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


It's Only A Stupid Question If You Have Not Googled It First!!

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-09-09 01:23
    Are these variables, or are they constants? Or... are you reading them from a GPS unit? If the latter, you're in luck because many math coprocessors will accept a text string and convert it to a float for you. You'll have to have the coprocessor convert back to fixed point for you if you need to use the values in your code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Brian CarpenterBrian Carpenter Posts: 728
    edited 2005-09-09 01:31
    latA and lonA will be variables form the GPS. latB and LonB will be constants from waypoints that i program in.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    It's Only A Stupid Question If You Have Not Googled It First!!
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-09-09 01:38
    Should be no problem then, as the constants in your program can be stored as strings and converted by the FPU.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Brian CarpenterBrian Carpenter Posts: 728
    edited 2005-09-09 01:39
    please shed some light to me as storing as STRING

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    It's Only A Stupid Question If You Have Not Googled It First!!
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-09-09 01:45
    You can do it like this:

    LatB··· DATA··· "33.031375", 0
    LonB ·· DATA··· "111.386647", 0

    ... but then you need a subroutine to iterate through the characters to send them to the FPU.· It's probably best just to embed them into setup statements that go directly to the FPU.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Brian CarpenterBrian Carpenter Posts: 728
    edited 2005-09-09 01:53
    can you point me in a direction to understand how to do this? sorry, i have really been able to understand all the other things and just need to understand this to.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    It's Only A Stupid Question If You Have Not Googled It First!!
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-09-09 01:58
    What FPU are you using? The docs for it should explain who to convert text to floats.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Brian CarpenterBrian Carpenter Posts: 728
    edited 2005-09-09 01:59
    the one that is on the parallax website. i have been using the IDE to program it. can what you are talking about be done through the IDE

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    It's Only A Stupid Question If You Have Not Googled It First!!
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-09-09 02:17
    Well, there are others available so I had to ask.· You really need to read through the documentation carefully -- it's not easy, I admit that.· But what you don't want to have to do is reprogram the FPU any time you change the fixed waypoint.

    Luckily, the FPU generates BS2 code for you to plug into your programs.· See the attached images.

    1. Define float registers for your values
    2. Assign values to them
    3. Click "Compile"
    4. Copy text from "Output" tab and paste into your program

    The other thing to do is download and study the App Notes on the MicroMega web site -- they are very informative.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    709 x 531 - 62K
    709 x 531 - 85K
  • Brian CarpenterBrian Carpenter Posts: 728
    edited 2005-09-09 02:28
    so you think that it might be possible to send this info into the coprocessor via data. for the variable latA and lonB

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    It's Only A Stupid Question If You Have Not Googled It First!!
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-09-09 02:34
    See the example above (with FPU IDE screen shots) for a cleaner way to do it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Brian CarpenterBrian Carpenter Posts: 728
    edited 2005-09-09 14:26
    jn, i have looked over the examples for several hours last night. i dont understand what the compiler is doing with the number. i dont understand what it is that it is converting it to. I will need to figure it out in orerder to get my variables into the BS2 program.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    It's Only A Stupid Question If You Have Not Googled It First!!
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-09-09 14:34
    The compiler is converting the FP value to the IEEE format used internally (though not compatible with the BASIC Stamp). That's why the IDE is so useful, it takes care of that kind of scut work for us (I don't want to have to know how engines work to drive my car). Now, there are also subroutines in the standard template that will convert strings to FP numbers so that you can use incoming data from your GPS. I'm not saying that it will be super simple, but I know that it is possible.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.