It is currently Tue May 23, 2017 9:45 am



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Retrieving Sensor Data
Unread postPosted: Sat May 13, 2017 5:00 am 
Offline

Joined: Tue Oct 01, 2013 4:37 am
Posts: 34
Does anyone know whether it would be possible to retrieve the Android Get_Rotation_Matrix from within RFOBasic? I can of course already access accelerometer and magnetometer sensor data, however the readings seem erratic and I haven't so far been able to use these to calculate a stable device orientation. After researching Android I found solutions using Get_Rotation_Matrix but am at a loss how to access this from within RFOBasic. Finally I gather the sensors return accuracy parameters to the Android platform and was wondering if RFOBasic might return these in a future version.


Report this post
Top
 Profile  
 
 Post subject: Re: Retrieving Sensor Data
Unread postPosted: Sat May 13, 2017 8:29 am 
Offline

Joined: Sat Dec 22, 2012 2:32 pm
Posts: 830
Normally the device orientation could be read from "orientation-sensor". Rotation-matrix is not present at my device at all, only a rotation-vector. Do you have ( and if: did you check) orientation-sensor?

Maybe you can provide the code you are testing with!?

brochi


Report this post
Top
 Profile  
 
 Post subject: Re: Retrieving Sensor Data
Unread postPosted: Sat May 13, 2017 12:29 pm 
Offline
User avatar

Joined: Wed Jul 10, 2013 8:11 am
Posts: 325
Hi flying porcupine,

FROM Stackoverflow:
>>
There is no actual "orientation" sensor - this is (was) actually a composite sensor, generated from a combination of the accelerometer and the magnometer.

From http://developer.android.com/reference/ ... Event.html

"This sensor type exists for legacy reasons, please use getRotationMatrix() in conjunction with remapCoordinateSystem() and getOrientation() to compute these values instead."
<<
If you use the unpublished command
sensors.rotate a,b,c
you get an error message, because this function is maybe since years not ready.

This kind of sensors are noisy. You have to deal with a running average.

Stay tuned. I will see what I can do.

Gregor


Report this post
Top
 Profile  
 
 Post subject: Re: Retrieving Sensor Data
Unread postPosted: Sat May 13, 2017 9:02 pm 
Offline

Joined: Sat Dec 22, 2012 2:32 pm
Posts: 830
hm... the link is from 2012 .... i wonder if it's still up-to-date?
On my devices, orientation "sensor" is (.. and was) always present, from Android 4...6, and always directly accessible from BASIC, therefore i didn't check for details....

brochi


Report this post
Top
 Profile  
 
 Post subject: Re: Retrieving Sensor Data
Unread postPosted: Mon May 15, 2017 2:50 pm 
Offline
User avatar

Joined: Wed Jul 10, 2013 8:11 am
Posts: 325
Brochi,

you are right.
It seems to be the Android documentation is up-to-date, but in a lot of cases wrong.


https://github.com/RFO-BASIC/Basic/files/1002574/OliBasicXVIIId.zip


Sensors.rotate {<axis1_sexp>}, {<axis2_sexp>}, <p1_nvar>, <p2_nvar>, <p3_nvar> {, rot_matrix_Array[]}
With <axis1_sexp> and <axis2_sexp> a new coordinate system can be set.
Possible axisses are _AXIS_X, _AXIS_Y, _AXIS_Z, _AXIS_MINUS_X, _AXIS_MINUS_Y, _AXIS_MINUS_Z.
Returns the orientation parameter <p1_nvar>, <p2_nvar>, <p3_nvar> in degree and the
Rotation Matrix rot_matrix_Array[]:
| [1] [2] [3] |
| [4] [5] [6] |
| [7] [8] [9] |


Code:
!!
For the averaging part, do you mean an exponentially decaying low-pass filter of the form
y_new = y_old + (input - y_old)*alpha
where alpha = dt/tau, dt = the timestep of the filter, tau = the time constant of the filter? (the variable-timestep form of this is as follows, just clip dt/tau to not be more than 1.0)
y_new = y_old + (input - y_old)*dt/tau
!!

ac = 3
Sensors.open 1:ac, 2:ac, 3:ac
i=0
alpha = 0
aa_old = 0
r_old = 0
aamin = 370
aamax = -1
rmin = 370
rmax = -1
do
alpha = i/1000
Alpha = 0.35
Sensors.read 3,r,s,t
!?r,s,t
sensors.rotate ,,aa,bb,cc
if aa < 0 then aa = 360 + aa
aa_new = aa_old + (aa - aa_old)*alpha
r_new = r_old + (r - r_old)*alpha
? r, aa_new, Abs(aa_new - aa_old), i, alpha
if i > 40
aamin = min(aamin,aa_new)
aamax = max(aamax,aa_new)
rmin = min(rmin,r_new)
rmax = max(rmax,r_new)
end if
r_old = r_new
aa_old = aa_new
pause 20
i++
until i>1000
? rmin,rmax
? aamin, aamax

!sensors.rotate "_axis_y","_axis_minus_x"%, w[]
!sensors.rotate ,,aa,bb,cc, w[]
!? aa, bb, cc
! debug.show.array w[]

!sensors.rotate "_axis_x","_axis_y",aa,bb,cc




The orientation sensor 3 is with Typical Delay 3 the exactest. :?: :?: :?:
Maybe a special smoothing algorithm in background. :?:
All device dependent.
My Samsung phone rounds the orientation sensor values to integers :!:



Gregor


Report this post
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
suspicion-preferred