Jump to content

I just want a simple ramp


pallen

Recommended Posts

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:

Link to comment

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.

Link to comment

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.

Link to comment

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.

Link to comment

QUOTE (Anders Björk @ Sep 11 2008, 03:09 PM)

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.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.