# Equals? function acting weird?

So we are trying to set up an acc/dec VI and we want to be able to gradually accelerate/decelerate, and for some reason when it reaches the maximum value, it oscillates between the max and the value of the acceleration. I know that sounds like crap so here is an example:
When trying to have a value of .5, and accelerating by .05, it rotates between the two values here every tick.

(Yeah one isn’t while the code is running because printscreen was being annoying.

This is our code, the outer true function does nothing while the true on the inner case funcion does the same but subtracts. We think it is because the equals is sending out the value before it gets changed to (when the input value is 1) a 1, as the Equals? function is always false, even when the number is 1.

Floating point numbers often may not compare exactly equal, especially after repeated math operations. It’s much more reliable to check whether the numbers are within a tolerance range, e.g. abs(A - B) < 0.001.

Put the robot on blocks so it’s not driving (this next step will substantially slow code execution and you don’t want the robot driving). Now click on the lightbulb icon on the toolbar of the Acc-Dec VI. This will turn on “highlight execution” which will show you what values are traveling across what wires when each time your VI runs. It should help you track down what’s going on here.

This is a common problem implementing this kind of acceleration function. Your problem isn’t even down to weird floating point math. Look at the code and ask what it would do if you started at 0 and went to 0.125 by 0.05. You’d get 0, 0.05, 0.1, 0.15, 0.1, …

As Peter said, you need to compare the difference first, but not to a random epsilon. Instead of = for your first test, you should look at:
ABS(Input - Feedback Node) < Acceleration

If true, you should send the input straight through to the output/feedback node. If false, decide whether to add/subtract your acceleration value.