This code includes FRDM-STBC-AGM01 in order to add 9dof Sensor Fusion to Nerf Gun Demo. 9dof = accelerometer, magnetometer and gyro.

Dependencies:   DebounceIn FXAS21000 FXOS8700Q Madgwick_Algorithm Mahony_Algorithm mbed nRF24L01P

Fork of FRDM-STBC-AGM01 by angus taggart

The goal of this project is to incorporate sensor fusion capability to the already existing Nerf Gun Demo. The demo is controlled using Freescale's FRDM-K64F. I'm looking to add the FRDM-STBC-AGM01 to the project, which not only has FSL's combo accelerometer and magnetometer part FXOS8700Q but also FSL's gyro part FXAS21000. Hopefully the combination of all three sensors for 9dof sensor fusion will improve the mobility and control of the the demo's movement.

Details of the project can be found on the Freescale online community at https://community.freescale.com/groups/demolab/projects/fun-with-sensorfusion-nerf-gun-and-openrov-projects.

Committer:
ajtag
Date:
Mon Apr 20 19:13:34 2015 +0000
Revision:
2:0cccf85f9b3f
Parent:
0:bfb567985c64
Child:
3:10f487bae65c
Hello World for STBC-AGM01 shield

Who changed what in which revision?

UserRevisionLine numberNew contents of line
screamer 0:bfb567985c64 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
screamer 0:bfb567985c64 2 *
screamer 0:bfb567985c64 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
screamer 0:bfb567985c64 4 * and associated documentation files (the "Software"), to deal in the Software without
screamer 0:bfb567985c64 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
screamer 0:bfb567985c64 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
screamer 0:bfb567985c64 7 * Software is furnished to do so, subject to the following conditions:
screamer 0:bfb567985c64 8 *
screamer 0:bfb567985c64 9 * The above copyright notice and this permission notice shall be included in all copies or
screamer 0:bfb567985c64 10 * substantial portions of the Software.
screamer 0:bfb567985c64 11 *
screamer 0:bfb567985c64 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
screamer 0:bfb567985c64 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
screamer 0:bfb567985c64 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
screamer 0:bfb567985c64 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
screamer 0:bfb567985c64 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
screamer 0:bfb567985c64 17 */
screamer 0:bfb567985c64 18
screamer 0:bfb567985c64 19 #include "mbed.h"
screamer 0:bfb567985c64 20 #include "FXOS8700Q.h"
screamer 0:bfb567985c64 21 #include "FXAS21000.h"
screamer 0:bfb567985c64 22
screamer 0:bfb567985c64 23
screamer 0:bfb567985c64 24 FXOS8700Q_acc combo_acc(D14, D15, FXOS8700CQ_SLAVE_ADDR0);
screamer 0:bfb567985c64 25 FXOS8700Q_mag combo_mag(D14, D15, FXOS8700CQ_SLAVE_ADDR0);
screamer 0:bfb567985c64 26 FXAS21000 gyro(D14, D15);
screamer 0:bfb567985c64 27
ajtag 2:0cccf85f9b3f 28 DigitalOut ledpin(LED1);
screamer 0:bfb567985c64 29
screamer 0:bfb567985c64 30 Serial pc(USBTX, USBRX);
screamer 0:bfb567985c64 31
screamer 0:bfb567985c64 32 int main()
screamer 0:bfb567985c64 33 {
ajtag 2:0cccf85f9b3f 34 pc.baud(115200);
ajtag 2:0cccf85f9b3f 35
ajtag 2:0cccf85f9b3f 36 float gyro_data[3];
screamer 0:bfb567985c64 37 MotionSensorDataUnits adata;
screamer 0:bfb567985c64 38 MotionSensorDataUnits mdata;
ajtag 2:0cccf85f9b3f 39 //int16_t acc_raw[3];
screamer 0:bfb567985c64 40
screamer 0:bfb567985c64 41 printf("\r\nStarting\r\n\r\n");
screamer 0:bfb567985c64 42
screamer 0:bfb567985c64 43 combo_acc.enable();
screamer 0:bfb567985c64 44 combo_mag.enable();
ajtag 2:0cccf85f9b3f 45 printf("FXOS8700 Combo mag = %X\r\n", combo_mag.whoAmI());
ajtag 2:0cccf85f9b3f 46 printf("FXOS8700 Combo acc = %X\r\n", combo_acc.whoAmI());
ajtag 2:0cccf85f9b3f 47
screamer 0:bfb567985c64 48 printf("FXAS21000 Gyro = %X\r\n", gyro.getWhoAmI());
screamer 0:bfb567985c64 49
screamer 0:bfb567985c64 50 wait(3);
screamer 0:bfb567985c64 51
screamer 0:bfb567985c64 52 while(1) {
ajtag 2:0cccf85f9b3f 53 ledpin = 0;
screamer 0:bfb567985c64 54 combo_acc.getAxis(adata);
screamer 0:bfb567985c64 55 printf("FXOS8700 Acc: X:%6.3f Y:%6.3f Z:%6.3f\r\n", adata.x, adata.y, adata.z);
screamer 0:bfb567985c64 56
screamer 0:bfb567985c64 57 combo_mag.getAxis(mdata);
screamer 0:bfb567985c64 58 printf("FXOS8700 Mag: X:%6.2f Y:%6.2f Z:%6.2f\r\n", mdata.x, mdata.y, mdata.z);
screamer 0:bfb567985c64 59
screamer 0:bfb567985c64 60 gyro.ReadXYZ(gyro_data);
screamer 0:bfb567985c64 61 printf("FXAS21000 Gyro: X:%6.2f Y:%6.2f Z:%6.2f\r\n", gyro_data[0], gyro_data[1], gyro_data[2]);
screamer 0:bfb567985c64 62
ajtag 2:0cccf85f9b3f 63
screamer 0:bfb567985c64 64 printf("\r\n");
screamer 0:bfb567985c64 65
ajtag 2:0cccf85f9b3f 66
ajtag 2:0cccf85f9b3f 67 ledpin = 1;
screamer 0:bfb567985c64 68 wait(1);
screamer 0:bfb567985c64 69 }
screamer 0:bfb567985c64 70 }