Society of Robots - Robot Forum
Software => Software => Topic started by: little-c on January 13, 2010, 02:35:50 PM
-
okay, I know
#include <math.h>
or MATLAB.
but, as a question,
trig functions are quite memory and processor intensive. does anyone know of an efficent and fast way of using them? im talking vectors, accelerating and deccelerating(on non vertical planes through gravity), converting one angle to another through gearing. ect.(think math nigtmares...)
basicaly Im trying to do balistics in 3d(2d if I can get away with it) on a(sort of) horizontal plane.
if I can get the equations programed into a language, run and output required servo positions over time, in a reasonable timeframe, I can make a lot of intresting things happen.
i.e balistics simulations in slow mo.... cool applications like that.
problem is if it takes weeks to work. which trig functions and MATLAB(interperated language) do...
-
You can make a lookup table for some basic trig functions (maybe just sin and cos) and use that to calculate everything else you need.
It won't give you perfectly exact answers, but if this is going to be applied to a robot then you're going to have a margin of error anyways.
If memory's a problem, they make eeprom IC's on the cheap that you can use to store the tables.
-
Have you seen this?
http://www.societyofrobots.com/programming_trigtable.shtml (http://www.societyofrobots.com/programming_trigtable.shtml)
-
Yea I agree lookup tables are good for speed with low accuracy.
But if you want to do complex time consuming calculations it can be better to formulate your equations as matrices, then you can use existing highly optimized matrix solvers. This can also hugely simplify 3D motion calcs.
-
@Madsci1016: In regard to existing optimized matrix solvers- I have done a Google search and found a ton of information and methods. However is there any one method/implementation you prefer?
-
Me? No. I really haven't personally messed with trig in a MCU (yet), I just remembered the Admin wrote a tut on his omni bot. I'm more of a 4WD rover kinda guy. :-)
I will be looking into it however when i start on the way-point navigation for my robot.
-
Actually the best way to ballistics, and any dynamic system are Differential equations....
Why would you need trig functions in this???
And Differential equations give some very good calculations with minimum processing power and memory.
Also, for trig functions have you considered Taylor series, not the fastest but give very good proximities...
What are you trying to build. For a physics model, Differential equations are the best tools...
-
Just another note . . . identify what you'd consider the maximum acceptable error, and modify your code as such. I do a lot of processor intensive stuff, and the key is to find the sweet spot between minimizing processor time and meeting required accuracy.
Oh, and matlab is inherently processor intensive. You might just want to code in C if processing speed is really important.
examples:
For example, don't use long long long int when just short int gives an acceptable amount of error.
Use 2nd order equations, not 3rd order, if they are accurate enough. Run some curve fitting experiments to determine accuracy.
etc.
-
running MATLAB on a uni server spoils you... though if you compile it, its basicly a c program.(nomanaly its interperated, hence slow)
part of the problem, is lack of memory, and 0.0001 degree accuracy. kinda not fun ::) though I might see if I can use three values and response time to formulate equations. and hope it works... more simulations :-\
oh and later I will be moaning about simulations not matching reality! curse friction!