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:

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

Committer:
Mashu
Date:
2015-07-08
Revision:
0:ec519775ae6f
Child:
2:05aaa453fbac

File content as of revision 0:ec519775ae6f:

#include "mbed.h"
#include "rtos.h"
#include "MotionSensor.h"
#include "FXAS21000.h"
#include "FXOS8700Q.h"

#include <BLE.h>
#include <BLEInstanceBase.h>
#include "UARTService.h"

Serial pc(USBTX, USBRX);
I2C i2c(PTE25, PTE24);
I2C i2c_gyro(A4, A5);

FXOS8700QAccelerometer acc(i2c, FXOS8700CQ_SLAVE_ADDR1);    // Configured for the FRDM-K64F with onboard sensors
FXOS8700QMagnetometer mag(i2c, FXOS8700CQ_SLAVE_ADDR1);
FXAS21000Gyroscpe gyro(i2c_gyro, FXAS21000_SLAVE_ADDR);
 
BLEDevice  ble;
UARTService *uart;

void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
{
    ble.startAdvertising();
}
 
void periodicCallback(void)
{
}
 
int main(void)
{
    motion_data_units_t acc_data, mag_data, gyro_data;
    
    acc.enable();
    mag.enable();
    gyro.enable();
    //printf("FXOS8700QAccelerometer Who Am I= %X\r\n", acc.whoAmI());
    //printf("FXOS8700QMagnetometer Who Am I= %X\r\n", acc.whoAmI());
    //printf("FXAS21000Gyroscope Who am I= %X\r\n", gyro.whoAmI());
    
    Ticker ticker;
    ticker.attach(periodicCallback, 1);
 
    ble.init();
    ble.onDisconnection(disconnectionCallback);
    
    uart = new UARTService(ble);
 
    /* setup advertising */
    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
    ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
    ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
                                     (const uint8_t *)"BLE UART", sizeof("BLE UART") - 1);
    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
                                     (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed));
 
    ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
    ble.startAdvertising();
    
    while (true) {
        // unit based results
        acc.getAxis(acc_data);
        mag.getAxis(mag_data);
        gyro.getAxis(gyro_data);
        /*
        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,
        gyro_data.x, gyro_data.y, gyro_data.z);
        */
     
        printf("%1.4f,%1.4f,%1.4f\r\n", gyro_data.x, gyro_data.y, gyro_data.z);
        ble.waitForEvent();
    }
}