Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/development'
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanademovic committed Jul 13, 2016
2 parents e37b55b + ae021da commit 4b5ccce
Show file tree
Hide file tree
Showing 42 changed files with 1,293 additions and 599 deletions.
14 changes: 6 additions & 8 deletions AK8963.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,20 @@ uint8_t AK8963::getStatusByte() {
bool AK8963::startMeasurement() {
ready = false;
data_to_send[0] = AK8963_XOUT_L;
i2c->addTransfer((uint8_t)AK8963_ADDRESS, (uint8_t)1, &data_to_send[0], (uint8_t)7, &data_to_read[0], this);
i2c->addTransfer(AK8963_ADDRESS, 1, data_to_send, 7, data_to_read, this);
return true;
}

void AK8963::processCallback(uint8_t count, uint8_t *rawData) {
// count should always be 7 if we wanted to check...

uint8_t c = rawData[6]; // ST2 register
void AK8963::triggerCallback() {
uint8_t c = data_to_read[6]; // ST2 register
if (!(c & 0x08)) { // Check if magnetic sensor overflow set, if not then report data
// convert from REGISTER system to IC/PCB system
// "Measurement data is stored in two’s complement and Little Endian format."
// be careful not to misinterpret 2's complement registers
int16_t registerValues[3];
registerValues[0] = (int16_t)(((uint16_t)rawData[1]) << 8) | (uint16_t)rawData[0]; // low byte, high byte
registerValues[1] = (int16_t)(((uint16_t)rawData[3]) << 8) | (uint16_t)rawData[2];
registerValues[2] = (int16_t)(((uint16_t)rawData[5]) << 8) | (uint16_t)rawData[4];
registerValues[0] = (int16_t)(((uint16_t)data_to_read[1]) << 8) | (uint16_t)data_to_read[0]; // low byte, high byte
registerValues[1] = (int16_t)(((uint16_t)data_to_read[3]) << 8) | (uint16_t)data_to_read[2];
registerValues[2] = (int16_t)(((uint16_t)data_to_read[5]) << 8) | (uint16_t)data_to_read[4];
magCount[0] = MAG_XSIGN * registerValues[MAG_XDIR];
magCount[1] = MAG_YSIGN * registerValues[MAG_YDIR];
magCount[2] = MAG_ZSIGN * registerValues[MAG_ZDIR];
Expand Down
2 changes: 1 addition & 1 deletion AK8963.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AK8963 : public CallbackProcessor {
bool ready;

bool startMeasurement(); // writes values to state (when data is ready)
void processCallback(uint8_t count, uint8_t *rawData); // handles return for getAccelGryo()
void triggerCallback(); // handles return for getAccelGryo()

uint8_t getID();

Expand Down
9 changes: 4 additions & 5 deletions BMP280.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,14 @@ boolean BMP280::validateCalibation() {
bool BMP280::startMeasurement(void) {
ready = false;
data_to_send[0] = BMP280_REG_RESULT;
i2c->addTransfer((uint8_t)BMP280_ADDR, (uint8_t)1, data_to_send, (uint8_t)6, data_to_read, this);
i2c->addTransfer(BMP280_ADDR, 1, data_to_send, 6, data_to_read, this);
return true;
}

void BMP280::processCallback(uint8_t count, uint8_t *data) {
// count should always be 6 if we wanted to check...
void BMP280::triggerCallback() {
int32_t rawP, rawT;
rawP = (((int32_t)data[0]) << 12) + (((int32_t)data[1]) << 4) + (((int32_t)data[2]) >> 4);
rawT = (((int32_t)data[3]) << 12) + (((int32_t)data[4]) << 4) + (((int32_t)data[5]) >> 4);
rawP = (((int32_t)data_to_read[0]) << 12) + (((int32_t)data_to_read[1]) << 4) + (((int32_t)data_to_read[2]) >> 4);
rawT = (((int32_t)data_to_read[3]) << 12) + (((int32_t)data_to_read[4]) << 4) + (((int32_t)data_to_read[5]) >> 4);
state->temperature = compensate_T_int32(rawT); // calculate temp first to update t_fine
state->pressure = compensate_P_int64(rawP);
ready = true;
Expand Down
2 changes: 1 addition & 1 deletion BMP280.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class BMP280 : public CallbackProcessor {
uint8_t getID();

bool startMeasurement();
void processCallback(uint8_t count, uint8_t *rawData); // handles return for getPT()
void triggerCallback(); // handles return for getPT()

private:
State *state;
Expand Down
25 changes: 12 additions & 13 deletions MPU9250.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <i2c_t3.h>
#include <stdio.h>
#include <math.h>
#include "board.h"
#include "state.h"

// we have three coordinate systems here:
Expand Down Expand Up @@ -40,7 +41,7 @@ MPU9250::MPU9250(State *__state, I2CManager *__i2c) {
state = __state;
i2c = __i2c;
ready = false;
pinMode(MPU_INTERRUPT, INPUT);
pinMode(board::MPU_INTERRUPT, INPUT);
}

uint8_t MPU9250::getID() {
Expand All @@ -54,7 +55,7 @@ void MPU9250::restart() {
}

bool MPU9250::dataReadyInterrupt() {
return digitalRead(MPU_INTERRUPT); // use the interrupt pin -- be sure to set INT_PIN_CFG
return digitalRead(board::MPU_INTERRUPT); // use the interrupt pin -- be sure to set INT_PIN_CFG
}

uint8_t MPU9250::getStatusByte() {
Expand Down Expand Up @@ -165,33 +166,31 @@ bool MPU9250::startMeasurement() {
if (dataReadyInterrupt()) {
ready = false;
data_to_send[0] = ACCEL_XOUT_H;
i2c->addTransfer((uint8_t)MPU9250_ADDRESS, (uint8_t)1, &data_to_send[0], (uint8_t)14, &data_to_read[0], this);
i2c->addTransfer(MPU9250_ADDRESS, 1, data_to_send, 14, data_to_read, this);
return true;
}
return false;
}

void MPU9250::processCallback(uint8_t count, uint8_t *rawData) {
// count should always be 14 if we wanted to check...

void MPU9250::triggerCallback() {
// convert from REGISTER system to IC/PCB system
int16_t registerValuesAccel[3];
// be careful not to misinterpret 2's complement registers
registerValuesAccel[0] = (int16_t)(((uint16_t)rawData[0]) << 8) | (uint16_t)rawData[1]; // high byte, low byte
registerValuesAccel[1] = (int16_t)(((uint16_t)rawData[2]) << 8) | (uint16_t)rawData[3];
registerValuesAccel[2] = (int16_t)(((uint16_t)rawData[4]) << 8) | (uint16_t)rawData[5];
registerValuesAccel[0] = (int16_t)(((uint16_t)data_to_read[0]) << 8) | (uint16_t)data_to_read[1]; // high byte, low byte
registerValuesAccel[1] = (int16_t)(((uint16_t)data_to_read[2]) << 8) | (uint16_t)data_to_read[3];
registerValuesAccel[2] = (int16_t)(((uint16_t)data_to_read[4]) << 8) | (uint16_t)data_to_read[5];
accelCount[0] = ACCEL_XSIGN * registerValuesAccel[ACCEL_XDIR];
accelCount[1] = ACCEL_YSIGN * registerValuesAccel[ACCEL_YDIR];
accelCount[2] = ACCEL_ZSIGN * registerValuesAccel[ACCEL_ZDIR];

// be careful not to misinterpret 2's complement registers
temperatureCount[0] = (int16_t)(((uint16_t)rawData[6]) << 8) | (uint16_t)rawData[7];
temperatureCount[0] = (int16_t)(((uint16_t)data_to_read[6]) << 8) | (uint16_t)data_to_read[7];

int16_t registerValuesGyro[3];
// be careful not to misinterpret 2's complement registers
registerValuesGyro[0] = (int16_t)(((uint16_t)rawData[8]) << 8) | (uint16_t)rawData[9]; // high byte, low byte
registerValuesGyro[1] = (int16_t)(((uint16_t)rawData[10]) << 8) | (uint16_t)rawData[11];
registerValuesGyro[2] = (int16_t)(((uint16_t)rawData[12]) << 8) | (uint16_t)rawData[13];
registerValuesGyro[0] = (int16_t)(((uint16_t)data_to_read[8]) << 8) | (uint16_t)data_to_read[9]; // high byte, low byte
registerValuesGyro[1] = (int16_t)(((uint16_t)data_to_read[10]) << 8) | (uint16_t)data_to_read[11];
registerValuesGyro[2] = (int16_t)(((uint16_t)data_to_read[12]) << 8) | (uint16_t)data_to_read[13];
gyroCount[0] = GYRO_XSIGN * registerValuesGyro[GYRO_XDIR];
gyroCount[1] = GYRO_YSIGN * registerValuesGyro[GYRO_YDIR];
gyroCount[2] = GYRO_ZSIGN * registerValuesGyro[GYRO_ZDIR];
Expand Down
4 changes: 1 addition & 3 deletions MPU9250.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MPU9250 : public CallbackProcessor {
void forgetBiasValues(); // discard bias values

bool startMeasurement();
void processCallback(uint8_t count, uint8_t *rawData); // handles return for getAccelGryo()
void triggerCallback(); // handles return for getAccelGryo()

float getTemp() {
return (float)temperatureCount[0] / 333.87 + 21.0;
Expand Down Expand Up @@ -73,8 +73,6 @@ class MPU9250 : public CallbackProcessor {

#define DEG2RAD 0.01745329251f

#define MPU_INTERRUPT 17 // 36

//*************************************************************
//
// MPU Registers (See Table 1 Register Map on page 7)
Expand Down
13 changes: 7 additions & 6 deletions R415X.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include "R415X.h"
#include "board.h"

volatile uint16_t RX[RC_CHANNEL_COUNT]; // filled by the interrupt with valid data
volatile uint16_t RX_errors = 0; // count dropped frames
Expand All @@ -13,12 +14,12 @@ volatile uint16_t RX_buffer[RC_CHANNEL_COUNT]; // buffer data in anticipation o
volatile uint8_t RX_channel = 0; // we are collecting data for this channel

R415X::R415X() {
attemptToBind(50);
initialize_isr();
attemptToBind(50); //this calls initialize_isr
//initialize_isr();
}

void R415X::initialize_isr(void) {
pinMode(RX_DAT, INPUT); // WE ARE ASSUMING RX_DAT IS PIN 3 IN FTM1 SETUP!
pinMode(board::RX_DAT, INPUT); // WE ARE ASSUMING RX_DAT IS PIN 3 IN FTM1 SETUP!

for (uint8_t i = 0; i <= RC_CHANNEL_COUNT; i++) {
RX[i] = 1100;
Expand Down Expand Up @@ -73,10 +74,10 @@ extern "C" void ftm1_isr(void) {
}

void R415X::attemptToBind(uint16_t milliseconds) {
pinMode(RX_DAT, OUTPUT);
digitalWrite(RX_DAT, LOW);
pinMode(board::RX_DAT, OUTPUT);
digitalWrite(board::RX_DAT, LOW);
delay(milliseconds);
pinMode(RX_DAT, INPUT); // WE ARE ASSUMING RX_DAT IS PIN 3 IN FTM1 SETUP!
pinMode(board::RX_DAT, INPUT); // WE ARE ASSUMING RX_DAT IS PIN 3 IN FTM1 SETUP!

// after we bind, we must setup our timer again.
initialize_isr();
Expand Down
2 changes: 0 additions & 2 deletions R415X.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ extern volatile uint16_t startPulse; // keeps track of the last received pulse
extern volatile uint16_t RX_buffer[RC_CHANNEL_COUNT]; // buffer data in anticipation of a valid frame
extern volatile uint8_t RX_channel; // we are collecting data for this channel

// pin definitions
#define RX_DAT 3 // 28 --- MUST BE PIN 3
#define RX_PPM_SYNCPULSE_MIN 7500 // 2.5ms
#define RX_PPM_SYNCPULSE_MAX 48000 // 16 ms (seems to be about 13.4ms on the scope)

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# flybrix-firmware

Flybrix is still in alpha, but we're excited to annouce our first open source code release!
Flybrix is in beta and still changing from time to time.

Dependencies:

* arduino 1.6.7 from https://www.arduino.cc/en/Main/Software
* teensyduino libraries from https://www.pjrc.com/teensy/teensyduino.html
* teensy loader from https://www.pjrc.com/teensy/loader.html
* SDFat library must be patched to use nonstandard pins (see 'SdSpiTeensy3.cpp.diff')


Tips:

If you can't compile because it appears that you're missing the ADC or i2c_t3 libraries,
If you can't compile because it appears that you're missing libraries,
be sure that you have set up the Arduino IDE to target the correct board ("Teensy 3.2 / 3.1")!

The Arduino IDE defaults to expand tabs with 2 spaces. To change that edit your preferences file.
Expand Down
8 changes: 8 additions & 0 deletions SdSpiTeensy3.cpp.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
91,93c91,93
< CORE_PIN11_CONFIG = PORT_PCR_DSE | PORT_PCR_MUX(2);
< CORE_PIN12_CONFIG = PORT_PCR_MUX(2);
< CORE_PIN13_CONFIG = PORT_PCR_DSE | PORT_PCR_MUX(2);
---
> CORE_PIN7_CONFIG = PORT_PCR_DSE | PORT_PCR_MUX(2);
> CORE_PIN8_CONFIG = PORT_PCR_MUX(2);
> CORE_PIN14_CONFIG = PORT_PCR_DSE | PORT_PCR_MUX(2);
16 changes: 4 additions & 12 deletions airframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
*/

#include "airframe.h"

#include <Arduino.h>
#include "config.h" //CONFIG variable

#include "state.h"

Airframe::Airframe(State* __state) {
state = __state;
Airframe::Airframe(State* state) : state(state) {
}

uint16_t Airframe::mix(int32_t mFz, int32_t mTx, int32_t mTy, int32_t mTz) {
Expand All @@ -20,12 +18,6 @@ uint16_t Airframe::mix(int32_t mFz, int32_t mTx, int32_t mTy, int32_t mTz) {
}

void Airframe::updateMotorsMix() {
state->MotorOut[0] = mix(CONFIG.data.mixTableFz[0], CONFIG.data.mixTableTx[0], CONFIG.data.mixTableTy[0], CONFIG.data.mixTableTz[0]);
state->MotorOut[1] = mix(CONFIG.data.mixTableFz[1], CONFIG.data.mixTableTx[1], CONFIG.data.mixTableTy[1], CONFIG.data.mixTableTz[1]);
state->MotorOut[2] = mix(CONFIG.data.mixTableFz[2], CONFIG.data.mixTableTx[2], CONFIG.data.mixTableTy[2], CONFIG.data.mixTableTz[2]);
state->MotorOut[3] = mix(CONFIG.data.mixTableFz[3], CONFIG.data.mixTableTx[3], CONFIG.data.mixTableTy[3], CONFIG.data.mixTableTz[3]);
state->MotorOut[4] = mix(CONFIG.data.mixTableFz[4], CONFIG.data.mixTableTx[4], CONFIG.data.mixTableTy[4], CONFIG.data.mixTableTz[4]);
state->MotorOut[5] = mix(CONFIG.data.mixTableFz[5], CONFIG.data.mixTableTx[5], CONFIG.data.mixTableTy[5], CONFIG.data.mixTableTz[5]);
state->MotorOut[6] = mix(CONFIG.data.mixTableFz[6], CONFIG.data.mixTableTx[6], CONFIG.data.mixTableTy[6], CONFIG.data.mixTableTz[6]);
state->MotorOut[7] = mix(CONFIG.data.mixTableFz[7], CONFIG.data.mixTableTx[7], CONFIG.data.mixTableTy[7], CONFIG.data.mixTableTz[7]);
for (size_t i = 0; i < 8; ++i)
state->MotorOut[i] = mix(CONFIG.data.mixTableFz[i], CONFIG.data.mixTableTx[i], CONFIG.data.mixTableTy[i], CONFIG.data.mixTableTz[i]);
}
2 changes: 1 addition & 1 deletion airframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#ifndef airframe_h
#define airframe_h

#include "Arduino.h"
#include <cstdint>

class State;

Expand Down
Loading

0 comments on commit 4b5ccce

Please sign in to comment.