Rev 474 | Rev 480 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 474 | Rev 475 | ||
---|---|---|---|
Line 336... | Line 336... | ||
336 | 336 | ||
337 | void NCMAG_Calibrate(void) |
337 | void NCMAG_Calibrate(void) |
338 | { |
338 | { |
339 | u8 msg[64]; |
339 | u8 msg[64]; |
340 | static u8 speak = 0; |
340 | static u8 speak = 0; |
341 | static s16 Xmin = 0, Xmax = 0, Ymin = 0, Ymax = 0, Zmin = 0, Zmax = 0; |
341 | static s16 Xmin = 0, Xmax = 0, Ymin = 0, Ymax = 0, Zmin = 0, Zmax = 0, Zmin2 = 0, Zmax2 = 0; |
342 | static s16 X = 0, Y = 0, Z = 0; |
342 | static s16 X = 0, Y = 0, Z = 0; |
343 | static u8 OldCalState = 0; |
343 | static u8 OldCalState = 0; |
Line 344... | Line 344... | ||
344 | s16 MinCalibration = 450; |
344 | s16 MinCalibration = 450; |
Line 358... | Line 358... | ||
358 | Ymin = 10000; |
358 | Ymin = 10000; |
359 | Ymax = -10000; |
359 | Ymax = -10000; |
360 | Zmin = 10000; |
360 | Zmin = 10000; |
361 | Zmax = -10000; |
361 | Zmax = -10000; |
362 | speak = 1; |
362 | speak = 1; |
- | 363 | if(Compass_CalState != OldCalState) // avoid continously writing of eeprom! |
|
- | 364 | { |
|
- | 365 | UART1_PutString("\r\nStarting compass calibration"); |
|
- | 366 | if(I2C_CompassPort == I2C_EXTERN_0) |
|
- | 367 | { |
|
- | 368 | if(!ExtCompassOrientation) ExtCompassOrientation = GetExtCompassOrientation(); |
|
- | 369 | UART1_PutString(" - External sensor "); |
|
- | 370 | sprintf(msg, "with orientation: %d ",ExtCompassOrientation); |
|
- | 371 | UART1_PutString(msg); |
|
- | 372 | } |
|
- | 373 | else UART1_PutString(" - Internal sensor"); |
|
- | 374 | } |
|
363 | break; |
375 | break; |
364 | - | ||
365 | case 2: // 2nd step of calibration |
376 | case 2: // 2nd step of calibration |
366 | // find Min and Max of the X- and Y-Sensors during rotation in the horizontal plane |
377 | // find Min and Max of the X- and Y-Sensors during rotation in the horizontal plane |
367 | if(X < Xmin) { Xmin = X; BeepTime = 20;} |
378 | if(X < Xmin) { Xmin = X; BeepTime = 20;} |
368 | else if(X > Xmax) { Xmax = X; BeepTime = 20;} |
379 | else if(X > Xmax) { Xmax = X; BeepTime = 20;} |
369 | if(Y < Ymin) { Ymin = Y; BeepTime = 60;} |
380 | if(Y < Ymin) { Ymin = Y; BeepTime = 60;} |
370 | else if(Y > Ymax) { Ymax = Y; BeepTime = 60;} |
381 | else if(Y > Ymax) { Ymax = Y; BeepTime = 60;} |
- | 382 | if(Z < Zmin) { Zmin = Z; } // silent |
|
- | 383 | else if(Z > Zmax) { Zmax = Z; } |
|
- | 384 | ||
371 | if(speak) SpeakHoTT = SPEAK_CALIBRATE; speak = 0; |
385 | if(speak) SpeakHoTT = SPEAK_CALIBRATE; speak = 0; |
372 | break; |
386 | break; |
Line 373... | Line 387... | ||
373 | 387 | ||
374 | case 3: // 3rd step of calibration |
388 | case 3: // 3rd step of calibration |
375 | // used to change the orientation of the MK3MAG vertical to the horizontal plane |
389 | // used to change the orientation of the MK3MAG vertical to the horizontal plane |
376 | speak = 1; |
390 | speak = 1; |
Line 377... | Line 391... | ||
377 | break; |
391 | break; |
378 | 392 | ||
379 | case 4: |
393 | case 4: |
380 | // find Min and Max of the Z-Sensor |
394 | // find Min and Max of the Z-Sensor |
- | 395 | if(Z < Zmin2) { Zmin2 = Z; BeepTime = 80;} |
|
- | 396 | else if(Z > Zmax2) { Zmax2 = Z; BeepTime = 80;} |
|
- | 397 | ||
- | 398 | if(X < Xmin) { Xmin = X; BeepTime = 20;} |
|
- | 399 | else if(X > Xmax) { Xmax = X; BeepTime = 20;} |
|
- | 400 | if(Y < Ymin) { Ymin = Y; BeepTime = 60;} |
|
381 | if(Z < Zmin) { Zmin = Z; BeepTime = 80;} |
401 | else if(Y > Ymax) { Ymax = Y; BeepTime = 60;} |
382 | else if(Z > Zmax) { Zmax = Z; BeepTime = 80;} |
402 | |
Line 383... | Line 403... | ||
383 | if(speak) SpeakHoTT = SPEAK_CALIBRATE; speak = 0; |
403 | if(speak) SpeakHoTT = SPEAK_CALIBRATE; speak = 0; |
384 | break; |
404 | break; |
385 | 405 | ||
386 | case 5: |
406 | case 5: |
387 | // Save values |
407 | // Save values |
388 | if(Compass_CalState != OldCalState) // avoid continously writing of eeprom! |
408 | if(Compass_CalState != OldCalState) // avoid continously writing of eeprom! |
389 | { |
409 | { |
390 | switch(NCMAG_SensorType) |
410 | switch(NCMAG_SensorType) |
391 | { |
411 | { |
392 | case TYPE_HMC5843: |
412 | case TYPE_HMC5843: |
Line 393... | Line 413... | ||
393 | UART1_PutString("\r\nHMC5843 calibration\n\r"); |
413 | UART1_PutString("\r\nFinished: HMC5843 calibration\n\r"); |
394 | MinCalibration = HMC5843_CALIBRATION_RANGE; |
414 | MinCalibration = HMC5843_CALIBRATION_RANGE; |
395 | break; |
415 | break; |
396 | 416 | ||
397 | case TYPE_LSM303DLH: |
417 | case TYPE_LSM303DLH: |
398 | case TYPE_LSM303DLM: |
418 | case TYPE_LSM303DLM: |
399 | UART1_PutString("\r\n\r\nLSM303 calibration\n\r"); |
419 | UART1_PutString("\r\nFinished: LSM303 calibration\n\r"); |
400 | MinCalibration = LSM303_CALIBRATION_RANGE; |
420 | MinCalibration = LSM303_CALIBRATION_RANGE; |
Line 406... | Line 426... | ||
406 | sprintf(msg, "Earth field on your location should be: %iuT\r\n",EarthMagneticStrengthTheoretic); |
426 | sprintf(msg, "Earth field on your location should be: %iuT\r\n",EarthMagneticStrengthTheoretic); |
407 | UART1_PutString(msg); |
427 | UART1_PutString(msg); |
408 | } |
428 | } |
409 | else UART1_PutString("without GPS\n\r"); |
429 | else UART1_PutString("without GPS\n\r"); |
Line -... | Line 430... | ||
- | 430 | ||
- | 431 | if(Zmin2 < Zmin) { Zmin = Zmin2; } |
|
- | 432 | else if(Zmax2 > Zmax) { Zmax = Zmax2; } |
|
410 | 433 | ||
411 | Calibration.MagX.Range = Xmax - Xmin; |
434 | Calibration.MagX.Range = Xmax - Xmin; |
412 | Calibration.MagX.Offset = (Xmin + Xmax) / 2; |
435 | Calibration.MagX.Offset = (Xmin + Xmax) / 2; |
413 | Calibration.MagY.Range = Ymax - Ymin; |
436 | Calibration.MagY.Range = Ymax - Ymin; |
414 | Calibration.MagY.Offset = (Ymin + Ymax) / 2; |
437 | Calibration.MagY.Offset = (Ymin + Ymax) / 2; |
Line 554... | Line 577... | ||
554 | } |
577 | } |
Line 555... | Line 578... | ||
555 | 578 | ||
556 | u8 GetExtCompassOrientation(void) |
579 | u8 GetExtCompassOrientation(void) |
557 | { |
580 | { |
558 | if(I2C_CompassPort != I2C_EXTERN_0) return(0); |
- | |
559 | if(abs(FromFlightCtrl.AngleNick) > 300) return(0); // MK tilted |
- | |
Line -... | Line 581... | ||
- | 581 | if(I2C_CompassPort != I2C_EXTERN_0) return(0); |
|
- | 582 | ||
- | 583 | if((abs(FromFlightCtrl.AngleNick) > 300) || (abs(FromFlightCtrl.AngleRoll) > 300)) |
|
- | 584 | { |
|
- | 585 | // UART1_PutString("\r\nTilted"); |
|
560 | if(abs(FromFlightCtrl.AngleRoll) > 300) return(0); |
586 | return(0); |
561 | 587 | } |
|
562 | if(AccRawVector.Z > 3300) return(1); // Flach - Bestückung oben - Pfeil nach vorn |
588 | if(AccRawVector.Z > 3300) return(1); // Flach - Bestückung oben - Pfeil nach vorn |
563 | else |
589 | else |
564 | if(AccRawVector.Z < -3300) return(2); // Flach - Bestückung unten - Pfeil nach vorn |
590 | if(AccRawVector.Z < -3300) return(2); // Flach - Bestückung unten - Pfeil nach vorn |
Line 1020... | Line 1046... | ||
1020 | 1046 | ||
1021 | for(repeat = 0; repeat < 100; repeat++) |
1047 | for(repeat = 0; repeat < 100; repeat++) |
1022 | { |
1048 | { |
1023 | NCMAG_GetAccVector(10); // only the sensor with ACC is supported |
1049 | NCMAG_GetAccVector(10); // only the sensor with ACC is supported |
1024 | ExtCompassOrientation = GetExtCompassOrientation(); |
1050 | ExtCompassOrientation = GetExtCompassOrientation(); |
- | 1051 | if(ExtCompassOrientation && (ExtCompassOrientation == Calibration.Version / 16)) break; |
|
1025 | if(ExtCompassOrientation) break; |
1052 | //UART1_Putchar('-'); |
1026 | } |
1053 | } |
Line 1027... | Line 1054... | ||
1027 | //DebugOut.Analog[19] = repeat; |
1054 | //DebugOut.Analog[19] = repeat; |
1028 | 1055 | ||
Line 1032... | Line 1059... | ||
1032 | NCMag_CalibrationRead(I2C_CompassPort); |
1059 | NCMag_CalibrationRead(I2C_CompassPort); |
1033 | sprintf(msg, "with orientation: %d ",ExtCompassOrientation ); |
1060 | sprintf(msg, "with orientation: %d ",ExtCompassOrientation ); |
1034 | UART1_PutString(msg); |
1061 | UART1_PutString(msg); |
1035 | if(ExtCompassOrientation != Calibration.Version / 16) |
1062 | if(ExtCompassOrientation != Calibration.Version / 16) |
1036 | { |
1063 | { |
1037 | sprintf(msg, "\n\r! Warining: calibrated orientation was %d !",Calibration.Version / 16); |
1064 | sprintf(msg, "\n\r! Warning: calibrated orientation was %d !",Calibration.Version / 16); |
1038 | UART1_PutString(msg); |
1065 | UART1_PutString(msg); |
1039 | } |
1066 | } |
1040 | else UART1_PutString("ok"); |
1067 | else UART1_PutString("ok"); |
1041 | } |
1068 | } |