Skip to content

Commit

Permalink
update serial protocol with payload length
Browse files Browse the repository at this point in the history
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
dubusal@gmail.com committed Apr 12, 2012
1 parent 7760b24 commit 2e904a1
Show file tree
Hide file tree
Showing 9 changed files with 210 additions and 248 deletions.
3 changes: 2 additions & 1 deletion Buzzer.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions EEPROM.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand All @@ -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;
Expand All @@ -90,6 +90,6 @@ void checkFirstTime() {
#ifdef TRI
tri_yaw_middle = TRI_YAW_MIDDLE;
#endif
writeParams();
writeParams(0);
}

24 changes: 12 additions & 12 deletions GPS.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand Down Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions IMU.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions LCD.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions MultiWii.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -651,7 +651,7 @@ void loop () {
break;
}
}

computeIMU();
// Measure loop rate just afer reading the sensors
currentTime = micros();
Expand Down
6 changes: 3 additions & 3 deletions Sensors.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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--;
}
Expand Down Expand Up @@ -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] ;
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
Loading

0 comments on commit 2e904a1

Please sign in to comment.