Page 1 of 1

Accessing SxR Accelerometer and gyro data

Posted: Tue Sep 10, 2019 1:54 pm
by jonasbjurel
Anyone knowing if it is possible to access the raw Accelerometer and Gyro data from SxR through LUA?
I would assume that you could access it through sportTelemetryPush/Pop but I havnt found the full field map of SxR.
I would want that data to build a level and turn coordination LUA telemetry script.
Thanks in advance!
/Jonas

Re: Accessing SxR Accelerometer and gyro data

Posted: Thu Sep 12, 2019 4:59 pm
by jonasbjurel
Well, I will try to do some reverse engineering, this script should help me find any interesting SxR S.port registers.
/Jonas


#!/bin/lua
--[[
##############################################################################
# Brief: An Open-TX LUA script that reads the SxR registers from 0x00 to 0xFF
# And presents them on the screen
#------------------------------------------------------------------------------
##############################################################################
--]]


local refreshState = 0
local baseIndex=0x00
local index=0x00
local table = {nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil}
local UNINIT = 3
local NOTTRANSMITTED = 1
local TIMEOUT = 2
local SUCCESS = 0
local errorTable = {UNINIT, UNINIT, UNINIT, UNINIT, UNINIT, UNINIT, UNINIT, UNINIT, UNINIT, UNINIT, UNINIT, UNINIT, UNINIT, UNINIT, UNINIT, UNINIT}
local telemetryPopTimeout

-- Redraw the current page
local function redrawFieldsPage()
local x = 0
local y = 10

lcd.clear()
lcd.drawScreenTitle("SxR, Base address: " .. string.format('%02x',baseIndex), 1, 1)
lcd.drawText(x, y, "Base Address: 0x" .. string.format('%02x',baseIndex))
x = 110
lcd.drawText(x, y, "Status:")
x = 150
lcd.drawNumber(x, y, index)
x = 170
for i = 1, 8, 1 do
lcd.drawNumber(x, y, errorTable)
x = x + 5
end

x = 0
y = 20
for i = 1, 8, 1 do
if table == nil then
lcd.drawText(x, y, "nil ")
else
lcd.drawText(x, y, string.format('%02x',table))
end
x = x + 26
end
y = 40
x = 0
lcd.drawText(x, y, "Base address 0x" .. string.format('%02x',baseIndex + 0x08))
x = 110
lcd.drawText(x, y, "Status:")
x = 150
lcd.drawNumber(x, y, index)
x = 170
for i = 9, 16, 1 do
lcd.drawNumber(x, y, errorTable)
x = x + 5
end
x = 0
y = 50
for i = 1, 8, 1 do
if table == nil then
lcd.drawText(x, y, "nil ")
else
lcd.drawText(x, y, string.format('%02x',table))
end
x = x + 26
end
end

local function telemetryRead(field)
return sportTelemetryPush(0x17, 0x30, 0x0C30, field)
end


local telemetryPopTimeout = 0

local function refreshNext()
if refreshState == 0 then
if telemetryRead(baseIndex+index) == true then
print("Read order sent for address: " .. string.format('%02x',baseIndex + index))
refreshState = 1
telemetryPopTimeout = getTime() + 120 -- normal delay is 500ms
else
print("Read order NOT sent for address: " .. string.format('%02x',baseIndex + index))
errorTable[index + 1] = NOTTRANSMITTED
end
elseif refreshState == 1 then
local physicalId, primId, dataId, value = sportTelemetryPop()
--if physicalId == 0x1A and primId == 0x32 and dataId == 0x0C30 and value % 256 == baseIndex + index then
if physicalId == 0x1A and primId == 0x32 and dataId == 0x0C30 then
errorTable[index + 1] = SUCCESS
table[index + 1] = math.floor(value / 256)
if index == 0x0F then
index = 0
else
index = index + 0x01
end
refreshState = 0
elseif getTime() > telemetryPopTimeout then
print("Timeout")
errorTable[index + 1] = TIMEOUT
if index == 0x0F then
index = 0
else
index = index + 0x01
end
refreshState = 0
end
end

redrawFieldsPage()
return
end

local function flushTables()
table = {nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil}
errorTable = {UNINIT, UNINIT, UNINIT, UNINIT, UNINIT, UNINIT, UNINIT, UNINIT, UNINIT, UNINIT, UNINIT, UNINIT, UNINIT, UNINIT, UNINIT, UNINIT}
end

