In Range and Coerce

Hello all, we just finishd our second season and have been using Labview to program but have been getting quite frustrated with the long compiling and push times. So, I am beginning to learn java and will try to teach it to the team. One thing that is helpful in labview is the in range and coerce function. We use it to set soft limits and deal with inconsistencies in scaling between inputs and desired outputs. Is there something similar in Java?

You may have to write you own function to accomplish the task but shouldn’t be too difficult.


public void doSomeThing(double power){
    doSomething.set(softlimit(power));
}

private m_hi_setpoint = 10;
private m_low_setpoint = 2

public double softlimit(double setpoint){

    if(setpoint>m_hi_setpoint){
        return m_hi_setpoint;
    }else if(setpoint<m_low_setpoint){
        return m_low_setpoint;
    }else{
        return setpoint;
    }

}

There is code out there to look at for scaling say a -1 to 1 input to 0-100 deg. I just don’t have a sample right now.

“In range and coerce” also has a t/f output, not sure if OP needs it, but it wouldn’t be too hard to add to the above code

This is in C (Arduino). You can replace the longs with whatever types you want

long map(long x, long in_min, long in_max, long out_min, long out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

yep looks like the one I have used before.

I copied it form the Arduino page for map(), plus it’s not too complicated of a function in general.

Thanks. This is exactly what I was looking for.

Glad we figured it out together what ever “This” was. If at any time you need help with a function or how to translate how you did something in LV to Java this is your place.