Reading data from Sensor Streamer; data conversion binary==>float
3 次查看(过去 30 天)
显示 更早的评论
Hi All, I have some trouble reading data from an Iphone app (sensor streamer, https://itunes.apple.com/us/app/sensor-data-streamer/id608278214?mt=8). I know Matlab has a solution for this, but that solution does not work on iOS 8. Sensor streamer seems to work, however, I cannot read in the data correctly. What I tried so far (after opening an udp connection is
[data, count]=fread(udpobject,1, 'char')
because I know the first byte is a character. My plan was to go according to the specifications of the data in the app like this. But, although I specify the size to read to be 1, the result I get is all 111 bytes that the the data packet contains. (see also below). I do know that bytes 4-7 (data(5:8) should contain acceleration in x-direction, bytes 8-11 (data(9:12) in y, and so on. So now, I have eto find a way to get bytes 4-7 (which I assume to be the integers 5:8 in my data, which look like 8 bit numbers now), which I know should be a float, into a float. And here, I’m at a loss. Does anybody have some suggestions? or suggestions on how to otherwise solve this? Thanks! Sjoerd
data = 70 83 1 107 0 42 208 62 0 0 165 188 0 222 96 191 145 197 42 188 173 251 86 189 32 165 132 58 0 0 0 224 66 122 100 64 0 0 0 0 27 121 127 192 0 0 0 64 46 170 77 64 0 0 0 0 123 113 89 64 0 0 0 0 0 0 240 191 159 74 113 185 22 254 73 64 92 239 81 48 98 152 23 64 0 0 0 160 248 160 62 64 0 0 255 255 255 255 255 255 255 255 0 255 255 255 255 255 255 255 255
0 个评论
回答(2 个)
Timo
2014-11-19
I think i've figured out how to convert the 4 byte data and 8 byte data into single's and doubles. I used the typecast function like this for the 4 byte data:
typecast(uint8(data(5:8)'),'single')
and like this for the 8 byte data:
typecast(uint8(data(29:36)'),'double')
this means getting accelerometer, gyroscope and tesla data (in x,y,z axis) will go as follow:
acc = [typecast(uint8(data(5:8)'),'single'),typecast(uint8(data(9:12)'),'single'),typecast(uint8(data(13:16)'),'single')]; gyr = [typecast(uint8(data(17:20)'),'single'),typecast(uint8(data(21:24)'),'single'),typecast(uint8(data(25:28)'),'single')]; tes = [typecast(uint8(data(29:36)'),'double'),typecast(uint8(data(37:44)'),'double'),typecast(uint8(data(45:52)'),'double')];
I've checked the outcome with the values of my iphone when in static position, and for acc, gyr and tes the values checked out.
See you tomorrow during the practical!
gr. Timo
0 个评论
Roger van Rensburg
2015-3-5
Hi Sjoerd and Timo,
Thanks for your contributions, I used the same app to read in sensor data to Simulink in real-time. Works quite nice, you saved me a lot time with your previous posts.
Roger
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!