Freescale Quadcopter with Freedom K64F Board
Dependencies: FXAS21000 FXLS8471Q FXOS8700Q MAG3110 MMA8652 MPL3115A2 mbed kalman mbed-dsp
Fork of Freescale_Multi-Sensor_Shield by
Quadcopter based on Freescale FRDM-K64F, Freescale FRDM-FXS-9AXIS, Hobbypower X525 V3 Quadcopter Foldable Kit with 1000KV Motors and SimonK 30A ESC
main.cpp@2:4bc4e25328cc, 2015-08-31 (annotated)
- Committer:
- julioefajardo
- Date:
- Mon Aug 31 23:37:07 2015 +0000
- Revision:
- 2:4bc4e25328cc
- Parent:
- 0:bfb567985c64
- Child:
- 3:58ebc00f1a68
Version 0.1; Acc, Mag, Gyro; PWM for 4 motors (D13, D12, D11, D10)
Who changed what in which revision?
User | Revision | Line number | New 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 | |
julioefajardo | 2:4bc4e25328cc | 24 | //FXOS8700Q_acc combo_acc(D14, D15, FXOS8700CQ_SLAVE_ADDR0); |
julioefajardo | 2:4bc4e25328cc | 25 | //FXOS8700Q_mag combo_mag(D14, D15, FXOS8700CQ_SLAVE_ADDR0); |
julioefajardo | 2:4bc4e25328cc | 26 | FXOS8700Q_acc combo_acc(A5, A4, FXOS8700CQ_SLAVE_ADDR0); |
julioefajardo | 2:4bc4e25328cc | 27 | FXOS8700Q_mag combo_mag(A5, A4, FXOS8700CQ_SLAVE_ADDR0); |
julioefajardo | 2:4bc4e25328cc | 28 | //FXAS21000 gyro(D14, D15); |
julioefajardo | 2:4bc4e25328cc | 29 | FXAS21000 gyro(A5, A4); |
screamer | 0:bfb567985c64 | 30 | |
julioefajardo | 2:4bc4e25328cc | 31 | //PwmOut M1(PTB18); |
julioefajardo | 2:4bc4e25328cc | 32 | PwmOut M1(D13); |
julioefajardo | 2:4bc4e25328cc | 33 | PwmOut M2(D12); |
julioefajardo | 2:4bc4e25328cc | 34 | PwmOut M3(D11); |
julioefajardo | 2:4bc4e25328cc | 35 | PwmOut M4(D10); |
screamer | 0:bfb567985c64 | 36 | |
screamer | 0:bfb567985c64 | 37 | Serial pc(USBTX, USBRX); |
screamer | 0:bfb567985c64 | 38 | |
screamer | 0:bfb567985c64 | 39 | int main() |
screamer | 0:bfb567985c64 | 40 | { |
julioefajardo | 2:4bc4e25328cc | 41 | float gyro_data[3]; |
screamer | 0:bfb567985c64 | 42 | MotionSensorDataUnits adata; |
screamer | 0:bfb567985c64 | 43 | MotionSensorDataUnits mdata; |
julioefajardo | 2:4bc4e25328cc | 44 | |
screamer | 0:bfb567985c64 | 45 | printf("\r\nStarting\r\n\r\n"); |
julioefajardo | 2:4bc4e25328cc | 46 | |
julioefajardo | 2:4bc4e25328cc | 47 | M1.period(0.02f); //Comparten el mismo timer |
julioefajardo | 2:4bc4e25328cc | 48 | M1.pulsewidth(0.0006f); |
julioefajardo | 2:4bc4e25328cc | 49 | M2.pulsewidth(0.0006f); |
julioefajardo | 2:4bc4e25328cc | 50 | M3.pulsewidth(0.0006f); |
julioefajardo | 2:4bc4e25328cc | 51 | M4.pulsewidth(0.0006f); |
julioefajardo | 2:4bc4e25328cc | 52 | |
screamer | 0:bfb567985c64 | 53 | combo_acc.enable(); |
screamer | 0:bfb567985c64 | 54 | combo_mag.enable(); |
screamer | 0:bfb567985c64 | 55 | printf("FXOS8700 Combo = %X\r\n", combo_acc.whoAmI()); |
screamer | 0:bfb567985c64 | 56 | printf("FXAS21000 Gyro = %X\r\n", gyro.getWhoAmI()); |
screamer | 0:bfb567985c64 | 57 | |
screamer | 0:bfb567985c64 | 58 | wait(3); |
screamer | 0:bfb567985c64 | 59 | |
screamer | 0:bfb567985c64 | 60 | while(1) { |
screamer | 0:bfb567985c64 | 61 | combo_acc.getAxis(adata); |
screamer | 0:bfb567985c64 | 62 | printf("FXOS8700 Acc: X:%6.3f Y:%6.3f Z:%6.3f\r\n", adata.x, adata.y, adata.z); |
screamer | 0:bfb567985c64 | 63 | |
screamer | 0:bfb567985c64 | 64 | combo_mag.getAxis(mdata); |
screamer | 0:bfb567985c64 | 65 | printf("FXOS8700 Mag: X:%6.2f Y:%6.2f Z:%6.2f\r\n", mdata.x, mdata.y, mdata.z); |
screamer | 0:bfb567985c64 | 66 | |
screamer | 0:bfb567985c64 | 67 | gyro.ReadXYZ(gyro_data); |
screamer | 0:bfb567985c64 | 68 | printf("FXAS21000 Gyro: X:%6.2f Y:%6.2f Z:%6.2f\r\n", gyro_data[0], gyro_data[1], gyro_data[2]); |
julioefajardo | 2:4bc4e25328cc | 69 | |
screamer | 0:bfb567985c64 | 70 | printf("\r\n"); |
screamer | 0:bfb567985c64 | 71 | |
julioefajardo | 2:4bc4e25328cc | 72 | wait(0.5); |
screamer | 0:bfb567985c64 | 73 | } |
screamer | 0:bfb567985c64 | 74 | } |