Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 2040 → Rev 2041

/branches/dongfang_FC_rewrite/attitude.c
109,7 → 109,7
// Yaw angle and compass stuff.
 
// This is updated/written from MM3. Negative angle indicates invalid data.
int16_t compassHeading = -1;
int16_t magneticHeading = -1;
 
// This is NOT updated from MM3. Negative angle indicates invalid data.
int16_t compassCourse = -1;
187,10 → 187,10
yawAngleDiff = 0;
 
// update compass course to current heading
compassCourse = compassHeading;
compassCourse = magneticHeading;
 
// Inititialize YawGyroIntegral value with current compass heading
yawGyroHeading = (int32_t) compassHeading * GYRO_DEG_FACTOR_YAW;
yawGyroHeading = (int32_t) magneticHeading * GYRO_DEG_FACTOR_YAW;
 
// Servo_On(); //enable servo output
}
435,13 → 435,13
w = v;
correction = w / 8 + 1;
// calculate the deviation of the yaw gyro heading and the compass heading
if (compassHeading < 0)
if (magneticHeading < 0)
error = 0; // disable yaw drift compensation if compass heading is undefined
else if (abs(yawRate) > 128) { // spinning fast
error = 0;
} else {
// compassHeading - yawGyroHeading, on a -180..179 deg interval.
error = ((540 + compassHeading - (yawGyroHeading / GYRO_DEG_FACTOR_YAW))
error = ((540 + magneticHeading - (yawGyroHeading / GYRO_DEG_FACTOR_YAW))
% 360) - 180;
}
if (!ignoreCompassTimer && w < 25) {
449,8 → 449,8
// Basically this gets set if we are in "fix" mode, and when starting.
if (updateCompassCourse) {
beep(200);
yawGyroHeading = (int32_t) compassHeading * GYRO_DEG_FACTOR_YAW;
compassCourse = compassHeading; //(int16_t)(yawGyroHeading / GYRO_DEG_FACTOR_YAW);
yawGyroHeading = (int32_t) magneticHeading * GYRO_DEG_FACTOR_YAW;
compassCourse = magneticHeading; //(int16_t)(yawGyroHeading / GYRO_DEG_FACTOR_YAW);
updateCompassCourse = 0;
}
}
/branches/dongfang_FC_rewrite/attitude.h
95,7 → 95,7
/*
* Compass navigation
*/
extern int16_t compassHeading;
extern int16_t magneticHeading;
extern int16_t compassCourse;
// extern int16_t compassOffCourse;
extern uint8_t compassCalState;
/branches/dongfang_FC_rewrite/menu.c
155,7 → 155,7
LCD_printfxy(0,0,"Attitude");
LCD_printfxy(0,1,"Nick: %5i", angle[PITCH] / GYRO_DEG_FACTOR_PITCHROLL);
LCD_printfxy(0,2,"Roll: %5i", angle[ROLL ] / GYRO_DEG_FACTOR_PITCHROLL);
LCD_printfxy(0,3,"Heading: %5i", compassHeading);
LCD_printfxy(0,3,"Heading(M):%5i", magneticHeading);
break;
case 3:// Remote Control Channel Menu Item
LCD_printfxy(0,0,"C1:%4i C2:%4i ",PPM_in[1],PPM_in[2]);
208,8 → 208,8
case 8:// Compass Menu Item
LCD_printfxy(0,0,"Compass ");
LCD_printfxy(0,1,"Course: %5i", compassCourse);
LCD_printfxy(0,2,"Heading: %5i", compassHeading);
LCD_printfxy(0,3,"OffCourse: %5i", ((540 + compassHeading - compassCourse) % 360) - 180);
LCD_printfxy(0,2,"Heading: %5i", magneticHeading);
LCD_printfxy(0,3,"OffCourse: %5i", ((540 + magneticHeading - compassCourse) % 360) - 180);
break;
case 9:// Poti Menu Item
LCD_printfxy(0,0,"Po1: %3i Po5: %3i" ,variables[0], variables[4]); //PPM24-Extesion
/branches/dongfang_FC_rewrite/mk3mag.c
80,7 → 80,7
void MK3MAG_periodicTask(void) {// called every 102.4 us by timer 0 ISR
static uint16_t PWMCount = 0;
static uint16_t beepDelay = 0;
static uint16_t debugCounter = 0;
// static uint16_t debugCounter = 0;
// The pulse width varies from 1ms (0°) to 36.99ms (359.9°)
// in other words 100us/° with a +1ms offset.
// The signal goes low for 65ms between pulses,
87,10 → 87,10
// so the cycle time is 65mS + the pulse width.
// pwm is high
 
if (debugCounter++ == 5000) {
// DebugOut.Digital[0] ^= DEBUG_MK3MAG;
debugCounter = 0;
}
// if (debugCounter++ == 5000) {
// DebugOut.Digital[0] ^= DEBUG_MK3MAG;
// debugCounter = 0;
// }
 
if (PINC & (1 << PINC4)) {
// If PWM signal is high increment PWM high counter
101,7 → 101,7
if (PWMCount > 400) {
if (PWMTimeout)
PWMTimeout--; // decrement timeout
compassHeading = -1; // unknown heading
magneticHeading = -1; // unknown heading
PWMCount = 0; // reset PWM Counter
}
} else { // pwm is low
108,9 → 108,9
// ignore pwm values values of 0 and higher than 37 ms;
if ((PWMCount) && (PWMCount < 362)) { // 362 * 102.4us = 37.0688 ms
if (PWMCount < 10)
compassHeading = 0;
magneticHeading = 0;
else {
compassHeading = ((uint32_t) (PWMCount - 10) * 1049L) / 1024; // correct timebase and offset
magneticHeading = ((uint32_t) (PWMCount - 10) * 1049L) / 1024; // correct timebase and offset
//DebugOut.Digital[1] ^= DEBUG_MK3MAG; // correct signal recd.
}
/*
126,10 → 126,11
}
PWMCount = 0; // reset pwm counter
}
 
if (!PWMTimeout) {
if (checkDelay(beepDelay)) {
if (!beepTime)
beepTime = 100; // make noise with 10Hz to signal the compass problem
beep(100); // make noise with 10Hz to signal the compass problem
beepDelay = setDelay(100);
}
}
/branches/dongfang_FC_rewrite/uart0.c
448,7 → 448,8
switch (rxd_buffer[2]) {
#ifdef USE_DIRECT_GPS
case 'K':// compass value
compassHeading = ((Heading_t *)pRxData)->heading;
// What is the point of this - the compass will overwrite this soon?
magneticHeading = ((Heading_t *)pRxData)->heading;
// compassOffCourse = ((540 + compassHeading - compassCourse) % 360) - 180;
break;
#endif