Inverse Trig in Java ME

I’ve found myself in a bit of a pickle. I need to write a calculation that involves some inverse trig for our robot, and the embedded version of Java that the cRIO uses (Java ME) does not have the inverse trig functions of the Java SE Math library.

How have other teams moved past this limitation?

You wantMathUtils. It provides some of the functions that you’d usually find in Math in Java SE that aren’t implemented in ME’s Math class.

Another possibility is javalution: http://javolution.org/core-java/target/apidocs/index.html I have never compared this with mathutils, but it might be worth exploring too.

Thanks for all the help! :slight_smile:

Depending on how you intend to use the trig function, another option is to write a simple routine that gives an approximate but “close enough” answer.

For example, our robot uses a leadscrew to adjust the tilt angle of our climbing mast. There is an encoder attached to the end of the leadscrew so we can measure the distance it has traveled and use the cosine rule to convert this to an angle for the drivers. However to convert from leadscrew distance to angle requires using the acos() function.

Since the range of leadscrew distances are limited by the physical system, our programmers approximated the function using a piecewise linear approximation implemented as a lookup table. While the results are approximate they are close enough for visual display.

This approach is fairly common practice in embedded software, and can be used safely if you do proper error analysis.