LSM9DS1 and balancing math

2»

Comments

  • I have been using a spreadsheet to verify the calculations so far. I will dig out one of my P1 boards when I get back from work, run the code you have posted, and list the results for each step to see where things go off the rails.
    In science there is no authority. There is only experiment.
    Life is unpredictable. Eat dessert first.
  • kwinn wrote: »
    I have been using a spreadsheet to verify the calculations so far. I will dig out one of my P1 boards when I get back from work, run the code you have posted, and list the results for each step to see where things go off the rails.

    Well, that was a bit optimistic. Got the board connected, copied your posted code, and found I was missing several of the objects you used. Downloaded the ones I needed and started modifying the code so I could substitute keyboard input for accelerometer readings. Looks like it will take another evening or two to finish.
    In science there is no authority. There is only experiment.
    Life is unpredictable. Eat dessert first.
  • Here is the current code with all accompanying files.
  • Thanks, that will help. Will get to it asap, but inevitably, as soon as you start a project other more urgent tasks come along. At least the weekend is not too far away.
    In science there is no authority. There is only experiment.
    Life is unpredictable. Eat dessert first.
  • I appreciate it, I'm at a wall trying to figure this out
  • Jwolf wrote: »
    I appreciate it, I'm at a wall trying to figure this out

    Unfortunately I am now in Edmonton trying to get a customer's equipment running, and it looks like I may be here for a few more days.
    In science there is no authority. There is only experiment.
    Life is unpredictable. Eat dessert first.
  • hate to bug ya, hopin youll have lil time soon tho :)
    I have tried everything... cannot find any other obex for atan2, the one I have does not produce the results it should... online atan2 calculators do produce correct results though.

  • dgatelydgately Posts: 1,074
    edited 2019-02-13 - 21:17:47
    The FME object in OBEX appears to give a good result (I think!)... Seems to almost match the result I get compiling a C program on my macOS system.
    CON
            _clkmode        = xtal1 + pll16x
            _xinfreq        = 5_000_000
    OBJ
            term    : "FullDuplexSerialPlus"
            fp      : "FloatString"
            ff      : "FME"
    VAR
      long ax, ay
    PUB start | i
      'start the terminal
      term.startPST(115200)
      'print startup 
      term.str(string("Float atan2 Demo...",13))
    
      fp.SetPrecision(3)
      term.str(string("PI Ratio (180 / PI): "))
      term.str(fp.FloatToString(ff.FDiv(180.00, PI)))
      term.Tx(13)
    
      ax := -7    ' test integer inputs, could be floats returned from other functions
      ay := 7
      
      term.str(string("Radians: "))
      term.str(fp.FloatToString(ff.atan2(ff.FFloat(ay), ff.FFloat(ax))))
      term.Tx(13)
     
      term.str(string("Degrees: "))
      ' must use FDiv to multiply PI ratio by atan2 result (i.e. don't use '*')
      term.str(fp.FloatToString(ff.FMul(ff.FDiv(180.0, PI),ff.atan2(ff.FFloat(ay), ff.FFloat(ax)))))
      term.Tx(13)
    
    Displays:
    Float atan2 Demo...
    PI Ratio (180 / PI): 57.3
    Radians: 2.36
    Degrees: 135
    
    C code:
    #include <stdio.h>
    #include <math.h>
    #define PI 3.14159265
    
    int main () {
       double x, y, ret, val;
       x = -7.0;
       y = 7.0;
       val = 180.0 / PI;
    
       ret = atan2 (y,x) * val;
       printf("The arc tangent of x = %lf, y = %lf ", x, y);
       printf("is %lf degrees\n", ret); 
       return(0);
    }
    Result:
    $ ./a.out 
    57.295780 ratio
    The arc tangent of x = -7.000000, y = 7.000000 is 2.356194 radians
    The arc tangent of x = -7.000000, y = 7.000000 is 135.000000 degrees
    

    dgately
    Livermore, CA (50 miles SE of San Francisco)
  • Jwolf wrote: »
    hate to bug ya, hopin youll have lil time soon tho :)
    I have tried everything... cannot find any other obex for atan2, the one I have does not produce the results it should... online atan2 calculators do produce correct results though.

    Sorry, still in Edmonton. Hate to start helping someone and then let them down. Hoping to resolve it soon and get back home, but it has already taken way more time than anticipated. Now trying to find a vacuum leak on the system that has 80+ potential leak prone areas and no quick way to locate the culprit.
    In science there is no authority. There is only experiment.
    Life is unpredictable. Eat dessert first.
  • JwolfJwolf Posts: 31
    edited 2019-02-16 - 04:27:11
    dgate... can you help with finding the FME obex? Im not sure what FME is an acronym for and nothing shows up when searching 'FME'
    doh nm... it was included with the mpu-9150 driver :)
    Ill give it a try!
  • JwolfJwolf Posts: 31
    edited 2019-02-16 - 04:51:47
    kwinn, u workin on a plc system?
    for a pressurized link, use soapy water and look for bubbles....
    for vacuum, use a rubber bulb with baby powder or chalk... if too windy / not poss... use a simple vacuum gauge on each tube till u find the leak.

    Im available for contract help :blush:
  • JwolfJwolf Posts: 31
    edited 2019-02-16 - 07:03:30
    dgately: It works! Beautifully!
    I'm getting a +/- 180deg result, and I was able to free up 2 cogs :)

    So what I'm seeing is: the result of atan2(x,y) needs to be multiplied by the results of (180/pi)
    Online Atan2 calculators seem to automatically include this
  • Jwolf wrote: »
    dgate... can you help with finding the FME obex? Im not sure what FME is an acronym for and nothing shows up when searching 'FME'
    doh nm... it was included with the mpu-9150 driver :)
    Ill give it a try!

    "Float Math Extended" http://obex.parallax.com/object/710
    Infernal Machine
  • Jwolf wrote: »
    kwinn, u workin on a plc system?
    for a pressurized link, use soapy water and look for bubbles....
    for vacuum, use a rubber bulb with baby powder or chalk... if too windy / not poss... use a simple vacuum gauge on each tube till u find the leak.

    Im available for contract help :blush:

    No, it's not a PLC system, it's an ARL Spectrometer (3460 metal analyzer). Customer left it on the foundry floor exposed to large temperature and humidity changes for several weeks. Not a good thing to do to an instrument with delicate optics and electronics.

    On top of that they replaced a plastic fitting with a brass one that created a short and damaged the source electronics. This is a 30 year old instrument so a lot of the parts are now obsolete, and I had to find suitable replacements for them. Took a lot of time and searching.

    Now I just have to find the leak(s) that are preventing the optical chamber from getting down to the 10-20 millitorr range it needs for proper operation. Replacing "O"rings on a total of 87 possible leak sites today, then pump down overnight and hope for a good vacuum.
    In science there is no authority. There is only experiment.
    Life is unpredictable. Eat dessert first.
  • Jwolf wrote: »
    So what I'm seeing is: the result of atan2(x,y) needs to be multiplied by the results of (180/pi)
    Online Atan2 calculators seem to automatically include this
    Yes, that calculates degrees from radians...

    Glad it worked!
    Livermore, CA (50 miles SE of San Francisco)
  • JwolfJwolf Posts: 31
    edited 2019-02-17 - 05:25:25
    kwinn, sounds like a fun job if u ask me :)
    I worked with lasers for years, got undercut by china tho and biz tapered so had to shut down.
    please let me know if theres any work or components you need outsourced, i still have stock of dichroics, splitters, collimators, drivers and at least 200 diodes (IR & visible)... i design and cnc my own psu's & ttl/analog modulation drivers.
  • So now that I'm getting a usable value, I need to simply control the flight surfaces, which I plan to do with servos.
    I need a servo with a decent response time and indexing... being able to accurately position the servo right on startup is important to me.
    What kind of servo do I need? I have a few analog servos, but they do not have any feedback on position (that i know of)
    do I need something like a digital coreless?
  • Jwolf wrote: »
    kwinn, sounds like a fun job if u ask me :)
    I worked with lasers for years, got undercut by china tho and biz tapered so had to shut down.
    please let me know if theres any work or components you need outsourced, i still have stock of dichroics, splitters, collimators, drivers and at least 200 diodes (IR & visible)... i design and cnc my own psu's & ttl/analog modulation drivers.

    I guess it is fun for some definitions of fun. Definitely a challenge. Good to see that you solved your challenge with the balancing math.

    Appreciate the offer of parts and help, but the optical and electronics problems have been repaired. All I need to do now is solve the poor vacuum problem. It could be a leak, bad pump, bad pressure gauge, or a final electronics failure. Will tackle that in the morning.
    In science there is no authority. There is only experiment.
    Life is unpredictable. Eat dessert first.
  • so would you say... that job sucks? waka waka ;)
  • LOL - Taking in to consideration that I am stuck in a motel room when I am not working, and that the local temperature varies from -17C and -30C, yes, this job sucks any way you look at it.
    In science there is no authority. There is only experiment.
    Life is unpredictable. Eat dessert first.
Sign In or Register to comment.