View Full Version : Inverse Trig in Java ME
brennonbrimhall
03-04-2013, 11:18
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 want MathUtils (http://robotics.francisparker.org/javadoc/com/sun/squawk/util/MathUtils.html). 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.
shindigo
06-04-2013, 07:33
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.
brennonbrimhall
06-04-2013, 08:31
Thanks for all the help! :)
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 (http://en.wikipedia.org/wiki/Law_of_cosines) 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 (http://en.wikipedia.org/wiki/Piecewise_linear_function#Fitting_to_a_curve) 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.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.