arctan
Jonathan Holle
Posts: 48
Hi all !
I'am doing an hexapod controlled by a basic stamp 2 and two PSC. So, in order to do inverse kinematic I have to use inverse trig functions (arcsin, arccos and arctan).
The only way I found is this :
' {$STAMP BS2}
' {$PBASIC 2.5}
X VAR Byte ' input value 0 to 99 (0.00 to 0.99)
Y VAR Byte
arccos VAR Byte ' angle in brads, 0<=A<=64.
arcsin VAR Byte
arctan VAR Byte
Z VAR Byte ' helper variable
X=
Z = X */ 983 / 3 ' renormalize to 127
arccos=63-(Z/2) ' first approx, to minimize iterations
boucle:
IF COS arccos <= Z THEN done
Arccos = Arccos+1
GOTO boucle
done:
Arccos = Arccos */ 360 ' convert brads to degrees using */ operator
arcsin = 90 - arccos
'For a negative X :
'Arccos = 180 - Arccos
'arcsin = -arsin
DEBUG "arccos 0.", DEC2 X," = ",DEC Arccos, CR
DEBUG ?arcsin, CR
But how could I get the arctan function, is there any relation with arcsin or arccos.
I know that a better way is to use a table ... But being completely beginner in BS2 programming, I don't know how to do it ...
Could you please help me :-D
many thanks !
I'am doing an hexapod controlled by a basic stamp 2 and two PSC. So, in order to do inverse kinematic I have to use inverse trig functions (arcsin, arccos and arctan).
The only way I found is this :
' {$STAMP BS2}
' {$PBASIC 2.5}
X VAR Byte ' input value 0 to 99 (0.00 to 0.99)
Y VAR Byte
arccos VAR Byte ' angle in brads, 0<=A<=64.
arcsin VAR Byte
arctan VAR Byte
Z VAR Byte ' helper variable
X=
Z = X */ 983 / 3 ' renormalize to 127
arccos=63-(Z/2) ' first approx, to minimize iterations
boucle:
IF COS arccos <= Z THEN done
Arccos = Arccos+1
GOTO boucle
done:
Arccos = Arccos */ 360 ' convert brads to degrees using */ operator
arcsin = 90 - arccos
'For a negative X :
'Arccos = 180 - Arccos
'arcsin = -arsin
DEBUG "arccos 0.", DEC2 X," = ",DEC Arccos, CR
DEBUG ?arcsin, CR
But how could I get the arctan function, is there any relation with arcsin or arccos.
I know that a better way is to use a table ... But being completely beginner in BS2 programming, I don't know how to do it ...
Could you please help me :-D
many thanks !
Comments
I have a computation of the ARCTAN (using CORDIC math) posted at
emesystems.com/programs/cordic-atn.bpe
emesystems.com/BS2mathC.htm
It is more accurate than the Stamp ATN operator, but slower.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com