Skip to content

Commit

Permalink
Merge branch 'upstream_shared' into landinglights
Browse files Browse the repository at this point in the history
Conflicts:
	config.h
  • Loading branch information
wertarbyte committed May 20, 2012
2 parents 8199a02 + 16e9bd6 commit db7cb88
Show file tree
Hide file tree
Showing 11 changed files with 1,219 additions and 908 deletions.
7 changes: 5 additions & 2 deletions Buzzer.pde
@@ -1,8 +1,11 @@
static uint8_t buzzerIsOn = 0;

uint8_t isBuzzerON() { return buzzerIsOn; } // returns true while buzzer is buzzing; returns 0 for silent periods

void buzzer(uint8_t warn_vbat){
static uint16_t ontime, offtime, beepcount, repeat, repeatcounter;
static uint32_t buzzerLastToggleTime;
static uint8_t buzzerIsOn = 0,
activateBuzzer,
static uint8_t activateBuzzer,
beeperOnBox,
i,
last_rcOptions[CHECKBOXITEMS],
Expand Down
30 changes: 27 additions & 3 deletions CREDITS.txt
Expand Up @@ -91,10 +91,10 @@ E:
W: http://fotoflygarn.blogspot.se/2012/04/multiwii-helicopter.html

S: i2c LCD03
D:
N:
D: Support for the cheap i2c LCD03
N: Th0rsten
E:
W:
W: http://www.multiwii.com/forum/viewtopic.php?f=8&t=1094

S: i2c OLED 128x64 display
D: support for OLED as alternatative to LCD
Expand Down Expand Up @@ -238,3 +238,27 @@ N: Stefan Tomanek
N: Jevermeister (Nils Ivo von Aswege)
E:
W:http://ncopters.blogspot.com

S: Atmega32u4 support
D: so it works on Promicro, & Teensy20
N: Felix Niessen (ronco)
E: felix.niessen@googlemail.com
W:

S: 11-bit PWM
D: Better Signal resolution for the ESC's on MEGA's and 32u4's
N: Felix Niessen (ronco)
E: felix.niessen@googlemail.com
W:

S: Hexa with Servos and Octo on Promini
D:
N: Felix Niessen (ronco)
E: felix.niessen@googlemail.com
W:

S: Faster Servo refreshrate & 11-bit PWM (for servos on the MEGA & 32u4)
D:
N: Felix Niessen (ronco)
E: felix.niessen@googlemail.com
W:
34 changes: 24 additions & 10 deletions EEPROM.pde
@@ -1,6 +1,7 @@
#include <avr/eeprom.h>

static uint8_t checkNewConf = 154;
#define EEPROM_CONF_VERSION 155
static uint8_t checkNewConf;

struct eep_entry_t{
void * var;
Expand All @@ -11,7 +12,7 @@ struct eep_entry_t{
// EEPROM Layout definition
// ************************************************************************************************************
static eep_entry_t eep_entry[] = {
{&checkNewConf, sizeof(checkNewConf)}
{&checkNewConf, sizeof(checkNewConf)} // this is only left here to keep the read/write logic intact
, {&P8, sizeof(P8)}
, {&I8, sizeof(I8)}
, {&D8, sizeof(D8)}
Expand All @@ -34,7 +35,7 @@ static eep_entry_t eep_entry[] = {
#ifdef TRI
, {&tri_yaw_middle, sizeof(tri_yaw_middle)}
#endif

, {&checkNewConf, sizeof(checkNewConf)} // this _must_ be the last entry always.
};
#define EEBLOCK_SIZE sizeof(eep_entry)/sizeof(eep_entry_t)
// ************************************************************************************************************
Expand All @@ -61,16 +62,26 @@ void readEEPROM() {
pAlarm = (uint32_t) powerTrigger1 * (uint32_t) PLEVELSCALE * (uint32_t) PLEVELDIV; // need to cast before multiplying
#endif
#ifdef FLYING_WING
wing_left_mid = constrain(wing_left_mid, WING_LEFT_MIN, WING_LEFT_MAX); //LEFT
wing_right_mid = constrain(wing_right_mid, WING_RIGHT_MIN, WING_RIGHT_MAX); //RIGHT
#ifdef LCD_CONF
wing_left_mid = constrain(wing_left_mid, WING_LEFT_MIN, WING_LEFT_MAX); //LEFT
wing_right_mid = constrain(wing_right_mid, WING_RIGHT_MIN, WING_RIGHT_MAX); //RIGHT
#else // w.o LCD support user may not find this value stored in eeprom, so always use the define value
wing_left_mid = WING_LEFT_MID;
wing_right_mid = WING_RIGHT_MID;
#endif
#endif
#ifdef TRI
tri_yaw_middle = constrain(tri_yaw_middle, TRI_YAW_CONSTRAINT_MIN, TRI_YAW_CONSTRAINT_MAX); //REAR
#ifdef LCD_CONF
tri_yaw_middle = constrain(tri_yaw_middle, TRI_YAW_CONSTRAINT_MIN, TRI_YAW_CONSTRAINT_MAX); //REAR
#else // w.o LCD support user may not find this value stored in eeprom, so always use the define value
tri_yaw_middle = TRI_YAW_MIDDLE;
#endif
#endif
}

void writeParams(uint8_t b) {
uint8_t i, _address = 0;
checkNewConf = EEPROM_CONF_VERSION; // make sure we write the current version into eeprom
for(i=0; i<EEBLOCK_SIZE; i++) {
eeprom_write_block(eep_entry[i].var, (void*)(_address), eep_entry[i].size); _address += eep_entry[i].size;
}
Expand All @@ -79,8 +90,7 @@ void writeParams(uint8_t b) {
}

void checkFirstTime() {
uint8_t test_val; eeprom_read_block((void*)&test_val, (void*)(0), sizeof(test_val));
if (test_val == checkNewConf) return;
if (EEPROM_CONF_VERSION == checkNewConf) return;
P8[ROLL] = 40; I8[ROLL] = 30; D8[ROLL] = 23;
P8[PITCH] = 40; I8[PITCH] = 30; D8[PITCH] = 23;
P8[YAW] = 85; I8[YAW] = 45; D8[YAW] = 0;
Expand All @@ -101,8 +111,12 @@ void checkFirstTime() {
wing_left_mid = WING_LEFT_MID;
wing_right_mid = WING_RIGHT_MID;
#endif
#ifdef FIXEDWING
dynThrPID = 50;
rcExpo8 = 0;
#endif
#ifdef TRI
tri_yaw_middle = TRI_YAW_MIDDLE;
#endif
writeParams(0);
}
writeParams(0); // this will also (p)reset checkNewConf with the current version number again.
}
7 changes: 6 additions & 1 deletion GPS.pde
Expand Up @@ -14,6 +14,7 @@ void GPS_NewData() {
if (!GPS_fix_home) { //if home is not set set home position to WP#0 and activate it
i2c_rep_start(I2C_GPS_ADDRESS);i2c_write(I2C_GPS_COMMAND);i2c_write(I2C_GPS_COMMAND_SET_WP);//Store current position to WP#0 (this is used for RTH)
i2c_rep_start(I2C_GPS_ADDRESS);i2c_write(I2C_GPS_COMMAND);i2c_write(I2C_GPS_COMMAND_ACTIVATE_WP);//Set WP#0 as the active WP
GPS_altitude_home = GPS_altitude; //Store Home altitude
GPS_fix_home = 1; //Now we have a home
}
if (_i2c_gps_status & I2C_GPS_STATUS_NEW_DATA) { //Check about new data
Expand Down Expand Up @@ -79,6 +80,8 @@ void GPS_NewData() {
GPS_fix_home = 1;
GPS_latitude_home = GPS_latitude;
GPS_longitude_home = GPS_longitude;
GPS_altitude_home = GPS_altitude;

}
if (GPSModeHold == 1)
GPS_distance(GPS_latitude_hold,GPS_longitude_hold,GPS_latitude,GPS_longitude, &GPS_distanceToHold, &GPS_directionToHold);
Expand All @@ -96,6 +99,7 @@ void GPS_NewData() {
GPS_fix_home = 1;
GPS_latitude_home = GPS_latitude;
GPS_longitude_home = GPS_longitude;
GPS_altitude_home = GPS_altitude;
}
if (GPSModeHold == 1)
GPS_distance(GPS_latitude_hold,GPS_longitude_hold,GPS_latitude,GPS_longitude, &GPS_distanceToHold, &GPS_directionToHold);
Expand Down Expand Up @@ -221,6 +225,7 @@ bool GPS_newFrame(char c) {
else if (param == 9) {GPS_altitude = grab_fields(string,0);} // altitude in meters added by Mis
} else if (frame == FRAME_RMC) {
if (param == 7) {GPS_speed = ((uint32_t)grab_fields(string,1)*514444L)/100000L;} // speed in cm/s added by Mis
if (param == 8) {GPS_ground_course = grab_fields(string,0)*10 ;} // GPS_ground_course added by PatrikE
}
param++; offset = 0;
if (c == '*') checksum_param=1;
Expand All @@ -241,4 +246,4 @@ bool GPS_newFrame(char c) {
}

#endif
#endif
#endif
3 changes: 2 additions & 1 deletion IMU.pde
Expand Up @@ -61,7 +61,8 @@ void computeIMU () {
static uint8_t Smoothing[3] = GYRO_SMOOTHING; // How much to smoothen with per axis
static int16_t gyroSmooth[3] = {0,0,0};
for (axis = 0; axis < 3; axis++) {
gyroData[axis] = (gyroSmooth[axis]*(Smoothing[axis]-1)+gyroData[axis])/Smoothing[axis];
gyroData[axis] = (int16_t) ( ( (int32_t)((int32_t)gyroSmooth[axis] * (Smoothing[axis]-1) )+gyroData[axis]+1 ) / Smoothing[axis]);
// was :gyroData[axis] = (gyroSmooth[axis]*(Smoothing[axis]-1)+gyroData[axis])/Smoothing[axis];
gyroSmooth[axis] = gyroData[axis];
}
#elif defined(TRI)
Expand Down
6 changes: 4 additions & 2 deletions LCD.pde
Expand Up @@ -1163,7 +1163,7 @@ void fill_line2_AmaxA() {
}
void fill_line1_VmA() {
strcpy_P(line1,PSTR("--.-V -----mAh")); // uint8_t vbat, intPowerMeterSum
// 0123456789.12345
// 0123456789.12345
#ifdef VBAT
line1[0] = digit100(vbat);
line1[1] = digit10(vbat);
Expand All @@ -1176,7 +1176,7 @@ void fill_line1_VmA() {
line1[11] = digit10(intPowerMeterSum);
line1[12] = digit1(intPowerMeterSum);
#endif
if (buzzerState) { // buzzer on? then add some blink for attention
if (isBuzzerON()) { // buzzer on? then add some blink for attention
line1[5] = '+'; line1[6] = '+'; line1[7] = '+';
}
// set mark, if we had i2c errors, failsafes or annex650 overruns
Expand Down Expand Up @@ -1467,11 +1467,13 @@ void lcd_telemetry() {
case 0:// V, mAh
LCDsetLine(1);
fill_line1_VmA();
if (isBuzzerON()) { LCDattributesReverse(); } // buzzer on? then add some blink for attention
LCDprintChar(line1);
break;
case 1:// V, mAh bars
LCDsetLine(2);
output_VmAbars();
LCDattributesOff(); // turn Reverse off for rest of display
break;
case 2:// A, maxA
LCDsetLine(3);
Expand Down
40 changes: 27 additions & 13 deletions MultiWii.ino
Expand Up @@ -11,7 +11,7 @@ March 2012 V2.0
#include "config.h"
#include "def.h"
#include <avr/pgmspace.h>
#define VERSION 200
#define VERSION 201

/*********** RC alias *****************/
#define ROLL 0
Expand Down Expand Up @@ -74,7 +74,6 @@ static int32_t EstAlt; // in cm
static int16_t BaroPID = 0;
static int32_t AltHold;
static int16_t errorAltitudeI = 0;
static uint8_t buzzerState = 0;
static uint8_t toggleBeep = 0;
static int16_t debug1,debug2,debug3,debug4;
static int16_t sonarAlt; //to think about the unit
Expand Down Expand Up @@ -169,13 +168,13 @@ static uint16_t activate[CHECKBOXITEMS];
// GPS
// **********************
static int32_t GPS_latitude,GPS_longitude;
static int32_t GPS_latitude_home,GPS_longitude_home;
static int32_t GPS_latitude_hold,GPS_longitude_hold;
static int32_t GPS_latitude_home,GPS_longitude_home,GPS_altitude_home;
static int32_t GPS_latitude_hold,GPS_longitude_hold,GPS_altitude_hold;
static uint8_t GPS_fix , GPS_fix_home = 0;
static uint8_t GPS_numSat;
static uint16_t GPS_distanceToHome,GPS_distanceToHold; // distance to home or hold point in meters
static int16_t GPS_directionToHome,GPS_directionToHold; // direction to home or hol point in degrees
static uint16_t GPS_altitude,GPS_speed; // altitude in 0.1m and speed in 0.1m/s
static int16_t GPS_altitude,GPS_speed; // altitude in 0.1m and speed in 0.1m/s
static uint8_t GPS_update = 0; // it's a binary toogle to distinct a GPS position update
static int16_t GPS_angle[2] = { 0, 0}; // it's the angles that must be applied for GPS correction

Expand Down Expand Up @@ -279,7 +278,7 @@ void annexCode() { // this code is excetuted at each loop and won't interfere wi
#endif
) || (NO_VBAT>vbat) ) // ToLuSe
{ // VBAT ok AND powermeter ok, buzzer off
buzzerFreq = 0; buzzerState = 0;
buzzerFreq = 0;
#if defined(POWERMETER)
} else if (pMeter[PMOTOR_SUM] > pAlarm) { // sound alarm for powermeter
buzzerFreq = 4;
Expand Down Expand Up @@ -520,14 +519,25 @@ void loop () {
headFreeModeHold = heading;
} else if (armed) armed = 0;
rcDelayCommand = 0;
} else if ( (rcData[YAW] < MINCHECK || rcData[ROLL] < MINCHECK) && armed == 1) {
#ifdef ALLOW_ARM_DISARM_VIA_TX_YAW
} else if ( (rcData[YAW] < MINCHECK ) && armed == 1) {
if (rcDelayCommand == 20) armed = 0; // rcDelayCommand = 20 => 20x20ms = 0.4s = time to wait for a specific RC command to be acknowledged
} else if ( (rcData[YAW] > MAXCHECK || rcData[ROLL] > MAXCHECK) && rcData[PITCH] < MAXCHECK && armed == 0 && calibratingG == 0 && calibratedACC == 1) {
} else if ( (rcData[YAW] > MAXCHECK ) && rcData[PITCH] < MAXCHECK && armed == 0 && calibratingG == 0 && calibratedACC == 1) {
if (rcDelayCommand == 20) {
armed = 1;
headFreeModeHold = heading;
armed = 1;
headFreeModeHold = heading;
}
#ifdef LCD_TELEMETRY_AUTO
#endif
#ifdef ALLOW_ARM_DISARM_VIA_TX_ROLL
} else if ( (rcData[ROLL] < MINCHECK) && armed == 1) {
if (rcDelayCommand == 20) armed = 0; // rcDelayCommand = 20 => 20x20ms = 0.4s = time to wait for a specific RC command to be acknowledged
} else if ( (rcData[ROLL] > MAXCHECK) && rcData[PITCH] < MAXCHECK && armed == 0 && calibratingG == 0 && calibratedACC == 1) {
if (rcDelayCommand == 20) {
armed = 1;
headFreeModeHold = heading;
}
#endif
#ifdef LCD_TELEMETRY_AUTO
} else if (rcData[ROLL] < MINCHECK && rcData[PITCH] > MAXCHECK && armed == 0) {
if (rcDelayCommand == 20) {
if (telemetry_auto) {
Expand Down Expand Up @@ -644,7 +654,11 @@ void loop () {
}
#endif
if (rcOptions[BOXPASSTHRU]) {passThruMode = 1;}
else passThruMode = 0;
else {passThruMode = 0;}

#ifdef FIXEDWING
headFreeMode = 0;
#endif
} else { // not in rc loop
static uint8_t taskOrder=0; // never call all functions in the same loop, to avoid high delay spikes
switch (taskOrder++ % 5) {
Expand Down Expand Up @@ -767,4 +781,4 @@ void loop () {
mixTable();
writeServos();
writeMotors();
}
}

0 comments on commit db7cb88

Please sign in to comment.