skipper_raspi_uart_test

Dependencies:   mbed MPU6050_2 HMC5883L_4 SDFileSystem3

Revision:
30:90252dc48c1a
Parent:
29:5d239812ace6
Child:
31:210cc32d3175
--- a/main.cpp	Tue Feb 26 10:52:35 2019 +0000
+++ b/main.cpp	Tue Feb 26 14:24:44 2019 +0000
@@ -72,7 +72,7 @@
 
 bool setupFlag = false;
 bool CameraDegFlag = false;
-bool jevoisFlag = false;
+bool jevoisFlag = true;
 
 int g_CameraDegCounter = 0;    //カメラの回転数をカウント
 
@@ -85,9 +85,9 @@
 
 SDFileSystem sd(PB_15, PB_14, PB_13, PB_12, "sd");
 
-RawSerial pc(PA_2,PA_3,115200); //uart2
+RawSerial pc(PA_2,PA_3,115200); //uart2 jevoiis
 //pa2:UART2_TX,pa3:UART2_RX
-RawSerial pc2(PA_11,PA_12,115200); //uart1
+RawSerial pc2(PA_11,PA_12,115200); //uart1 raspberry
 //pb6:UART1_TX,pb7:UART1_RX
 
 //PWM pin宣言
@@ -142,7 +142,7 @@
     pc2.attach(getSF_Serial_pi, Serial::RxIrq);
     t2.start();
     
-    NVIC_DisableIRQ(USART2_IRQn);
+    /*NVIC_DisableIRQ(USART2_IRQn);
     while(g_landingcommand != 'B'){
         wait_ms(30);
         }
@@ -151,9 +151,9 @@
     NVIC_EnableIRQ(USART2_IRQn);
     wait(5); 
     pc.printf("start\r\n");  
-    
+    */
     while(1) {
-        if(jevoisFlag==true) NVIC_DisableIRQ(USART1_IRQn);
+        if(jevoisFlag==true) NVIC_DisableIRQ(USART6_IRQn);
         else NVIC_DisableIRQ(USART2_IRQn);
         pc.printf("Move Camera Board\r\n");
         MoveCameraBoard();
@@ -161,23 +161,23 @@
         pc.printf("Position\r\n");
         pc.printf("g_landingcommand=%c\r\n",g_landingcommand);
         
-        NVIC_DisableIRQ(USART1_IRQn);
+        NVIC_DisableIRQ(USART6_IRQn);
         NVIC_DisableIRQ(USART2_IRQn);
         if(g_landingcommand!='N') MatchPosition();
-        NVIC_EnableIRQ(USART1_IRQn);
+        NVIC_EnableIRQ(USART6_IRQn);
         NVIC_EnableIRQ(USART2_IRQn);
         
-        if(jevoisFlag==true) NVIC_DisableIRQ(USART1_IRQn);
+        if(jevoisFlag==true) NVIC_DisableIRQ(USART6_IRQn);
         else NVIC_DisableIRQ(USART2_IRQn);
         
         pc.printf("Move Cansat\r\n");
         MoveCansat(g_landingcommand); 
-        if(jevoisFlag==true) NVIC_DisableIRQ(USART1_IRQn);
+        if(jevoisFlag==true) NVIC_DisableIRQ(USART6_IRQn);
         else NVIC_DisableIRQ(USART2_IRQn);
         wait_ms(23);
         
         pc.printf("finish\r\n");
-        if(jevoisFlag==true) NVIC_EnableIRQ(USART1_IRQn);
+        if(jevoisFlag==true) NVIC_EnableIRQ(USART6_IRQn);
         else NVIC_EnableIRQ(USART2_IRQn);
         }
 }