-- Init
local function init()
end

-- Main
local function run(event)
if event == nil then
error("Cannot be run as a model script!")
return 2
end
if event == EVT_EXIT_BREAK then
return 2
end
if event == EVT_PLUS_FIRST then
if baseIndex >= 0xF0 then
baseIndex = 0xF0
else
baseIndex = baseIndex + 0x10
flushTables()
end
elseif event == EVT_MINUS_FIRST then
if baseIndex <= 0x00 then
baseIndex = 0x00
else
baseIndex = baseIndex - 0x10
flushTables()
end
end

refreshNext()
return 0
end

return { init=init, run=run }

Re: Accessing SxR Accelerometer and gyro data

Posted: Thu Sep 12, 2019 8:16 pm
by rdeanchurch
Interesting.
Please keep posting on your results.

Re: Accessing SxR Accelerometer and gyro data

Posted: Fri Sep 13, 2019 10:37 am
by jonasbjurel
The only accessible registers that are not used by the SxR LuA configuration script are:
0x8A
0x8B
0x8F
0x93
0x94
0x98
But they are only showing static data and nothing interesting.
A pitty, since SxR has Gyro and Accel data.
Time to build an own Accel, Gyro and Magnetometer telemetry device.
I will use this chip https://www.electrokit.com/produkt/mpu- ... gJlcPD_BwE

/Jonas

Re: Accessing SxR Accelerometer and gyro data

Posted: Fri Sep 13, 2019 11:01 am
by jhsa
Have you seen the oXs (OpenXsensor) project? search this forum :)

João

Re: Accessing SxR Accelerometer and gyro data

Posted: Fri Sep 13, 2019 12:34 pm
by MikeB
Accelerometers are 0x9E, 0x9F and 0xA0 (x,y,z), signed 16-bit, BIg Endian (high byte in D4), units of "milli G".

Mike

Re: Accessing SxR Accelerometer and gyro data

Posted: Sat Sep 14, 2019 6:28 pm
by jonasbjurel
Sorry, but my responses seem not to come through - and this site is so crowded with advertising so it is hard to navigate - let's try again.
- "jhsa" - thanks for the reference to oXs, but the community around this initiative seems to be dead - very few github commits younger than a couple of years back - but thanks for the reference, there is certainly code to re-use from that repo.
- " MikeB" - thanks alot for these addresses (I must have lost my mind in mapping registers with the SxR config registers), 0x9E, 0x9F and 0xA0 surely shows dynamic acceleration in the three axeses. Unfortunately the updating frequency which I'm able to achieve is crazily low (.5 - .1 Hz) which to me makes it virtually unusable for any practical use. Correct me if I'm wrong!
BR/Jonas

Re: Accessing SxR Accelerometer and gyro data

Posted: Sat Sep 14, 2019 6:32 pm
by Kilrah
jonasbjurel wrote: Sat Sep 14, 2019 6:28 pm - "jhsa" - thanks for the reference to oXs, but the community around this initiative seems to be dead - very few github commits younger than a couple of years back - but thanks for the reference, there is certainly code to re-use from that repo.
It's just mostly "finished" and does basically all you'd want it to do, so nothing to commit anymore... The people are around, the devs will answer your questions in a day or 2 and most of us regularly build some. It already supports reading IMUs and transferring the data out of the box, and it's easy to add whatever computation you'd want yourself.
jonasbjurel wrote: Sat Sep 14, 2019 6:28 pmUnfortunately the updating frequency which I'm able to achieve is crazily low (.5 - .1 Hz) which to me makes it virtually unusable for any practical use. Correct me if I'm wrong!
That is correct, all it was made for was to give you a reading during manual calibration.

Re: Accessing SxR Accelerometer and gyro data

Posted: Sun Sep 15, 2019 6:59 pm
by jhsa
oXs is NOT dead at all. Michel always replies to our questions and he is still implementing new stuff and fixing any bug that shows up. OXs is great, and I don't use any other sensors.. And it is DIY..

João

Sent from my BLN-L21 using Tapatalk


Re: Accessing SxR Accelerometer and gyro data

Posted: Sun Sep 15, 2019 8:47 pm
by antlerhanger
I am building sensors right now and I always have questions and they always get answered ...100% of the time .

Allen