Accessing SxR Accelerometer and gyro data
-
- Posts: 4
- Joined: Tue Sep 10, 2019 1:46 pm
- Country: -
Accessing SxR Accelerometer and gyro data
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
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
-
- Posts: 4
- Joined: Tue Sep 10, 2019 1:46 pm
- Country: -
Re: Accessing SxR Accelerometer and gyro data
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 }
/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 }
-
- Posts: 750
- Joined: Tue Dec 27, 2011 11:22 pm
- Country: United States
- Location: Carson City, Nv
Re: Accessing SxR Accelerometer and gyro data
Interesting.
Please keep posting on your results.
Please keep posting on your results.
Dean
OldDmbThms: 1. Takeoff, 2. Crash, 3. Repair, GOTO 1
OldDmbThms: 1. Takeoff, 2. Crash, 3. Repair, GOTO 1
-
- Posts: 4
- Joined: Tue Sep 10, 2019 1:46 pm
- Country: -
Re: Accessing SxR Accelerometer and gyro data
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
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
Have you seen the oXs (OpenXsensor) project? search this forum
João
João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9
Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9
Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
- MikeB
- 9x Developer
- Posts: 18000
- Joined: Tue Dec 27, 2011 1:24 pm
- Country: -
- Location: Poole, Dorset, UK
Re: Accessing SxR Accelerometer and gyro data
Accelerometers are 0x9E, 0x9F and 0xA0 (x,y,z), signed 16-bit, BIg Endian (high byte in D4), units of "milli G".
Mike
Mike
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
The difficult we do immediately,
The impossible takes a little longer!
-
- Posts: 4
- Joined: Tue Sep 10, 2019 1:46 pm
- Country: -
Re: Accessing SxR Accelerometer and gyro data
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
- "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
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 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.
That is correct, all it was made for was to give you a reading during manual calibration.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!
Re: Accessing SxR Accelerometer and gyro data
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
João
Sent from my BLN-L21 using Tapatalk
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9
Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9
Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
-
- Posts: 238
- Joined: Tue Dec 25, 2018 3:19 am
- Country: United States
Re: Accessing SxR Accelerometer and gyro data
I am building sensors right now and I always have questions and they always get answered ...100% of the time .
Allen
Allen