@@ -185,13 +185,13 @@
 
 void MoveCansat(char a)
 {
-    NVIC_DisableIRQ(USART1_IRQn);
+    NVIC_DisableIRQ(USART6_IRQn);
     NVIC_DisableIRQ(USART2_IRQn);
     switch(a){
         case 'N': //MOVE_NEUTRAL 
             servoR.pulsewidth_us(Servo_NEUTRAL_R);
             servoL.pulsewidth_us(Servo_NEUTRAL_L);
-            NVIC_EnableIRQ(USART1_IRQn);
+            NVIC_EnableIRQ(USART6_IRQn);
             NVIC_EnableIRQ(USART2_IRQn);
             g_fp = fopen( "/sd/Datalog01.txt" ,"a" );
             fprintf(g_fp, "Time = %d min %d sec : Goal is not found.\r\n",(int)t2.read()/60,(int)t2.read()%60);        
@@ -201,7 +201,7 @@
         case 'Y': //MOVE_FORWARD
             servoR.pulsewidth_us(Servo_high_FORWARD_R);
             servoL.pulsewidth_us(Servo_high_FORWARD_L);
-            NVIC_EnableIRQ(USART1_IRQn);
+            NVIC_EnableIRQ(USART6_IRQn);
             NVIC_EnableIRQ(USART2_IRQn); 
             g_fp = fopen( "/sd/Datalog01.txt" ,"a" );
             fprintf(g_fp, "Time = %d min %d sec : Cansat move forward .\r\n",(int)t2.read()/60,(int)t2.read()%60);        
@@ -211,7 +211,7 @@
         case 'l': //MOVE_LEFT Low Speed
             servoR.pulsewidth_us(Servo_slow_FORWARD_R);
             servoL.pulsewidth_us(Servo_NEUTRAL_L);
-            NVIC_EnableIRQ(USART1_IRQn);
+            NVIC_EnableIRQ(USART6_IRQn);
             NVIC_EnableIRQ(USART2_IRQn); 
             g_fp = fopen( "/sd/Datalog01.txt","a" );
             fprintf(g_fp, "Time = %d min %d sec : Cansat move left low speed.\r\n",(int)t2.read()/60,(int)t2.read()%60);        
@@ -221,7 +221,7 @@
         case 'L': //MOVE_LEFT High Speed
             servoR.pulsewidth_us(Servo_high_FORWARD_R);
             servoL.pulsewidth_us(Servo_NEUTRAL_L);
-            NVIC_EnableIRQ(USART1_IRQn);
+            NVIC_EnableIRQ(USART6_IRQn);
             NVIC_EnableIRQ(USART2_IRQn); 
             g_fp = fopen( "/sd/Datalog01.txt","a" );
             fprintf(g_fp, "Time = %d min %d sec : Cansat move left high speed.\r\n",(int)t2.read()/60,(int)t2.read()%60);        
@@ -231,7 +231,7 @@
         case 'r': //MOVE_RIGHT Low Speed  
             servoR.pulsewidth_us(Servo_NEUTRAL_R);
             servoL.pulsewidth_us(Servo_slow_FORWARD_L);
-            NVIC_EnableIRQ(USART1_IRQn);
+            NVIC_EnableIRQ(USART6_IRQn);
             NVIC_EnableIRQ(USART2_IRQn); 
             g_fp = fopen( "/sd/Datalog01.txt","a" );
             fprintf(g_fp, "Time = %d min %d sec : Cansat move right low speed.\r\n",(int)t2.read()/60,(int)t2.read()%60);        
@@ -241,7 +241,7 @@
         case 'R': //MOVE_RIGHT  High Speed
             servoR.pulsewidth_us(Servo_NEUTRAL_R);
             servoL.pulsewidth_us(Servo_high_FORWARD_L);
-            NVIC_EnableIRQ(USART1_IRQn);
+            NVIC_EnableIRQ(USART6_IRQn);
             NVIC_EnableIRQ(USART2_IRQn); 
             g_fp = fopen( "/sd/Datalog01.txt","a" );
             fprintf(g_fp, "Time = %d min %d sec : Cansat move left high speed.\r\n",(int)t2.read()/60,(int)t2.read()%60);        
@@ -251,7 +251,7 @@
         case 'G': //GOAL_FORWARD
             servoR.pulsewidth_us(Servo_slow_FORWARD_R);
             servoL.pulsewidth_us(Servo_slow_FORWARD_L);
-            NVIC_EnableIRQ(USART1_IRQn);
+            NVIC_EnableIRQ(USART6_IRQn);
             NVIC_EnableIRQ(USART2_IRQn); 
             g_fp = fopen( "/sd/Datalog01.txt","a" );
             fprintf(g_fp, "Time = %d min %d sec : Cansat move goal forward mode.\r\n",(int)t2.read()/60,(int)t2.read()%60);        
@@ -266,7 +266,7 @@
                 SensingMPU();
                 wait_ms(30);
             }while((nowAngle[PITCH]>20||nowAngle[PITCH]<-20)&&(nowAngle[ROLL]>20||nowAngle[ROLL]<-20));
-            NVIC_EnableIRQ(USART1_IRQn);
+            NVIC_EnableIRQ(USART6_IRQn);
             NVIC_EnableIRQ(USART2_IRQn);  
             g_fp = fopen( "/sd/Datalog01.txt","a" );
             fprintf(g_fp, "Time = %d min %d sec : Cansat move forward 1sec!.\r\n",(int)t2.read()/60,(int)t2.read()%60);        
@@ -281,7 +281,7 @@
                 SensingMPU();
                 wait_ms(30);
             }while((nowAngle[PITCH]>20||nowAngle[PITCH]<-20)&&(nowAngle[ROLL]>20||nowAngle[ROLL]<-20));
