Shop OBEX P1 Docs P2 Docs Learn Events
Kalman Filter (Working) Small bug - Page 4 — Parallax Forums

Kalman Filter (Working) Small bug

1246

Comments

  • MCopplerMCoppler Posts: 38
    edited 2008-04-23 21:01
    Thanks JWood!
    I think maybe notification isn't working because I didn't get notified either, I just checked and, hey! there's some more messages! Anyways...

    Since you're response I was able to verify that my IMU is working (I just used a volt-meter and checked the pins, the output voltages changes as I rock it around).

    I was also able to figure out my float vs. dec issue and am now outputting responable values.

    However, the MCP3208 though I haven't verified, in fact, I'm a little worried because I took it out and turned it around and plugged in back in and got the same basically constant value of -134.something no matter how I rocked the IMU around. However, I know it's doing someting, because when I took it out completely I got very huge and very small numbers.

    Yeah we plan on mounting to something to absorb vibration. Wind, people, etc. shouldn't be too much of an issue because we have a test stand in the lab and hopefully we can convince the professor to let us just get it to hover instead of flying with GPS and all that.

    Thanks for the info!
  • JWoodJWood Posts: 56
    edited 2008-04-23 21:31
    MCoppler,
    After re-checking "Notify me" I did get notified of your response.

    I'm glad to hear you got your Float and IMU all straightened out. It does sound like your ADC isn't playing correctly. I fried my first chip by not fallowing good practice (keeping the power on while hooking up circuits). They are a relatively cheap IC and very nice so I bought 20 of them at once.

    I hope to hear good news in your next post. You'll need to verify that your ADC is working properly (doesn't sound so) or get a new one. Then you'll be on your way, rock'n and roll'n.

    Jason
    ·· Wood

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • MCopplerMCoppler Posts: 38
    edited 2008-04-24 18:48
    Hello again Jason.

    I ran MCP3208.spin with the IMU disconnected. I had a pushbutton going from 3.3V to pin0. When I ran MCP.Start(14,13,15,0) whether I had the pushbutton depressed or not I repeated got a decimal value of 14. If I changed pin0 to another even pin number I still got 14. When I changed pin0 to an odd pin, say, pin1, I repeatedly got a decimal value of 0 - Does that mean it's fried.

    Where did you get your PID in spin? I found one by Craig Weber that I could't really figure out how to work.
  • JWoodJWood Posts: 56
    edited 2008-04-25 14:46
    MCoppler,
    I believe I see what your problem is. Looking at the picture you took with the MCP3208 you have DIO to PIN 14, CLK to PIN 15 and CS to PIN 13. That MCP3208.spin Object requires you pass the pins in this order: DIO, CLK, CS.

    So, that would be for you: · MCP.Start(14,15,13, %11111111)

    Also, the 4th parameter indicates what pins to enable. The above code enables all 8 pens and MCP.Start(14,15,13, %00001111) only enables the first 4.

    It doesn't sound like your unit is fried just yet. It looks like you have a few code issues.

    Make these modes to your code and give your push button anther go round.

    Good Day
    Jason
    ·· Wood

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • MCopplerMCoppler Posts: 38
    edited 2008-04-25 18:57
    Thanks for the catch JWood.

    Does mode also tell the ADC whether it is single-ended input or pseudo-differential input? Since 1.65V is 0, 0V is -3g, and 3.3V is +3g do you need pseudo-differential input? Or are you taking care of the sign in your KF code?

    Also, I'll be integrating the PID soon. Does anybody know how to use the one by Craig Weber? If not, does anybody know of a good one to use? Thanks.
  • JWoodJWood Posts: 56
    edited 2008-04-25 19:16
    MCoppler,
    The 5DOF unit from Sparkfun works off a 3.3v supply where 0V = -3g and 3.3v = +3g. 0g would be smack in the middle of the voltage range at about 1.65v.

    As far as PID Loops, Andy Lindsay work an extremely good article about it. http://forums.parallax.com/showthread.php?p=529609·It not only shows you how to implement the code but exactly how PID loops work. I've read it a few times because of how well it's been written. I suggest you study this article well. It will teach you what your looking for.

    Jason
    ·· Wood

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • JWoodJWood Posts: 56
    edited 2008-04-25 19:22
    MCoppler,
    My apologies. I didn't read your post to the fullest. It is a single ended input and you do not specify in the mode parameter anything other than what pins to turn on.

    Jason
    ·· Wood

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • simonlsimonl Posts: 866
    edited 2008-04-25 21:10
    @Matt: I'll second Jason's post regarding Andy Lindsay's article - it's spot on; you'll learn loads from it smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheers,

    Simon
    www.norfolkhelicopterclub.co.uk
    You'll always have as many take-offs as landings, the trick is to be sure you can take-off again ;-)
    BTW: I type as I'm thinking, so please don't take any offense at my writing style smile.gif
  • MCopplerMCoppler Posts: 38
    edited 2008-04-25 23:17
    Whoops! Sorry, I forgot about that Andy Lindsay thing. Will the BS2Functions.spin support is BASIC code though?
  • MCopplerMCoppler Posts: 38
    edited 2008-04-26 00:06
    ·· I tried using MCP3208 to read out decimals with a pushbutton on a single pin (to alternate between 0V and 3.3V and see what the ADC is putting out). At 0V it seems to put mostly relatively small numbers, (<1000), but will output anywhere from 0 all the way to 4096. At 3.3V is puts out mostly large numbers, (>3000), but, again, anwhere from 0 to 4096. Does this sound like a fried ADC? Luckily two more are supposed to arrive on Monday.

    ·· I·also tried testing the IMU and with it sitting level got readings from -61 up to +17. Is it really that noisy? Or is something wrong? I tried computing the average but for some reason it·kept giving me zero. I'm not super affluent at spin yet so maybe I just did something wrong, I tried saying the new average is equal to itself, plus the new IMU angle, divided by 2 - is that allowed in spin?

    ·· I attached my test file, I comment out different sections of PUB start's repeat section to test either the ADC or IMU.

    ···Sort of off subject here, but, is there a way to input·from·the keyboard to the·HyperTerminal and to the Propeller, say,·to simulate a signal from·our GPS unit·or something?

    ·· Lastly, not·sure if I asked about this already or not but, is there·something out there for reading in PWM? I tried·looping until a pin went high, when it did, setting time1 = cnt, then using waitpeq for it to go low, then setting time2·= cnt, then saying width·= (time2 - time1)/clkfreq)*1_000_000 (to display the pulse width in micro-seconds)··
  • MCopplerMCoppler Posts: 38
    edited 2008-04-26 17:42
    Messing with reading in pulse widths I found a cunundrum. If I set one variable equal to·cnt and then a second variable equal to cnt at a later time, first, they don't add up, and second, if I divide by clkfreq to get them in units of seconds it goes to zero. Is this maybe due to rounding or something? I have each variable assigned as a word, is that enough space?

    ··· time1 := cnt
    ··· waitcnt(clkfreq + cnt)
    ··· time2 := cnt
    ··· width := (time2 - time1)/clkfreq
    ··· Debug.str( string("time1 = ") )
    ··· Debug.dec(time1)
    ··· Debug.str( string(" ",10,13) )
    ··· Debug.str( string("time2 = ") )
    ··· Debug.dec(time2)
    ··· Debug.str( string(" ",10,13) )
    ··· Debug.str( string("width = ") )
    ··· Debug.dec(width)
    ··· Debug.str( string("us") )
    ··· Debug.str( string(" ",10,13) )
    ··· Debug.str( string(" ",10,13) )
  • simonlsimonl Posts: 866
    edited 2008-04-26 18:23
    I think CNT is expected to be a long wink.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheers,

    Simon
    www.norfolkhelicopterclub.co.uk
    You'll always have as many take-offs as landings, the trick is to be sure you can take-off again ;-)
    BTW: I type as I'm thinking, so please don't take any offense at my writing style smile.gif
  • MCopplerMCoppler Posts: 38
    edited 2008-04-26 19:00
    Thanks Simon! I'll try that out.
  • MCopplerMCoppler Posts: 38
    edited 2008-04-30 19:19
    Hello again.

    Still have problems with my ADC. When using the code JWood posted above and turning on all the pins (%11111111) I still get very sporadic readings.

    I noticed on the data sheet for the MCP3208 that there are supposed to be Din and Dout but the wiring diagram I have shows that they are supposed to be tied together - is there a reason for this? Should Din and Dout have separate pins on the Propeller chip? Also, I noticed in IMU.spin the wiring diagram shows pin6 at VDD and pin7 left unconnected, is there a reason for any of those either?
  • JWoodJWood Posts: 56
    edited 2008-04-30 19:47
    MCoppler,

    Would you take a picture of your exact ADC setup again and also post the code your using to start and read from the MCP3208.spin object. This will help me help you.

    Din and Dout should be connected together. You do not need pin6 connected to VDD and pin7 can be left floating. I don't have much of a reason for connecting pen6 to VDD other than to check that the ADC is reading 4096 and working correctly.

    with out getting correct readings from you ADC there is no hope in getting the filter to work. We really need to get your MCP3208 object working correctly before we trouble shoot anything else in the system. It's the life blood of the filter.

    I'll wait to hear back with your code and pictures. Did you get new ADC's yet?

    Jason
    ·· Wood

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • MCopplerMCoppler Posts: 38
    edited 2008-04-30 21:17
    Thanks JWood!

    Yes I got new ADCs and had the same problem.

    I've attached a picture and my code. You can see that I've playing with it a little bit, I have the majority commented-out though, the portion I used to test just a single channel of the ADC by itself though is not commented-out. I tried various combinations for, "mode," in ADC.start such as %11111111 (sporadic readings), %00111111 (a constant value, 14 if I remember correctly), %11111100 (a different constant value, somewhere around 6000 I think, which was weird).
    2048 x 1536 - 745K
  • JWoodJWood Posts: 56
    edited 2008-04-30 21:37
    MCoppler,
    So your wiring looks good according the the picture. You are also referencing the correct pins in your code.

    in your code, your starting both the·MCP3208 and the IMU objects. This will create two MCP3208 objects trying to interact with the same ADC. Have you commented out the IMU start line and just left the MCP3208 start line?

      ADC.start(DIO, CLK, CS, %11111111)
      'IMU.start(CS, DIO, CLK)
    

    Jason
    ·· Wood

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • JWoodJWood Posts: 56
    edited 2008-04-30 21:52
    FYI to all you forum readers.

    My last suggestion got MCoppler up and working.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • MCopplerMCoppler Posts: 38
    edited 2008-04-30 22:31
    Hey everybody, here are those pictures of the test stand that was built for the helicopter project I'm working on. Let me know if you have any questions! This thing is great for tuning a PID because you can easily measure the oscillation period without the helicopter walking away on you. Plus, it can go crazy out of control and never hit anything. It also allows for altitude adjustment but has soft landing and soft "topping" so you don't ram it up or down.
    2048 x 1536 - 749K
    2048 x 1536 - 768K
    2048 x 1536 - 743K
    2048 x 1536 - 756K
  • toohighpsitoohighpsi Posts: 1
    edited 2008-05-03 05:15
    You guys have some pretty sweet projects going... I've just begun researching implementing a similar setup for a Blade CP... check out the following link posted by mmormota for some good info regarding 120deg CCPM background:

    www.rcgroups.com/forums/showthread.php?t=624290

    When noodling his post, I put his equations into a quick excel sheet to conceptualize... seems to be spot on. Seems that I can't attach an excel file here, so PM me if you can post or want a copy. I'll verify in a quick CATIA model later this week.

    -toohighpsi
    900 x 613 - 100K
  • simonlsimonl Posts: 866
    edited 2008-05-03 09:58
    @toohighpsi: Hey - great find. Thanks smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheers,

    Simon
    www.norfolkhelicopterclub.co.uk
    You'll always have as many take-offs as landings, the trick is to be sure you can take-off again ;-)
    BTW: I type as I'm thinking, so please don't take any offense at my writing style smile.gif
  • MCopplerMCoppler Posts: 38
    edited 2008-05-05 23:29
    Hello again everybody.

    Has anybody successfully used the IMU/KF code in conjunction with a PID. I'm getting funky results, I think due to running out of cogs, but I'm not sure.
  • simonlsimonl Posts: 866
    edited 2008-05-06 19:35
    Not tried it myself, but my first reaction is: have you allowed enough stack space? Better to start high and work back. I seem to remember there being an object in obex that tells you how much stack space is required/used...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheers,

    Simon
    www.norfolkhelicopterclub.co.uk
    You'll always have as many take-offs as landings, the trick is to be sure you can take-off again ;-)
    BTW: I type as I'm thinking, so please don't take any offense at my writing style smile.gif
  • MCopplerMCoppler Posts: 38
    edited 2008-05-06 19:39
    Hey Simon, nice to hear from you!

    I think I was able to determine that I am indeed running out of cogs. Although stack space is definitely an issue as well, I'm sure. I looked at that object for determening how much stack space is required and couldn't really figure out how to use it (I'm not a programmer). I just through 25 longs at it, figured that'd be enough.
  • simonlsimonl Posts: 866
    edited 2008-05-06 20:11
    Yeah - discovering how much stack to assign can be tricky. I've seen some guidelines, but never actually had a problem where I needed to use them! Similar story with # cogs, but that can usually be worked-out by looking at # of cognews in your code - if there's more than 7 you're either out-of-cogs, or your code's being clever with letting/forcing cogs to stop.

    OK; when you do F8 in the IDE, see how much Stack/free space it shows (blue bar) then assign half of it to stack. If you still have the problem, add half again.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheers,

    Simon
    www.norfolkhelicopterclub.co.uk
    You'll always have as many take-offs as landings, the trick is to be sure you can take-off again ;-)
    BTW: I type as I'm thinking, so please don't take any offense at my writing style smile.gif
  • MCopplerMCoppler Posts: 38
    edited 2008-05-10 06:28
    I feel retarded once more.

    After determining that there aren't enough cogs to start Andy Lindsay's PID methods in new cogs in addition to having Jason Wood's IMU running at the same time on a single Propeller I tried something different (my partner is working on using two Props instead). I basically copied Lindsay's code but duplicated it (see attachment). Basically this should mean the update rate is about 1/2 as fast, oh well, comprimises right? Anyway, I'm not able to get past a line using Float32's FDiv method, "4" (see attachment), don't really know why...anybody got any clues?
  • MCopplerMCoppler Posts: 38
    edited 2008-05-10 06:31
    ...sorry, to add to that last post, when I comment out the lines using FDiv it gets to "Time calculations" but then at the next Float math method it stops again, maybe I'm not initializing Float32 right or something?
  • MCopplerMCoppler Posts: 38
    edited 2008-05-10 06:37
    Wow, I feel really retarded. Sorry to all of you whose inboxes I am flooding if you have checked, "Notify of replies."

    Once I added f.start to Hover2.spin the repeat loop started working.

    However, some funny results came out. The Debug was just sort of strange, but the more troubling part is that no matter what the error, my outputs were always 1500 (microseconds, for the servos). Any clues?
  • simonlsimonl Posts: 866
    edited 2008-05-10 07:30
    Not looked into it in detail, but the fact that you're seeing debug output like 1500ched 'Time' suggests you're overwriting memory - you probably need more stack space...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheers,

    Simon
    www.norfolkhelicopterclub.co.uk
    You'll always have as many take-offs as landings, the trick is to be sure you can take-off again ;-)
    BTW: I type as I'm thinking, so please don't take any offense at my writing style smile.gif
  • MCopplerMCoppler Posts: 38
    edited 2008-05-10 08:25
    Good call Simon, is there a way to assign more memory to a cog that's already running?
Sign In or Register to comment.