Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rhockenbury committed Jan 26, 2014
1 parent 46a414a commit 1d2d6fe
Show file tree
Hide file tree
Showing 37 changed files with 1,174 additions and 572 deletions.
88 changes: 76 additions & 12 deletions Quad2/.cproject

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions Quad2/.project
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
<nature>it.baeyens.arduinonature</nature>
</natures>
<linkedResources>
<link>
<name>EEPROM</name>
<type>2</type>
<locationURI>ArduinoLibPath/EEPROM</locationURI>
</link>
<link>
<name>Servo</name>
<type>2</type>
Expand Down
2 changes: 1 addition & 1 deletion Quad2/Libraries/Quad_Accelerometer/ADXL345.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

#include "ADXL345.h"
#include "../Quad_Defines/globals.h"
#include "globals.h"

ADXL345::ADXL345() {
devAddr = ADXL345_ADDR;
Expand Down
2 changes: 1 addition & 1 deletion Quad2/Libraries/Quad_Accelerometer/ADXL345.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#ifndef ADXL345_h
#define ADXL345_h

#include "../Quad_I2C/I2Cdev.h"
#include "I2Cdev.h"
#include <inttypes.h>

#define ADXL345_ADDR 0x53
Expand Down
14 changes: 13 additions & 1 deletion Quad2/Libraries/Quad_BatteryMonitor/battMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

#include "battMonitor.h"
#include "../Quad_Defines/globals.h"
#include "globals.h"
#include <Arduino.h>

// Constructor
Expand All @@ -31,7 +31,19 @@ battMonitor::battMonitor()

}

bool battMonitor::init() {
float v = getProcessedBattVoltage();

if(v < V_FULL) {
return false;
Serial.println("Battery is not fully charged");
}
else {
return true;
}

return false;
}

// Method to read raw battery voltage on analog pin
int battMonitor::getRawBattVoltage()
Expand Down
6 changes: 4 additions & 2 deletions Quad2/Libraries/Quad_BatteryMonitor/battMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#define V_SENSITIVITY 12.99 // for 180Amp board
#define I_SENSITIVITY 3.7

#define V_FULL 16.8 // volts (4S lipo)
#define V_EMPTY 13.2 // volts (4s lipo)
#define V_FULL (4*4.05) // volts (4S lipo)
#define V_EMPTY (4*3.35) // volts (4s lipo)

#define INITIAL_CAPACITY 4000 // 4 amp-hours

Expand All @@ -37,6 +37,8 @@ class battMonitor
public:
battMonitor();

bool init();

int getRawBattVoltage();
int getRawBattCurrent();

Expand Down
47 changes: 26 additions & 21 deletions Quad2/Libraries/Quad_Compass/HMC5883L.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

#include "HMC5883L.h"
#include "../Quad_Defines/globals.h"
#include "globals.h"



