フェイルセーフ完成版

Dependencies:   HCSR04_2 MPU6050_2 mbed SDFileSystem3

Fork of Autoflight2018_53 by 航空研究会

Revision:
40:f03b62a3b495
Parent:
39:b8d5be233b70
Child:
41:3b8c250ae79c
--- a/main.cpp	Tue Sep 25 10:27:21 2018 +0000
+++ b/main.cpp	Wed Sep 26 04:02:25 2018 +0000
@@ -1192,7 +1192,6 @@
     static int groundcount = 0;
     
     targetAngle[ROLL] = g_glideloopROLL;
-    targetAngle[PITCH] = g_glideloopPITCH;
     
     autopwm[RUD]=g_glideloopRUD;
    // autopwm[THR]=oldTHR;
@@ -1241,8 +1240,14 @@
         else THRcount = 0;
         NVIC_EnableIRQ(EXTI9_5_IRQn);
         
-        if(flg_ground == true) autopwm[THR] = SetTHRinRatio(0.6);
-        else autopwm[THR] = minpwm[THR];
+        if(flg_ground == true) {
+            autopwm[THR] = SetTHRinRatio(0.6);
+            targetAngle[PITCH] = g_gostraightPITCH;
+            }
+        else {
+            autopwm[THR] = minpwm[THR];
+            targetAngle[PITCH] = g_glideloopPITCH;
+            }
         
         NVIC_DisableIRQ(USART1_IRQn);
         if(!CheckSW_Up(Ch7)){
@@ -1411,8 +1416,8 @@
                 }
                 else{
                 targetAngle[ROLL] = g_rightloopROLL_approach;
-        targetAngle[PITCH] = g_rightloopPITCH ;
-        autopwm[RUD]=g_rightloopRUD_approach;              //RUD固定
+        targetAngle[PITCH] = g_rightloopPITCH_approach ;
+        autopwm[RUD]=g_rightloopRUD_approach; //RUD固定
             if(autopwm[AIL_R]<trimpwm[AIL_R]){                                                                                  //エルロン上がりやすさ調節
                 autopwm[AIL_L]=trimpwm[AIL_L]+AIL_L_correctionrightloop+(autopwm[AIL_R]-trimpwm[AIL_R])*AIL_L_RatioRising;
                 }
@@ -1429,7 +1434,7 @@
                 }
                     else{
                         targetAngle[ROLL] = g_leftloopROLL_approach;
-                        targetAngle[PITCH] = g_leftloopPITCH;
+                        targetAngle[PITCH] = g_leftloopPITCH_approach;
                         autopwm[RUD]=g_leftloopRUD_approach;
                         if(autopwm[AIL_R]<trimpwm[AIL_R]){
                             autopwm[AIL_L]=trimpwm[AIL_L]+AIL_L_correctionleftloop+(autopwm[AIL_R]-trimpwm[AIL_R])*AIL_L_RatioRising;
@@ -1541,7 +1546,7 @@
 
     targetAngle[PITCH] = g_rightloopPITCH ;
     autopwm[RUD]=g_rightloopRUD;              //RUD固定
-    autopwm[THR] = SetTHRinRatio(0.5);                  //手動スロットル記憶
+    autopwm[THR] = SetTHRinRatio(0.45);                  //手動スロットル記憶
     
     /*
     if (nowAngle[ROLL]>20.0||nowAngle[ROLL]<-20.0){
@@ -1574,7 +1579,7 @@
 void UpdateTargetAngle_Rightloop_zero(float targetAngle[3]){ //右旋回
     autopwm[THR]=minpwm[THR];
     targetAngle[ROLL] = g_rightloopROLL_approach;
-    targetAngle[PITCH] = g_rightloopPITCH ;
+    targetAngle[PITCH] = g_rightloopPITCH_approach ;
     autopwm[RUD]=g_rightloopRUD_approach;              //RUD固定
     if(autopwm[AIL_R]<trimpwm[AIL_R]){                                                                                  //エルロン上がりやすさ調節
             autopwm[AIL_L]=trimpwm[AIL_L]+AIL_L_correctionrightloop+(autopwm[AIL_R]-trimpwm[AIL_R])*AIL_L_RatioRising;
@@ -1591,7 +1596,7 @@
     targetAngle[ROLL] = g_rightloopROLLshort;
     targetAngle[PITCH] = g_rightloopPITCHshort;
     autopwm[RUD]=g_rightloopshortRUD;
-    autopwm[THR] = SetTHRinRatio(0.5);
+    autopwm[THR] = SetTHRinRatio(0.45);
     if(autopwm[AIL_R]<trimpwm[AIL_R]){
         autopwm[AIL_L]=trimpwm[AIL_L]+AIL_L_correctionrightloopshort+(autopwm[AIL_R]-trimpwm[AIL_R])*AIL_L_RatioRising;
         }
@@ -1606,7 +1611,7 @@
     targetAngle[ROLL] = g_leftloopROLL;
     targetAngle[PITCH] = g_leftloopPITCH;
     autopwm[RUD]=g_leftloopRUD;
-    autopwm[THR] = SetTHRinRatio(0.5);
+    autopwm[THR] = SetTHRinRatio(0.45);
     if(autopwm[AIL_R]<trimpwm[AIL_R]){
         autopwm[AIL_L]=trimpwm[AIL_L]+g_AIL_L_correctionleftloop+(autopwm[AIL_R]-trimpwm[AIL_R])*AIL_L_RatioRising;
         }
@@ -1620,7 +1625,7 @@
 void UpdateTargetAngle_Leftloop_zero(float targetAngle[3]){
     
     targetAngle[ROLL] = g_leftloopROLL_approach;
-    targetAngle[PITCH] = g_leftloopPITCH;
+    targetAngle[PITCH] = g_leftloopPITCH_approach;
     autopwm[RUD]=g_leftloopRUD_approach;
     autopwm[THR] = minpwm[THR];
     if(autopwm[AIL_R]<trimpwm[AIL_R]){
@@ -1638,7 +1643,7 @@
     targetAngle[ROLL] = g_leftloopROLLshort;
     targetAngle[PITCH] = g_leftloopPITCHshort;
     autopwm[RUD]=g_leftloopRUD;
-    autopwm[THR] = SetTHRinRatio(0.5);
+    autopwm[THR] = SetTHRinRatio(0.45);
     if(autopwm[AIL_R]<trimpwm[AIL_R]){
         autopwm[AIL_L]=trimpwm[AIL_L]+AIL_L_correctionleftloopshort+(autopwm[AIL_R]-trimpwm[AIL_R])*AIL_L_RatioRising;
         }
@@ -1673,10 +1678,10 @@
     //pc.printf("%d\t",autopwm[AIL_L]);  
     //pc.printf("%d\t",autopwm[RUD]);
     //pc.printf("%d",g_distance);
-    //NVIC_DisableIRQ(EXTI9_5_IRQn); 
-    //pc.printf("g_distance = %d",g_distance);
-    //NVIC_EnableIRQ(EXTI9_5_IRQn);
+    NVIC_DisableIRQ(EXTI9_5_IRQn); 
+    pc.printf("g_distance = %d",g_distance);
+    NVIC_EnableIRQ(EXTI9_5_IRQn);
     //pc.printf("Mode: %c: ",g_buf[0]);
     //if(g_buf[0] == 'Y') pc.printf(" %3.1f",g_SerialTargetYAW);
-    //pc.printf("\r\n");
+    pc.printf("\r\n");
 }
\ No newline at end of file