Rev 790 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 790 | Rev 791 | ||
---|---|---|---|
Line 120... | Line 120... | ||
120 | // setpoints for motors |
120 | // setpoints for motors |
121 | volatile uint8_t Motor_Front, Motor_Rear, Motor_Right, Motor_Left; |
121 | volatile uint8_t Motor_Front, Motor_Rear, Motor_Right, Motor_Left; |
Line 122... | Line 122... | ||
122 | 122 | ||
123 | // stick values derived by rc channels readings |
123 | // stick values derived by rc channels readings |
124 | int16_t StickPitch = 0, StickRoll = 0, StickYaw = 0, StickThrust = 0; |
124 | int16_t StickPitch = 0, StickRoll = 0, StickYaw = 0, StickThrust = 0; |
125 | int16_t MaxStickPitch = 0, MaxStickRoll = 0, MaxStickYaw = 0; |
125 | int16_t MaxStickPitch = 0, MaxStickRoll = 0; |
126 | // stick values derived by uart inputs |
126 | // stick values derived by uart inputs |
Line 326... | Line 326... | ||
326 | if(Reading_GyroPitch > 200) Reading_GyroPitch += 4 * (Reading_GyroPitch - 200); |
326 | if(Reading_GyroPitch > 200) Reading_GyroPitch += 4 * (Reading_GyroPitch - 200); |
327 | else if(Reading_GyroPitch < -200) Reading_GyroPitch += 4 * (Reading_GyroPitch + 200); |
327 | else if(Reading_GyroPitch < -200) Reading_GyroPitch += 4 * (Reading_GyroPitch + 200); |
328 | if(Reading_GyroRoll > 200) Reading_GyroRoll += 4 * (Reading_GyroRoll - 200); |
328 | if(Reading_GyroRoll > 200) Reading_GyroRoll += 4 * (Reading_GyroRoll - 200); |
329 | else if(Reading_GyroRoll < -200) Reading_GyroRoll += 4 * (Reading_GyroRoll + 200); |
329 | else if(Reading_GyroRoll < -200) Reading_GyroRoll += 4 * (Reading_GyroRoll + 200); |
330 | } |
330 | } |
331 | //update poti values by rc-signals |
- | |
332 | if(Poti1 < PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110 && Poti1) Poti1--; |
- | |
333 | if(Poti2 < PPM_in[ParamSet.ChannelAssignment[CH_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[ParamSet.ChannelAssignment[CH_POTI2]] + 110 && Poti2) Poti2--; |
- | |
334 | if(Poti3 < PPM_in[ParamSet.ChannelAssignment[CH_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[ParamSet.ChannelAssignment[CH_POTI3]] + 110 && Poti3) Poti3--; |
- | |
335 | if(Poti4 < PPM_in[ParamSet.ChannelAssignment[CH_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[ParamSet.ChannelAssignment[CH_POTI4]] + 110 && Poti4) Poti4--; |
- | |
336 | //limit poti values |
- | |
337 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
- | |
338 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
- | |
339 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
- | |
340 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
- | |
341 | } |
331 | } |
Line 342... | Line 332... | ||
342 | 332 | ||
343 | /************************************************************************/ |
333 | /************************************************************************/ |
344 | /* Averaging Measurement Readings for Calibration */ |
334 | /* Averaging Measurement Readings for Calibration */ |
Line 356... | Line 346... | ||
356 | Mean_AccRoll = ACC_AMPLIFY * (int32_t)AdValueAccRoll; |
346 | Mean_AccRoll = ACC_AMPLIFY * (int32_t)AdValueAccRoll; |
357 | Mean_AccTop = (int32_t)AdValueAccTop; |
347 | Mean_AccTop = (int32_t)AdValueAccTop; |
358 | // start ADC (enables internal trigger so that the ISR in analog.c |
348 | // start ADC (enables internal trigger so that the ISR in analog.c |
359 | // updates the readings once) |
349 | // updates the readings once) |
360 | ADC_Enable(); |
350 | ADC_Enable(); |
361 | //update poti values by rc-signals |
- | |
362 | if(Poti1 < PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110 && Poti1) Poti1--; |
- | |
363 | if(Poti2 < PPM_in[ParamSet.ChannelAssignment[CH_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[ParamSet.ChannelAssignment[CH_POTI2]] + 110 && Poti2) Poti2--; |
- | |
364 | if(Poti3 < PPM_in[ParamSet.ChannelAssignment[CH_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[ParamSet.ChannelAssignment[CH_POTI3]] + 110 && Poti3) Poti3--; |
- | |
365 | if(Poti4 < PPM_in[ParamSet.ChannelAssignment[CH_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[ParamSet.ChannelAssignment[CH_POTI4]] + 110 && Poti4) Poti4--; |
- | |
366 | - | ||
367 | //PPM24-Extension |
- | |
368 | if(Poti5 < PPM_in[9] + 110) Poti5++; else if(Poti5 > PPM_in[9] + 110 && Poti5) Poti5--; |
- | |
369 | if(Poti6 < PPM_in[10] + 110) Poti6++; else if(Poti6 > PPM_in[10] + 110 && Poti6) Poti6--; |
- | |
370 | if(Poti7 < PPM_in[11] + 110) Poti7++; else if(Poti7 > PPM_in[11] + 110 && Poti7) Poti7--; |
- | |
371 | if(Poti8 < PPM_in[12] + 110) Poti8++; else if(Poti8 > PPM_in[12] + 110 && Poti8) Poti8--; |
- | |
372 | - | ||
373 | //limit poti values |
- | |
374 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
- | |
375 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
- | |
376 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
- | |
377 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
- | |
378 | //PPM24-Extension |
- | |
379 | if(Poti5 < 0) Poti5 = 0; else if(Poti5 > 255) Poti5 = 255; |
- | |
380 | if(Poti6 < 0) Poti6 = 0; else if(Poti6 > 255) Poti6 = 255; |
- | |
381 | if(Poti7 < 0) Poti7 = 0; else if(Poti7 > 255) Poti7 = 255; |
- | |
382 | if(Poti8 < 0) Poti8 = 0; else if(Poti8 > 255) Poti8 = 255; |
- | |
Line 383... | Line 351... | ||
383 | 351 | ||
384 | TurnOver180Pitch = (int32_t) ParamSet.AngleTurnOverPitch * 2500L; |
352 | TurnOver180Pitch = (int32_t) ParamSet.AngleTurnOverPitch * 2500L; |
385 | TurnOver180Roll = (int32_t) ParamSet.AngleTurnOverRoll * 2500L; |
353 | TurnOver180Roll = (int32_t) ParamSet.AngleTurnOverRoll * 2500L; |
Line 421... | Line 389... | ||
421 | void ParameterMapping(void) |
389 | void ParameterMapping(void) |
422 | { |
390 | { |
423 | if(SenderOkay > 140) // do the mapping of RC-Potis only if the rc-signal is ok |
391 | if(SenderOkay > 140) // do the mapping of RC-Potis only if the rc-signal is ok |
424 | // else the last updated values are used |
392 | // else the last updated values are used |
425 | { |
393 | { |
- | 394 | //update poti values by rc-signals |
|
426 | #define CHK_POTI(b,a,min,max) { if(a > 250) { if(a == 251) b = Poti1; else if(a == 252) b = Poti2; else if(a == 253) b = Poti3; else if(a == 254) b = Poti4;} else b = a; if(b <= min) b = min; else if(b >= max) b = max;} |
395 | #define CHK_POTI(b,a,min,max) { if(a > 250) { if(a == 251) b = Poti1; else if(a == 252) b = Poti2; else if(a == 253) b = Poti3; else if(a == 254) b = Poti4;} else b = a; if(b <= min) b = min; else if(b >= max) b = max;} |
427 | CHK_POTI(FCParam.MaxHeight,ParamSet.MaxHeight,0,255); |
396 | CHK_POTI(FCParam.MaxHeight,ParamSet.MaxHeight,0,255); |
428 | CHK_POTI(FCParam.Height_D,ParamSet.Height_D,0,100); |
397 | CHK_POTI(FCParam.Height_D,ParamSet.Height_D,0,100); |
429 | CHK_POTI(FCParam.Height_P,ParamSet.Height_P,0,100); |
398 | CHK_POTI(FCParam.Height_P,ParamSet.Height_P,0,100); |
430 | CHK_POTI(FCParam.Height_ACC_Effect,ParamSet.Height_ACC_Effect,0,255); |
399 | CHK_POTI(FCParam.Height_ACC_Effect,ParamSet.Height_ACC_Effect,0,255); |
Line 508... | Line 477... | ||
508 | ThrustMixFraction = ParamSet.EmergencyThrust; // set emergency thrust |
477 | ThrustMixFraction = ParamSet.EmergencyThrust; // set emergency thrust |
509 | EmergencyLanding = 1; // enable emergency landing |
478 | EmergencyLanding = 1; // enable emergency landing |
510 | // set neutral rc inputs |
479 | // set neutral rc inputs |
511 | PPM_diff[ParamSet.ChannelAssignment[CH_PITCH]] = 0; |
480 | PPM_diff[ParamSet.ChannelAssignment[CH_PITCH]] = 0; |
512 | PPM_diff[ParamSet.ChannelAssignment[CH_ROLL]] = 0; |
481 | PPM_diff[ParamSet.ChannelAssignment[CH_ROLL]] = 0; |
- | 482 | PPM_diff[ParamSet.ChannelAssignment[CH_YAW]] = 0; |
|
513 | PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] = 0; |
483 | PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] = 0; |
514 | PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] = 0; |
484 | PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] = 0; |
515 | PPM_in[ParamSet.ChannelAssignment[CH_YAW]] = 0; |
485 | PPM_in[ParamSet.ChannelAssignment[CH_YAW]] = 0; |
516 | } |
486 | } |
517 | else MotorsOn = 0; // switch of all motors |
487 | else MotorsOn = 0; // switch of all motors |
Line 534... | Line 504... | ||
534 | SumPitch = 0; |
504 | SumPitch = 0; |
535 | SumRoll = 0; |
505 | SumRoll = 0; |
536 | Reading_IntegralGyroYaw = 0; |
506 | Reading_IntegralGyroYaw = 0; |
537 | Reading_IntegralGyroYaw2 = 0; |
507 | Reading_IntegralGyroYaw2 = 0; |
538 | } |
508 | } |
- | 509 | ||
- | 510 | if(Poti1 < PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110 && Poti1) Poti1--; |
|
- | 511 | if(Poti2 < PPM_in[ParamSet.ChannelAssignment[CH_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[ParamSet.ChannelAssignment[CH_POTI2]] + 110 && Poti2) Poti2--; |
|
- | 512 | if(Poti3 < PPM_in[ParamSet.ChannelAssignment[CH_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[ParamSet.ChannelAssignment[CH_POTI3]] + 110 && Poti3) Poti3--; |
|
- | 513 | if(Poti4 < PPM_in[ParamSet.ChannelAssignment[CH_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[ParamSet.ChannelAssignment[CH_POTI4]] + 110 && Poti4) Poti4--; |
|
- | 514 | //PPM24-Extension |
|
- | 515 | if(Poti5 < PPM_in[9] + 110) Poti5++; else if(Poti5 > PPM_in[9] + 110 && Poti5) Poti5--; |
|
- | 516 | if(Poti6 < PPM_in[10] + 110) Poti6++; else if(Poti6 > PPM_in[10] + 110 && Poti6) Poti6--; |
|
- | 517 | if(Poti7 < PPM_in[11] + 110) Poti7++; else if(Poti7 > PPM_in[11] + 110 && Poti7) Poti7--; |
|
- | 518 | if(Poti8 < PPM_in[12] + 110) Poti8++; else if(Poti8 > PPM_in[12] + 110 && Poti8) Poti8--; |
|
- | 519 | //limit poti values |
|
- | 520 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
|
- | 521 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
|
- | 522 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
|
- | 523 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
|
- | 524 | //PPM24-Extension |
|
- | 525 | if(Poti5 < 0) Poti5 = 0; else if(Poti5 > 255) Poti5 = 255; |
|
- | 526 | if(Poti6 < 0) Poti6 = 0; else if(Poti6 > 255) Poti6 = 255; |
|
- | 527 | if(Poti7 < 0) Poti7 = 0; else if(Poti7 > 255) Poti7 = 255; |
|
- | 528 | if(Poti8 < 0) Poti8 = 0; else if(Poti8 > 255) Poti8 = 255; |
|
- | 529 | ||
539 | // if motors are off and the thrust stick is in the upper position |
530 | // if motors are off and the thrust stick is in the upper position |
540 | if((PPM_in[ParamSet.ChannelAssignment[CH_THRUST]] > 80) && MotorsOn == 0) |
531 | if((PPM_in[ParamSet.ChannelAssignment[CH_THRUST]] > 80) && MotorsOn == 0) |
541 | { |
532 | { |
542 | // and if the yaw stick is in the leftmost position |
533 | // and if the yaw stick is in the leftmost position |
543 | if(PPM_in[ParamSet.ChannelAssignment[CH_YAW]] > 75) |
534 | if(PPM_in[ParamSet.ChannelAssignment[CH_YAW]] > 75) |
Line 667... | Line 658... | ||
667 | 658 | ||
668 | // direct mapping of yaw and thrust |
659 | // direct mapping of yaw and thrust |
669 | StickYaw = -PPM_in[ParamSet.ChannelAssignment[CH_YAW]]; |
660 | StickYaw = -PPM_in[ParamSet.ChannelAssignment[CH_YAW]]; |
Line 670... | Line 661... | ||
670 | StickThrust = PPM_in[ParamSet.ChannelAssignment[CH_THRUST]] + 120;// shift to positive numbers |
661 | StickThrust = PPM_in[ParamSet.ChannelAssignment[CH_THRUST]] + 120;// shift to positive numbers |
671 | 662 | ||
672 | // update max stick positions for pitch, roll and yaw |
663 | // update max stick positions for pitch and roll |
673 | if(abs(PPM_in[ParamSet.ChannelAssignment[CH_PITCH]]) > MaxStickPitch) |
664 | if(abs(PPM_in[ParamSet.ChannelAssignment[CH_PITCH]]) > MaxStickPitch) |
674 | MaxStickPitch = abs(PPM_in[ParamSet.ChannelAssignment[CH_PITCH]]); |
665 | MaxStickPitch = abs(PPM_in[ParamSet.ChannelAssignment[CH_PITCH]]); |
675 | else MaxStickPitch--; |
666 | else MaxStickPitch--; |
676 | if(abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]) > MaxStickRoll) |
667 | if(abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]) > MaxStickRoll) |
677 | MaxStickRoll = abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]); |
- | |
678 | else MaxStickRoll--; |
- | |
679 | if(abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]) > MaxStickYaw) |
- | |
Line 680... | Line 668... | ||
680 | MaxStickYaw = abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]); |
668 | MaxStickRoll = abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]); |
Line 681... | Line 669... | ||
681 | else MaxStickYaw--; |
669 | else MaxStickRoll--; |
682 | 670 | ||
Line 796... | Line 784... | ||
796 | Gyro_I_Factor = 0.003; |
784 | Gyro_I_Factor = 0.003; |
797 | Looping_Roll = 0; |
785 | Looping_Roll = 0; |
798 | Looping_Pitch = 0; |
786 | Looping_Pitch = 0; |
799 | MaxStickPitch = 0; |
787 | MaxStickPitch = 0; |
800 | MaxStickRoll = 0; |
788 | MaxStickRoll = 0; |
801 | MaxStickYaw = 0; |
- | |
802 | } |
789 | } |
Line 803... | Line 790... | ||
803 | 790 | ||
804 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
791 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
805 | // Trim Gyro-Integrals to ACC-Signals |
792 | // Trim Gyro-Integrals to ACC-Signals |
Line 841... | Line 828... | ||
841 | if((MaxStickPitch > 15) || (MaxStickRoll > 15)) // reduce effect during stick commands |
828 | if((MaxStickPitch > 15) || (MaxStickRoll > 15)) // reduce effect during stick commands |
842 | { |
829 | { |
843 | tmp_long /= 3; |
830 | tmp_long /= 3; |
844 | tmp_long2 /= 3; |
831 | tmp_long2 /= 3; |
845 | } |
832 | } |
846 | if(MaxStickYaw > 25) // reduce further is yaw stick is active |
833 | if(abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]) > 25) // reduce further is yaw stick is active |
847 | { |
834 | { |
848 | tmp_long /= 3; |
835 | tmp_long /= 3; |
849 | tmp_long2 /= 3; |
836 | tmp_long2 /= 3; |
850 | } |
837 | } |
Line 888... | Line 875... | ||
888 | // Calculate deviation of the averaged gyro integral and the averaged acceleration integral |
875 | // Calculate deviation of the averaged gyro integral and the averaged acceleration integral |
889 | IntegralErrorRoll = (int32_t)(MeanIntegralRoll - (int32_t)IntegralAccRoll); |
876 | IntegralErrorRoll = (int32_t)(MeanIntegralRoll - (int32_t)IntegralAccRoll); |
890 | CorrectionRoll = IntegralErrorRoll / ParamSet.GyroAccTrim; |
877 | CorrectionRoll = IntegralErrorRoll / ParamSet.GyroAccTrim; |
891 | AttitudeCorrectionRoll = CorrectionRoll / BALANCE_NUMBER; |
878 | AttitudeCorrectionRoll = CorrectionRoll / BALANCE_NUMBER; |
Line 892... | Line 879... | ||
892 | 879 | ||
893 | if((MaxStickPitch > 15) || (MaxStickRoll > 15) || (MaxStickYaw > 25)) |
880 | if((MaxStickPitch > 15) || (MaxStickRoll > 15) || (abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]) > 25)) |
894 | { |
881 | { |
895 | AttitudeCorrectionPitch /= 2; |
882 | AttitudeCorrectionPitch /= 2; |
896 | AttitudeCorrectionRoll /= 2; |
883 | AttitudeCorrectionRoll /= 2; |
Line 1022... | Line 1009... | ||
1022 | 1009 | ||
1023 | 1010 | ||
1024 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1011 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1025 | // Yawing |
1012 | // Yawing |
1026 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1013 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1027 | if(MaxStickYaw > 20) // yaw stick is activated |
1014 | if(abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]) > 20) // yaw stick is activated |
1028 | { // if not fixed compass course is set update compass course |
1015 | { // if not fixed compass course is set update compass course |
1029 | if(!(ParamSet.GlobalConfig & CFG_COMPASS_FIX)) StoreNewCompassCourse = 1; |
1016 | if(!(ParamSet.GlobalConfig & CFG_COMPASS_FIX)) StoreNewCompassCourse = 1; |
1030 | } |
1017 | } |
Line 1163... | Line 1150... | ||
1163 | if(Reading_GyroYaw > MAX_SENSOR) Reading_GyroYaw = MAX_SENSOR; |
1150 | if(Reading_GyroYaw > MAX_SENSOR) Reading_GyroYaw = MAX_SENSOR; |
1164 | if(Reading_GyroYaw < -MAX_SENSOR) Reading_GyroYaw = -MAX_SENSOR; |
1151 | if(Reading_GyroYaw < -MAX_SENSOR) Reading_GyroYaw = -MAX_SENSOR; |
Line 1165... | Line 1152... | ||
1165 | 1152 | ||
1166 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1153 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1167 | // Height Control |
1154 | // Height Control |
1168 | // The higtht control algorithm reduces the thrust but does not increase the thrust. |
1155 | // The height control algorithm reduces the thrust but does not increase the thrust. |
1169 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1156 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1170 | // If hight control is activated and no emergency landing is active |
1157 | // If height control is activated and no emergency landing is active |
1171 | if((ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL) && (!EmergencyLanding) ) |
1158 | if((ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL) && (!EmergencyLanding) ) |
1172 | { |
1159 | { |
1173 | int tmp_int; |
1160 | int tmp_int; |
1174 | // if hight control is activated by an rc channel |
1161 | // if height control is activated by an rc channel |
1175 | if(ParamSet.GlobalConfig & CFG_HEIGHT_SWITCH) |
1162 | if(ParamSet.GlobalConfig & CFG_HEIGHT_SWITCH) |
1176 | { // check if parameter is less than activation threshold |
1163 | { // check if parameter is less than activation threshold |
1177 | if(FCParam.MaxHeight < 50) |
1164 | if(FCParam.MaxHeight < 50) |
1178 | { |
1165 | { |
1179 | SetPointHeight = ReadingHeight - 20; // update SetPoint with current reading |
1166 | SetPointHeight = ReadingHeight - 20; // update SetPoint with current reading |
1180 | HeightControlActive = 0; // disable hight control |
1167 | HeightControlActive = 0; // disable height control |
1181 | } |
1168 | } |
1182 | else HeightControlActive = 1; // enable hight control |
1169 | else HeightControlActive = 1; // enable height control |
1183 | } |
1170 | } |
1184 | else // no switchable hight control |
1171 | else // no switchable height control |
1185 | { |
1172 | { |
1186 | SetPointHeight = ((int16_t) ExternHeightValue + (int16_t) FCParam.MaxHeight) * (int16_t)ParamSet.Height_Gain - 20; |
1173 | SetPointHeight = ((int16_t) ExternHeightValue + (int16_t) FCParam.MaxHeight) * (int16_t)ParamSet.Height_Gain - 20; |
1187 | HeightControlActive = 1; |
1174 | HeightControlActive = 1; |
1188 | } |
1175 | } |
1189 | // get current hight |
1176 | // get current height |
1190 | h = ReadingHeight; |
1177 | h = ReadingHeight; |
1191 | // if current hight is above the setpoint reduce thrust |
1178 | // if current height is above the setpoint reduce thrust |
1192 | if((h > SetPointHeight) && HeightControlActive) |
1179 | if((h > SetPointHeight) && HeightControlActive) |
- | 1180 | { |
|
1193 | { |
1181 | // ThrustMixFraction - HightDeviation * P - HeightChange * D - ACCTop * DACC |
1194 | // hight difference -> P control part |
1182 | // height difference -> P control part |
1195 | h = ((h - SetPointHeight) * (int16_t) FCParam.Height_P) / 16; |
1183 | h = ((h - SetPointHeight) * (int16_t) FCParam.Height_P) / 16; |
1196 | h = ThrustMixFraction - h; // reduce gas |
1184 | h = ThrustMixFraction - h; // reduce gas |
1197 | // higth gradient --> D control part |
1185 | // height gradient --> D control part |
1198 | h -= (HeightD * FCParam.Height_D) / 8; // D control part |
1186 | h -= (HeightD * FCParam.Height_D) / 8; // D control part |
1199 | // acceleration sensor effect |
1187 | // acceleration sensor effect |
1200 | tmp_int = ((Reading_Integral_Top / 512) * (int32_t) FCParam.Height_ACC_Effect) / 32; |
1188 | tmp_int = ((Reading_Integral_Top / 512) * (int32_t) FCParam.Height_ACC_Effect) / 32; |
1201 | if(tmp_int > 50) tmp_int = 50; |
1189 | if(tmp_int > 50) tmp_int = 50; |
1202 | if(tmp_int < -50) tmp_int = -50; |
1190 | if(tmp_int < -50) tmp_int = -50; |
1203 | h -= tmp_int; |
1191 | h -= tmp_int; |
1204 | // update hight control thrust |
1192 | // update height control thrust |
1205 | HeightControlThrust = (HeightControlThrust*15 + h) / 16; |
1193 | HeightControlThrust = (HeightControlThrust*15 + h) / 16; |
1206 | // limit thrust reduction |
1194 | // limit thrust reduction |
1207 | if(HeightControlThrust < ParamSet.Height_MinThrust) |
1195 | if(HeightControlThrust < ParamSet.Height_MinThrust) |
1208 | { |
1196 | { |
1209 | if(ThrustMixFraction >= ParamSet.Height_MinThrust) HeightControlThrust = ParamSet.Height_MinThrust; |
1197 | if(ThrustMixFraction >= ParamSet.Height_MinThrust) HeightControlThrust = ParamSet.Height_MinThrust; |
1210 | // allows landing also if thrust stick is reduced below min thrust on hight control |
1198 | // allows landing also if thrust stick is reduced below min thrust on height control |
1211 | if(ThrustMixFraction < ParamSet.Height_MinThrust) HeightControlThrust = ThrustMixFraction; |
1199 | if(ThrustMixFraction < ParamSet.Height_MinThrust) HeightControlThrust = ThrustMixFraction; |
1212 | } |
1200 | } |
1213 | // limit thrust to stick setting |
1201 | // limit thrust to stick setting |
1214 | if(HeightControlThrust > ThrustMixFraction) HeightControlThrust = ThrustMixFraction; |
1202 | if(HeightControlThrust > ThrustMixFraction) HeightControlThrust = ThrustMixFraction; |