FRDM-Copter is an attempt to build firmware for mbed based multicopter running on FRDM boards from Freescale.
Dependencies: FXAS21000 FXOS8700Q PID mbed-dsp mbed-rtos mbed
FRDM-Copter
Hardware
So far the following boards are used:
In addition I am planning on using:
- FRDM-CR20A 2.4Ghz module for communication with Frsky Taranis X9D+
Implementation
I decided to use mbed platform as it allows easy CMSIS-DAP debugging and firmware can be easily ported to other mbed enabled devices in future.
Phase 1
Sensor fusion will be implemented and estimated orientation plotted over blue-tooth in the Android application.
Phase 2
PID controller will be used to maintain orientation and control the motors using PWM channels, tuning will be possible in the Android application.
Phase 3
Controll will be implemented with CR20A 2.4Ghz module for use with Frsky Taranis.
Phase 4
All schematics will be transferred to KiCad on a single board.
main.cpp@0:ec519775ae6f, 2015-07-08 (annotated)
- Committer:
- Mashu
- Date:
- Wed Jul 08 13:35:50 2015 +0000
- Revision:
- 0:ec519775ae6f
- Child:
- 2:05aaa453fbac
Updated frdm-copter with tested sensors including gyro sampling at 50Hz.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mashu | 0:ec519775ae6f | 1 | #include "mbed.h" |
Mashu | 0:ec519775ae6f | 2 | #include "rtos.h" |
Mashu | 0:ec519775ae6f | 3 | #include "MotionSensor.h" |
Mashu | 0:ec519775ae6f | 4 | #include "FXAS21000.h" |
Mashu | 0:ec519775ae6f | 5 | #include "FXOS8700Q.h" |
Mashu | 0:ec519775ae6f | 6 | |
Mashu | 0:ec519775ae6f | 7 | #include <BLE.h> |
Mashu | 0:ec519775ae6f | 8 | #include <BLEInstanceBase.h> |
Mashu | 0:ec519775ae6f | 9 | #include "UARTService.h" |
Mashu | 0:ec519775ae6f | 10 | |
Mashu | 0:ec519775ae6f | 11 | Serial pc(USBTX, USBRX); |
Mashu | 0:ec519775ae6f | 12 | I2C i2c(PTE25, PTE24); |
Mashu | 0:ec519775ae6f | 13 | I2C i2c_gyro(A4, A5); |
Mashu | 0:ec519775ae6f | 14 | |
Mashu | 0:ec519775ae6f | 15 | FXOS8700QAccelerometer acc(i2c, FXOS8700CQ_SLAVE_ADDR1); // Configured for the FRDM-K64F with onboard sensors |
Mashu | 0:ec519775ae6f | 16 | FXOS8700QMagnetometer mag(i2c, FXOS8700CQ_SLAVE_ADDR1); |
Mashu | 0:ec519775ae6f | 17 | FXAS21000Gyroscpe gyro(i2c_gyro, FXAS21000_SLAVE_ADDR); |
Mashu | 0:ec519775ae6f | 18 | |
Mashu | 0:ec519775ae6f | 19 | BLEDevice ble; |
Mashu | 0:ec519775ae6f | 20 | UARTService *uart; |
Mashu | 0:ec519775ae6f | 21 | |
Mashu | 0:ec519775ae6f | 22 | void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) |
Mashu | 0:ec519775ae6f | 23 | { |
Mashu | 0:ec519775ae6f | 24 | ble.startAdvertising(); |
Mashu | 0:ec519775ae6f | 25 | } |
Mashu | 0:ec519775ae6f | 26 | |
Mashu | 0:ec519775ae6f | 27 | void periodicCallback(void) |
Mashu | 0:ec519775ae6f | 28 | { |
Mashu | 0:ec519775ae6f | 29 | } |
Mashu | 0:ec519775ae6f | 30 | |
Mashu | 0:ec519775ae6f | 31 | int main(void) |
Mashu | 0:ec519775ae6f | 32 | { |
Mashu | 0:ec519775ae6f | 33 | motion_data_units_t acc_data, mag_data, gyro_data; |
Mashu | 0:ec519775ae6f | 34 | |
Mashu | 0:ec519775ae6f | 35 | acc.enable(); |
Mashu | 0:ec519775ae6f | 36 | mag.enable(); |
Mashu | 0:ec519775ae6f | 37 | gyro.enable(); |
Mashu | 0:ec519775ae6f | 38 | //printf("FXOS8700QAccelerometer Who Am I= %X\r\n", acc.whoAmI()); |
Mashu | 0:ec519775ae6f | 39 | //printf("FXOS8700QMagnetometer Who Am I= %X\r\n", acc.whoAmI()); |
Mashu | 0:ec519775ae6f | 40 | //printf("FXAS21000Gyroscope Who am I= %X\r\n", gyro.whoAmI()); |
Mashu | 0:ec519775ae6f | 41 | |
Mashu | 0:ec519775ae6f | 42 | Ticker ticker; |
Mashu | 0:ec519775ae6f | 43 | ticker.attach(periodicCallback, 1); |
Mashu | 0:ec519775ae6f | 44 | |
Mashu | 0:ec519775ae6f | 45 | ble.init(); |
Mashu | 0:ec519775ae6f | 46 | ble.onDisconnection(disconnectionCallback); |
Mashu | 0:ec519775ae6f | 47 | |
Mashu | 0:ec519775ae6f | 48 | uart = new UARTService(ble); |
Mashu | 0:ec519775ae6f | 49 | |
Mashu | 0:ec519775ae6f | 50 | /* setup advertising */ |
Mashu | 0:ec519775ae6f | 51 | ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); |
Mashu | 0:ec519775ae6f | 52 | ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); |
Mashu | 0:ec519775ae6f | 53 | ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, |
Mashu | 0:ec519775ae6f | 54 | (const uint8_t *)"BLE UART", sizeof("BLE UART") - 1); |
Mashu | 0:ec519775ae6f | 55 | ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, |
Mashu | 0:ec519775ae6f | 56 | (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed)); |
Mashu | 0:ec519775ae6f | 57 | |
Mashu | 0:ec519775ae6f | 58 | ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */ |
Mashu | 0:ec519775ae6f | 59 | ble.startAdvertising(); |
Mashu | 0:ec519775ae6f | 60 | |
Mashu | 0:ec519775ae6f | 61 | while (true) { |
Mashu | 0:ec519775ae6f | 62 | // unit based results |
Mashu | 0:ec519775ae6f | 63 | acc.getAxis(acc_data); |
Mashu | 0:ec519775ae6f | 64 | mag.getAxis(mag_data); |
Mashu | 0:ec519775ae6f | 65 | gyro.getAxis(gyro_data); |
Mashu | 0:ec519775ae6f | 66 | /* |
Mashu | 0:ec519775ae6f | 67 | printf("%1.4f,%1.4f,%1.4f,%4.1f,%4.1f,%4.1f,%1.4f,%1.4f,%1.4f\r\n", acc_data.x, acc_data.y, acc_data.z, mag_data.x, mag_data.y, mag_data.z, |
Mashu | 0:ec519775ae6f | 68 | gyro_data.x, gyro_data.y, gyro_data.z); |
Mashu | 0:ec519775ae6f | 69 | */ |
Mashu | 0:ec519775ae6f | 70 | |
Mashu | 0:ec519775ae6f | 71 | printf("%1.4f,%1.4f,%1.4f\r\n", gyro_data.x, gyro_data.y, gyro_data.z); |
Mashu | 0:ec519775ae6f | 72 | ble.waitForEvent(); |
Mashu | 0:ec519775ae6f | 73 | } |
Mashu | 0:ec519775ae6f | 74 | } |