Expand Down Expand Up @@ -91,28 +91,33 @@ void HMC5883L::setMode(uint8_t mode) {
* Place offsets in offset variables
*/
void HMC5883L::setOffset() {
int32_t sumX = 0;
int32_t sumY = 0;
int32_t sumZ = 0;
if(compStatus == ON) {
int32_t sumX = 0;
int32_t sumY = 0;
int32_t sumZ = 0;

for(uint8_t i = 0; i < 10; i++) {
getRawData(); // read raw data
for(uint8_t i = 0; i < 10; i++) {
getRawData(); // read raw data

sumX = sumX + (int32_t) data[X];
sumY = sumY + (int32_t) data[Y];
sumZ = sumZ + (int32_t) data[Z];

// delay long enough for another sample
// to be available on the sensor
// @ 75 Hz -> 0.014 sec
delay(14);
}

// TODO: fix this
//offset[X] = (float) sumX / 10.0;
//offset[Y] = (float) sumY / 10.0;
//offset[Z] = 0.0;// (float) sumZ / 10.0 - (float) HMC5883L_SENSITIVITY2;
vehicleStatus = vehicleStatus | MAG_READY;
sumX = sumX + (int32_t) data[X];
sumY = sumY + (int32_t) data[Y];
sumZ = sumZ + (int32_t) data[Z];

// delay long enough for another sample
// to be available on the sensor
// @ 75 Hz -> 0.014 sec
delay(14);
}

// TODO: fix this
//offset[X] = (float) sumX / 10.0;
//offset[Y] = (float) sumY / 10.0;
//offset[Z] = 0.0;// (float) sumZ / 10.0 - (float) HMC5883L_SENSITIVITY2;
vehicleStatus = vehicleStatus | MAG_READY;
}
else {
Serial.println("WARNING: mag is not online -> cannot be zeroed");
}
}

/*
Expand Down
2 changes: 1 addition & 1 deletion Quad2/Libraries/Quad_Compass/HMC5883L.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#ifndef HMC5883L_h
#define HMC5883L_h

#include "../Quad_I2C/I2Cdev.h"
#include "I2Cdev.h"
#include <inttypes.h>

#define HMC5883L_ADDR 0x1E
Expand Down
12 changes: 6 additions & 6 deletions Quad2/Libraries/Quad_Defines/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
#define YAW_AXIS 2
#define THROTTLE_AXIS 3

#define TRUE 1
#define FALSE 0

#define ON 1
#define OFF 0

Expand All @@ -40,18 +37,21 @@
extern bool inFlight;
extern uint8_t vehicleStatus;

#define SENSORS_ONLINE ((vehicleStatus & 0x7) == 0x7) // ==
#define SENSORS_ONLINE ((vehicleStatus & 0x7) == 0x7)
#define BATT_ONLINE ((vehicleStatus & BATT_READY) == BATT_READY)
#define RX_ONLINE ((vehicleStatus & RX_READY) == RX_READY)
#define MOTORS_ONLINE ((vehicleStatus & MOTOR_READY) == 0x64)
#define MOTORS_ONLINE ((vehicleStatus & MOTOR_READY) == MOTOR_READY)
#define SYSTEM_ONLINE ((vehicleStatus & 0xFF) == 0xFF)

// 6 channels - roll, pitch, throttle, yaw, mode, aux1
// 8 channels - roll, pitch, throttle, yaw, mode, aux1, aux2, aux3
#define ROLL_CHANNEL 0
#define PITCH_CHANNEL 1
#define THROTTLE_CHANNEL 2
#define YAW_CHANNEL 3
#define MODE_CHANNEL 4
#define AUX1_CHANNEL 5
#define AUX2_CHANNEL 6
#define AUX3_CHANNEL 7

#define MICROS 1000000.0 // 1 second = 1*10^6 microseconds
#define MILLIS 1000.0 // 1 second = 1*10^3 milliseconds
Expand Down
163 changes: 124 additions & 39 deletions Quad2/Libraries/Quad_EEPROM/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,82 +7,167 @@
* Read and write from EEPROM
*/

#include "storage.h"

void readEEPROM() {

void Storage::writePidPValue(float value, int address) {
writeFloat(value, address);
}

void writeEEPROM() {

void Storage::writePidIValue(float value, int address) {
writeFloat(value, address);
}

void Storage::writePidDValue(float value, int address) {
writeFloat(value, address);
}

float readFloat(int address) {
union floatStore {
byte floatByte[4];
unsigned short floatUShort[2];
float floatVal;
} floatOut;

void Storage::writeRadioSmoothFactorValue(float value, int address){
writeFloat(value, address);
}

for (int i = 0; i < 4; i++) {
floatOut.floatByte[i] = EEPROM.read(address + i);
}
/*
* Methods to read values will use default values if
* the USE_DEFAULT_VALUES is set, or no value is stored
*/

return floatOut.floatVal;
float Storage::readPidPValue(int address) {
float value;

#ifdef USE_DEFAULT_VALUES
value = PID_P;
writePidPValue(value);
#else
value = readFloat(address);
if(value == 0x0 || value == 0xFFFFFFFF) {
value = PID_P;
writePidPValue(value);
}
#endif

return value;
}

void writeFloat(float value, int address) {
union floatStore {
byte floatByte[4];
unsigned short floatUShort[2];
float floatVal;
} floatIn;
float Storage::readPidIValue(int address) {
float value;

#ifdef USE_DEFAULT_VALUES
value = PID_I;
writePidPValue(value);
#else
value = readFloat(address);
if(value == 0x0 || value == 0xFFFFFFFF) {
value = PID_I;
writePidIValue(value);
}
#endif

return value;
}

floatIn.floatVal = value;
float Storage::readPidDValue(int address) {
float value;

#ifdef USE_DEFAULT_VALUES
value = PID_D;
writePidPValue(value);
#else
value = readFloat(address);
if(value == 0x0 || value == 0xFFFFFFFF) {
value = PID_D;
writePidDValue(value);
}
#endif

return value;
}

for (int i = 0; i < 4; i++) {
EEPROM.write(address + i, floatIn.floatByte[i]);
}
float Storage::readRadioSmoothFactorValue(int address) {
float value;

#ifdef USE_DEFAULT_VALUES
value = RADIO_SMOOTH_FACTOR;
writePidPValue(value);
#else
value = readFloat(address);
if(value == 0x0 || value == 0xFFFFFFFF) {
value = PID_D;
writePidDValue(value);
}
#endif

return value;
}

void updateFloat(float value, int address) {

/*
* Utility method to read a float from an address
*/
float Storage::readFloat(int address) {
union floatStore {
byte floatByte[4];
unsigned short floatUShort[2];
float floatVal;
} floatOut;

for (int i = 0; i < 4; i++) {
floatOut.floatByte[i] = EEPROM.read(address + i);
}

return floatOut.floatVal;
}

/*
* Utility method to write a float to an address
*/
void Storage::writeFloat(float value, int address) {
union floatStore {
byte floatByte[4];
unsigned short floatUShort[2];
float floatVal;
} floatIn;

floatIn.floatVal = value;

for (int i = 0; i < 4; i++) {
EEPROM.write(address + i, floatIn.floatByte[i]);
}
}

long readLong(int address) {
/*
* Utility method to read a long from an address
*/
long Storage::readLong(int address) {
union longStore {
byte longByte[4];
unsigned short longUShort[2];
long longVal;
byte longByte[4];
unsigned short longUShort[2];
long longVal;
} longOut;

for (byte i = 0; i < 4; i++) {
longOut.longByte[i] = EEPROM.read(address + i);
}

return longOut.longVal;
}
}

void writeLong(long value, int address) {
/*
* Utility method to write a long to an address
*/
void Storage::writeLong(long value, int address) {
union longStore {
byte longByte[4];
unsigned short longUShort[2];
long longVal;
byte longByte[4];
unsigned short longUShort[2];
long longVal;
} longIn;

longIn.longVal = value;

for (int i = 0; i < 4; i++) {
EEPROM.write(address + i, longIn.longByte[i]);
}
}

}

void updateLong(long vaue, int address) {

}



Expand Down
Loading

0 comments on commit 1d2d6fe

Please sign in to comment.