-            NVIC_EnableIRQ(USART1_IRQn);
+            NVIC_EnableIRQ(USART6_IRQn);
             NVIC_EnableIRQ(USART2_IRQn); 
             g_fp = fopen( "/sd/Datalog01.txt","a" );
             fprintf(g_fp, "Time = %d min %d sec : Cansat move forward 2sec!.\r\n",(int)t2.read()/60,(int)t2.read()%60);        
@@ -296,7 +296,7 @@
                 SensingMPU();
                 wait_ms(30);
             }while((nowAngle[PITCH]>20||nowAngle[PITCH]<-20)&&(nowAngle[ROLL]>20||nowAngle[ROLL]<-20));
-            NVIC_EnableIRQ(USART1_IRQn);
+            NVIC_EnableIRQ(USART6_IRQn);
             NVIC_EnableIRQ(USART2_IRQn); 
             g_fp = fopen( "/sd/Datalog01.txt","a" );
             fprintf(g_fp, "Time = %d min %d sec : Cansat move forward 3sec!.\r\n",(int)t2.read()/60,(int)t2.read()%60);        
@@ -311,7 +311,7 @@
                 SensingMPU();
                 wait_ms(30);
             }while((nowAngle[PITCH]>20||nowAngle[PITCH]<-20)||(nowAngle[ROLL]>20||nowAngle[ROLL]<-20));
-            NVIC_EnableIRQ(USART1_IRQn);
+            NVIC_EnableIRQ(USART6_IRQn);
             NVIC_EnableIRQ(USART2_IRQn); 
             g_fp = fopen( "/sd/Datalog01.txt","a" );
             fprintf(g_fp, "Time = %d min %d sec : Cansat move forward 4sec!.\r\n",(int)t2.read()/60,(int)t2.read()%60);        
@@ -326,7 +326,7 @@
                 SensingMPU();
                 wait_ms(30);
             }while((nowAngle[PITCH]>20||nowAngle[PITCH]<-20)&&(nowAngle[ROLL]>20||nowAngle[ROLL]<-20));
-            NVIC_EnableIRQ(USART1_IRQn);
+            NVIC_EnableIRQ(USART6_IRQn);
             NVIC_EnableIRQ(USART2_IRQn); 
             g_fp = fopen( "/sd/Datalog01.txt","a" );
             fprintf(g_fp, "Time = %d min %d sec : Cansat move forward 5sec!.\r\n",(int)t2.read()/60,(int)t2.read()%60);        
@@ -335,7 +335,7 @@
             
         case 'M': //MatchPosition
             servoR.pulsewidth_us(Matchspeed);
