Created
August 3, 2013 20:40
-
-
Save natronics/6147897 to your computer and use it in GitHub Desktop.
Converting AIDS data to MKS units
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"name": "Parsing_ADIS_messages" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "heading", | |
"level": 1, | |
"metadata": {}, | |
"source": [ | |
"Parsing ADIS Messages" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Lets start with the raw packet from the pcat file and then pick out the first ADIS message and get just the data (message header unpacking should already work):" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"message_raw = \"\\x2D\\x08\\x06\\x00\\x04\\x00\\xF7\\xFF\\x28\\x01\\x01\\x00\\x00\\x00\\x9F\\x04\\x8D\\xFF\\xC8\\xFD\\x3C\\x00\\x00\\x00\"" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 80 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Using struct we can unpack the message" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"import struct\n", | |
"adis = struct.unpack('<12h', message_raw)\n", | |
"print adis" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"(2093, 6, 4, -9, 296, 1, 0, 1183, -115, -568, 60, 0)\n" | |
] | |
} | |
], | |
"prompt_number": 81 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Okay, those numbres look good. We should still be on the ground, so roll numbers are small, and x acell is close to 300 which is about 1 g (we'll see this later)\n", | |
"\n", | |
"Now we can do unit conversion:\n", | |
"\n", | |
"Starting with voltage. We have LSB, the ADIS datasheet tells us how to get to mV" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"power_mV = adis[0] * 2.418 # From datasheet\n", | |
"print power_mV" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"5060.874\n" | |
] | |
} | |
], | |
"prompt_number": 82 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"And now to MKS we want volts. mV to V is $\\frac{1}{1000}$" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"power_V = power_mV / 1000.0\n", | |
"print \"ADIS main bus voltage: %0.3f V\" % power_V # Rounding here because there is noise in the lower bits and float conversion " | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"ADIS main bus voltage: 5.061 V\n" | |
] | |
} | |
], | |
"prompt_number": 83 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"And now the rest with the same strategy:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"gyro = []\n", | |
"for i in xrange(3): gyro.append(adis[i+1] * 0.05) # deg/s\n", | |
"accel = []\n", | |
"for i in xrange(3): accel.append(adis[i+4] * 3.33) # mg (milli gee)\n", | |
"mag = []\n", | |
"for i in xrange(3): mag.append(adis[i+7] * 0.5) # mG\n", | |
"temp = adis[10] * 0.14 # C\n", | |
"spare = adis[11] # Unused" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 84 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Now to get to MKS we do some math.\n", | |
"\n", | |
"##### Degreess to radians:\n", | |
"\n", | |
"$$\\times \\frac{\\pi}{180}$$\n", | |
"\n", | |
"##### mg to m·s<sup>-2</sup>\n", | |
"\n", | |
"$$\\times \\frac{g_0}{1000}$$\n", | |
"\n", | |
"Were $g_0$ is `9.8066`\n", | |
"\n", | |
"##### mG to Tesla\n", | |
"\n", | |
"$$\\times 10^{-7}$$\n", | |
"\n", | |
"G is Gauss\n", | |
"\n", | |
"#### °C to K\n", | |
"\n", | |
"$$+ 274.15$$" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"from math import pi\n", | |
"for i in xrange(3): gyro[i] *= pi/180.0\n", | |
"for i in xrange(3): accel[i] *= 9.8066/1000.0\n", | |
"for i in xrange(3): mag[i] *= 1.0e-7\n", | |
"temp = temp + 274.15" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 85 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"And now we have MKS units from the ADIS:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"print \"XYZ Gryo: (\" + ', '.join('%0.5f r/s' % v for v in gyro) + ')'\n", | |
"print \"XYZ Accleration: (\" + ', '.join('%0.3f m/s^2' % v for v in accel) + ')'\n", | |
"print \"XYZ Magnatometer (\" + ', '.join('%0.2e T' % v for v in mag) + ')'\n", | |
"print \"temperature %0.0f K\" % temp" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"XYZ Gryo: (0.00524 r/s, 0.00349 r/s, -0.00785 r/s)\n", | |
"XYZ Accleration: (9.666 m/s^2, 0.033 m/s^2, 0.000 m/s^2)\n", | |
"XYZ Magnatometer (5.91e-05 T, -5.75e-06 T, -2.84e-05 T)\n", | |
"temperature 283 K\n" | |
] | |
} | |
], | |
"prompt_number": 86 | |
}, | |
{ | |
"cell_type": "raw", | |
"metadata": {}, | |
"source": [] | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment