pallen Posted September 12, 2008 Report Share Posted September 12, 2008 At the risk of looking even stupider than I feel right now, I really need to figure out what I'm doing wrong here. Problem: Pneumatic brake needs to have changes in pressure ramped slowly to keep oil from squirting out. Solution: Seems easy. I've got a "Brake Request" and a "Brake Output". When the two aren't equal, I add or subtract at a given "Rate" until they are both equal. Unexpected Problem: It just doesn't work. No matter what I do, I can't quite get it. Either I'm shooting past my setpoint by my rate nearly every time. Or when I try to go to zero, I end up with some super-dooper-small-but-not-quite-zero number. I've tried using a state machine. I've dividing the difference by rate and using a for loop. And finally I've tried what I've posted here. The sub VIs are nothing more than a simple add or subtract function. This latest one still shoots past occasionally. And I always get that not quite zero when trying to get there. Typically the "Rate" I'm using is either 0.1 or 0.01 I'm not sure if subtracting by 0.01 many times builds up some kind of "error" that prevents me from ever getting to zero. I don't know why this has been such a problem today. But several other programmers here have looked at it and can't figure it out either. Things like this really shake my confidence and ruin my day. Can anyone tell me what's going on here? It seems so simple what I want to do, yet nothing I've tried so far is working. :headbang: Quote Link to comment
Anders Björk Posted September 12, 2008 Report Share Posted September 12, 2008 If you have full development or prof. dev Labview, then you have a ramp vi under signal processing and signal generation. Quote Link to comment
eaolson Posted September 12, 2008 Report Share Posted September 12, 2008 QUOTE (pallen @ Sep 11 2008, 01:50 PM) Can anyone tell me what's going on here? Works for me. Could you maybe post your example? Have you tried turning on Highlight Execution and watch what's going on? I also just wanted to say I don't think this is a particularly good approach. If (Req - Output) is not an exact multiple of Rate, you're in trouble. What happens if Output = 0, Req = 5, and Rate = 2? You'll get an oscillation. Quote Link to comment
pallen Posted September 12, 2008 Author Report Share Posted September 12, 2008 QUOTE (eaolson @ Sep 11 2008, 03:32 PM) Works for me. Could you maybe post your example? Have you tried turning on Highlight Execution and watch what's going on?I also just wanted to say I don't think this is a particularly good approach. If (Req - Output) is not an exact multiple of Rate, you're in trouble. What happens if Output = 0, Req = 5, and Rate = 2? You'll get an oscillation. I agree this isn't the best. The Rate is only variable while I'm testing. It will be hard coded. Quote Link to comment
JohnRH Posted September 12, 2008 Report Share Posted September 12, 2008 When adding/subtracting values of 0.1 or 0.01 using doubles, you will often have VERY small rounding errors. At a minimum you'll probably have to decide on a value that you will consider close enough to zero. Quote Link to comment
Yair Posted September 12, 2008 Report Share Posted September 12, 2008 QUOTE (pallen @ Sep 11 2008, 09:50 PM) Typically the "Rate" I'm using is either 0.1 or 0.01 I'm not sure if subtracting by 0.01 many times builds up some kind of "error" that prevents me from ever getting to zero. That's a basic rule of floating-point math. You can't represent a fraction like 0.1 exactly. What you should do is compare to a small range (you can use the In Range and Coerce function) and only add or subtract if you're outside the range. The style would also be better if you used a shift register and a couple of select nodes or if you at least combined the case structures into a single structure by nesting them. Quote Link to comment
pallen Posted September 12, 2008 Author Report Share Posted September 12, 2008 QUOTE (Anders Björk @ Sep 11 2008, 03:09 PM) If you have full development or prof. dev Labview, then you have a ramp vi under signal processing and signal generation. I guess it was just that floating point error that was messing me up. I think I've found a way to make the ramp.vi work for me. Thanks. QUOTE (Yair @ Sep 11 2008, 03:42 PM) That's a basic rule of floating-point math. You can't represent a fraction like 0.1 exactly. I knew it would probably end up being a stupid question. But for some reason I couldn't even get things coerce properly for me either today. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.