-            NVIC_EnableIRQ(USART1_IRQn);
+            NVIC_EnableIRQ(USART6_IRQn);
             NVIC_EnableIRQ(USART2_IRQn); 
             break;
         
@@ -344,18 +344,18 @@
             servoTurnTable.pulsewidth_us(Turntable_NEUTRAL + Turntable_speed);
             wait_ms((float)Time360/(float)2);
             servoTurnTable.pulsewidth_us(Turntable_NEUTRAL);
-            NVIC_EnableIRQ(USART1_IRQn);
+            NVIC_EnableIRQ(USART6_IRQn);
             NVIC_EnableIRQ(USART2_IRQn); 
             break;
         
         case 'B':
             /*RasPiからの超音波判定(プログラムスタート部)*/
-            NVIC_EnableIRQ(USART1_IRQn);
+            NVIC_EnableIRQ(USART6_IRQn);
             NVIC_EnableIRQ(USART2_IRQn); 
             break;
             
         default :
-            NVIC_EnableIRQ(USART1_IRQn);
+            NVIC_EnableIRQ(USART6_IRQn);
             NVIC_EnableIRQ(USART2_IRQn); 
             break;
      
@@ -534,7 +534,7 @@
         
                 
         
-        //pc.printf("%c",SFbuf[bufcounter]);
+        pc.printf("%c",SFbuf[bufcounter]);
         
         if(SFbuf[0]=='S'&&bufcounter<5)bufcounter++;
             
@@ -591,13 +591,13 @@
     Init_sensors();
     //switch2.rise(ResetTrim);
     
-    //NVIC_SetPriority(USART1_IRQn,0);
+    //NVIC_SetPriority(USART6_IRQn,0);
     //NVIC_SetPriority(EXTI0_IRQn,1);
     //NVIC_SetPriority(TIM5_IRQn,2);
     //NVIC_SetPriority(EXTI9_5_IRQn,3);
     //NVIC_SetPriority(USART2_IRQn,4);
     
-    NVIC_SetPriority(USART1_IRQn,0);//割り込み優先度
+    NVIC_SetPriority(USART6_IRQn,0);//割り込み優先度
     NVIC_SetPriority(USART2_IRQn,1);
     
     DisplayClock();
@@ -659,7 +659,7 @@
     float rpy[3] = {0};
     static uint16_t count_changeRPY = 0;
     static bool flg_checkoutlier = false;
-    NVIC_DisableIRQ(USART1_IRQn);
+    NVIC_DisableIRQ(USART6_IRQn);
     NVIC_DisableIRQ(USART2_IRQn);
     NVIC_DisableIRQ(TIM5_IRQn);
     NVIC_DisableIRQ(EXTI0_IRQn);
@@ -667,7 +667,7 @@
 
     mpu6050.getRollPitchYaw_Skipper(rpy);
  
-    NVIC_EnableIRQ(USART1_IRQn);
+    NVIC_EnableIRQ(USART6_IRQn);
     NVIC_EnableIRQ(USART2_IRQn);
     NVIC_EnableIRQ(TIM5_IRQn);
     NVIC_EnableIRQ(EXTI0_IRQn);
@@ -723,7 +723,7 @@
     float rpy=0;
     static uint16_t count_changeRPY = 0;
     static bool flg_checkoutlier = false;
-    NVIC_DisableIRQ(USART1_IRQn);
+    NVIC_DisableIRQ(USART6_IRQn);
     NVIC_DisableIRQ(USART2_IRQn);
     //NVIC_DisableIRQ(TIM5_IRQn);
     //NVIC_DisableIRQ(EXTI0_IRQn);
@@ -731,7 +731,7 @@
 
     rpy= compass.getHeadingXYDeg(Time360,Match_wid);
  
-    NVIC_EnableIRQ(USART1_IRQn);
+    NVIC_EnableIRQ(USART6_IRQn);
     NVIC_EnableIRQ(USART2_IRQn);
     //NVIC_EnableIRQ(TIM5_IRQn);
     //NVIC_EnableIRQ(EXTI0_IRQn);