Please publish raw data (Excel format)I now removed the scaling altogether as it is not strictly needed before the calculations. This did not really change a thing in the fact that the angles jump some seemingly arbitrary number back and forth instead of increasing or decreasing with turning the vehicle.
Help, please
Edmunds
+ your code
M_quot = MX_Word / MY_Word * 100
Picaxe Math problem(s) !
Here MX>MY
if MX is close to MY, then MX/MY is 1 or at least 2
So MX/MY *100 is 100 or 200, nothing between...
Remember : for the ATAN picaxe function
X must be between 0 and 100...
For my ATAN2 function, I used an auto-scaling divide :
Code:
#MACRO ATAN2(dx,dy) ' result in Alpha
Xm=dx
Ym=dy
gosub ATAN2_Function
#ENDMACRO
#MACRO Quadrant(Qxm,Qym) ' Result ==> Alpha
if Xm>Ym then
gosub ATAN_Xm
Alpha=Qxm
else ' Xm < Ym
gosub ATAN_Ym
Alpha=Qym
endif
#ENDMACRO
ATAN2_Function:
' Input Xm & Ym are 2 complement encoded
' Xm and YM can be anything from -32767 to + 32767
' So you can use Xm=X1-X2
' even if X2 greater than X1
'
if Ym <32768 then ' Ym > 0
if Xm<32768 then ' Xm > 0
Quadrant(Alpha,90-Alpha)
else ' Xm < 0
Xm=-Xm
Quadrant(180-Alpha,90+Alpha)
endif
else ' Ym < 0
Ym=-Ym
if Xm<32768 then ' Xm > 0
Quadrant(360-Alpha,270+Alpha)
else ' Xm < 0
Xm=-Xm
Quadrant(180+Alpha,270-Alpha)
endif
endif
RETURN
}
{ 'reduce too big numbers
ATAN_Xm:
select case Ym ' Ym < Xm
case < 655 ' Ym < 655
Alpha=100*Ym/Xm
case < 6553 ' 655 < Ym < 6553 donc Xm > 655
Q=Xm/10
Alpha=10*Ym/Q
else ' 6553 < Ym donc Xm > 6553
Q=Xm/100
Alpha=Ym/Q
end select
Alpha=ATAN Alpha
RETURN
ATAN_Ym:
select case Xm ' Xm < Ym
case < 655 ' Xm < 655
Alpha=100*Xm/Ym
case < 6553 ' 655 < Xm < 6553
Q=Ym/10
Alpha=10*Xm/Q
else ' 6553 < Xm
Q=Ym/100
Alpha=Xm/Q
end select
Alpha=ATAN Alpha
RETURN
}
Last edited: