Permalink
Browse files

update serial protocol with payload length

serial protocol is highly described with code comments
altitude is transmitted in 32 bits
no more rcrate x2 factor

git-svn-id: http://multiwii.googlecode.com/svn/trunk/MultiWii@675 02679b44-d973-9852-f2fa-63770883b36c
  • Loading branch information...
1 parent 7760b24 commit 2e904a1f2f68d754afb9667d0419028f16a4763a dubusal@gmail.com committed Apr 12, 2012
Showing with 210 additions and 248 deletions.
  1. +2 −1 Buzzer.pde
  2. +5 −5 EEPROM.pde
  3. +12 −12 GPS.pde
  4. +0 −7 IMU.pde
  5. +2 −3 LCD.pde
  6. +7 −7 MultiWii.ino
  7. +3 −3 Sensors.pde
  8. +179 −206 Serial.pde
  9. +0 −4 config.h
View
@@ -32,12 +32,13 @@ void buzzer(uint8_t warn_vbat){
if ( failsafeCnt == 0) warn_failsafe = 0; // turn off alarm if TX is okay
#endif
//===================== GPS fix notification handling =====================
+ #if GPS
if ((GPSModeHome || GPSModeHold) && !GPS_fix){ //if no fix and gps funtion is activated: do warning beeps.
warn_noGPSfix = 1;
}else{
warn_noGPSfix = 0;
}
-
+ #endif
//===================== Main Handling Block =====================
repeat = 1; // set repeat to default
ontime = 100; // set offtime to default
View
@@ -45,7 +45,7 @@ void readEEPROM() {
#if defined(POWERMETER)
pAlarm = (uint32_t) powerTrigger1 * (uint32_t) PLEVELSCALE * (uint32_t) PLEVELDIV; // need to cast before multiplying
#endif
- for(i=0;i<7;i++) lookupRX[i] = (2500+rcExpo8*(i*i-25))*i*(int32_t)rcRate8/1250;
+ for(i=0;i<7;i++) lookupRX[i] = (2500+rcExpo8*(i*i-25))*i*(int32_t)rcRate8/2500;
#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
@@ -55,13 +55,13 @@ void readEEPROM() {
#endif
}
-void writeParams() {
+void writeParams(uint8_t b) {
uint8_t i, _address = 0;
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;
}
readEEPROM();
- blinkLED(15,20,1);
+ if (b == 1) blinkLED(15,20,1);
}
void checkFirstTime() {
@@ -75,7 +75,7 @@ void checkFirstTime() {
P8[PIDVEL] = 0; I8[PIDVEL] = 0; D8[PIDVEL] = 0;
P8[PIDLEVEL] = 90; I8[PIDLEVEL] = 45; D8[PIDLEVEL] = 100;
P8[PIDMAG] = 40;
- rcRate8 = 45; // = 0.9 in GUI
+ rcRate8 = 90;
rcExpo8 = 65;
rollPitchRate = 0;
yawRate = 0;
@@ -90,6 +90,6 @@ void checkFirstTime() {
#ifdef TRI
tri_yaw_middle = TRI_YAW_MIDDLE;
#endif
- writeParams();
+ writeParams(0);
}
View
24 GPS.pde
@@ -67,20 +67,9 @@ void GPS_NewData() {
GPS_distanceToHome = 0;
GPS_directionToHome = 0;
GPS_numSat = 0;
- }
+ }
#endif
-void GPS_reset_home_position() {
- #if defined(I2C_GPS)
- //set current position as home
- 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
- #else
- GPS_latitude_home = GPS_latitude;
- GPS_longitude_home = GPS_longitude;
- #endif
-}
-
#if defined(GPS_SERIAL)
while (SerialAvailable(GPS_SERIAL)) {
if (GPS_newFrame(SerialRead(GPS_SERIAL))) {
@@ -118,6 +107,17 @@ void GPS_reset_home_position() {
#endif
}
+void GPS_reset_home_position() {
+ #if defined(I2C_GPS)
+ //set current position as home
+ 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
+ #else
+ GPS_latitude_home = GPS_latitude;
+ GPS_longitude_home = GPS_longitude;
+ #endif
+}
+
/* this is an equirectangular approximation to calculate distance and bearing between 2 GPS points (lat/long)
it's much more faster than an exact calculation
the error is neglectible for few kilometers assuming a constant R for earth
View
@@ -230,13 +230,6 @@ void getEstimatedAttitude(){
if ( ( 36 < accMag && accMag < 196 ) || smallAngle25 )
for (axis = 0; axis < 3; axis++) {
int16_t acc = ACC_VALUE;
- #if !defined(TRUSTED_ACCZ)
- if (smallAngle25 && axis == YAW)
- //We consider ACCZ = acc_1G when the acc on other axis is small.
- //It's a tweak to deal with some configs where ACC_Z tends to a value < acc_1G when high throttle is applied.
- //This tweak applies only when the multi is not in inverted position
- acc = acc_1G;
- #endif
EstG.A[axis] = (EstG.A[axis] * GYR_CMPF_FACTOR + acc) * INV_GYR_CMPF_FACTOR;
}
#if MAG
View
@@ -735,7 +735,6 @@ static lcd_type_desc_t LAUX = {&__uAuxFmt, &__u16Inc}; //to review (activate is
static lcd_param_def_t __P = {&LTU8, 1, 1, 1};
static lcd_param_def_t __I = {&LTU8, 3, 1, 2};
static lcd_param_def_t __D = {&LTU8, 0, 1, 1};
-static lcd_param_def_t __RCR = {&LTU8, 2, 2, 2};
static lcd_param_def_t __RC = {&LTU8, 2, 1, 2};
static lcd_param_def_t __PM = {&LPMM, 1, 1, 0};
static lcd_param_def_t __PS = {&LPMS, 1, 1, 0};
@@ -849,7 +848,7 @@ PROGMEM const prog_void *lcd_param_ptr_table [] = {
#if MAG
&lcd_param_text19, &P8[PIDMAG], &__P,
#endif
- &lcd_param_text20, &rcRate8, &__RCR,
+ &lcd_param_text20, &rcRate8, &__RC,
&lcd_param_text21, &rcExpo8, &__RC,
&lcd_param_text22, &rollPitchRate, &__RC,
&lcd_param_text23, &yawRate, &__RC,
@@ -1084,7 +1083,7 @@ void configurationLoop() {
strcpy_P(line1,PSTR("Aborting"));
LCDprintChar(line1);
}
- if (LCD == 0) writeParams();
+ if (LCD == 0) writeParams(1);
LCDsetLine(2);
strcpy_P(line1,PSTR("Exit"));
LCDprintChar(line1);
View
@@ -473,7 +473,7 @@ void loop () {
previousTime = micros();
}
}
- #if defined(InflightAccCalibration)
+ #if defined(INFLIGHT_ACC_CALIBRATION)
else if (armed == 0 && rcData[YAW] < MINCHECK && rcData[PITCH] > MAXCHECK && rcData[ROLL] > MAXCHECK){
if (rcDelayCommand == 20){
if (AccInflightCalibrationMeasurementDone){ // trigger saving into eeprom after landing
@@ -523,22 +523,22 @@ void loop () {
if (rcDelayCommand == 20) calibratingM=1; // MAG calibration request
rcDelayCommand++;
} else if (rcData[PITCH] > MAXCHECK) {
- accTrim[PITCH]+=2;writeParams();
+ accTrim[PITCH]+=2;writeParams(1);
#if defined(LED_RING)
blinkLedRing();
#endif
} else if (rcData[PITCH] < MINCHECK) {
- accTrim[PITCH]-=2;writeParams();
+ accTrim[PITCH]-=2;writeParams(1);
#if defined(LED_RING)
blinkLedRing();
#endif
} else if (rcData[ROLL] > MAXCHECK) {
- accTrim[ROLL]+=2;writeParams();
+ accTrim[ROLL]+=2;writeParams(1);
#if defined(LED_RING)
blinkLedRing();
#endif
} else if (rcData[ROLL] < MINCHECK) {
- accTrim[ROLL]-=2;writeParams();
+ accTrim[ROLL]-=2;writeParams(1);
#if defined(LED_RING)
blinkLedRing();
#endif
@@ -622,7 +622,7 @@ void loop () {
if (rcOptions[BOXPASSTHRU]) {passThruMode = 1;}
else passThruMode = 0;
} else { // not in rc loop
- static int8_t taskOrder=0; // never call all functions in the same loop, to avoid high delay spikes
+ static uint8_t taskOrder=0; // never call all functions in the same loop, to avoid high delay spikes
switch (taskOrder++ % 5) {
case 0:
#if MAG
@@ -651,7 +651,7 @@ void loop () {
break;
}
}
-
+
computeIMU();
// Measure loop rate just afer reading the sensors
currentTime = micros();
View
@@ -269,7 +269,7 @@ void ACC_Common() {
accZero[YAW] = a[YAW]/400-acc_1G; // for nunchuk 200=1G
accTrim[ROLL] = 0;
accTrim[PITCH] = 0;
- writeParams(); // write accZero in EEPROM
+ writeParams(1); // write accZero in EEPROM
}
calibratingA--;
}
@@ -317,7 +317,7 @@ void ACC_Common() {
accZero[YAW] = b[YAW]/50-acc_1G; // for nunchuk 200=1G
accTrim[ROLL] = 0;
accTrim[PITCH] = 0;
- writeParams(); // write accZero in EEPROM
+ writeParams(1); // write accZero in EEPROM
}
#endif
accADC[ROLL] -= accZero[ROLL] ;
@@ -946,7 +946,7 @@ void Mag_getADC() {
tCal = 0;
for(axis=0;axis<3;axis++)
magZero[axis] = (magZeroTempMin[axis] + magZeroTempMax[axis])/2;
- writeParams();
+ writeParams(1);
}
}
}
Oops, something went wrong.

0 comments on commit 2e904a1

Please sign in to comment.