skipper_raspi_uart_test

Dependencies:   mbed MPU6050_2 HMC5883L_4 SDFileSystem3

Committer:
taknokolat
Date:
Thu Feb 28 11:59:51 2019 +0000
Revision:
32:ab030832d180
Parent:
31:210cc32d3175
Child:
33:5f77118eacd5
a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
HARUKIDELTA 0:84ddd6d354e1 1 #include "mbed.h"
Skykon 3:c18342e4fddd 2 #include "MPU6050_DMP6.h"
taknokolat 6:166746820555 3 #include "HMC5883L.h"
taknokolat 12:083662bca47d 4 #include "SDFileSystem.h"
taknokolat 12:083662bca47d 5 #include "SkipperSv2.h"
taknokolat 12:083662bca47d 6 #include "falfalla.h"
Skykon 3:c18342e4fddd 7
Skykon 3:c18342e4fddd 8 //MPU_check用
Skykon 3:c18342e4fddd 9 #define PI 3.14159265358979
HARUKIDELTA 0:84ddd6d354e1 10
HARUKIDELTA 17:83db05cab3d1 11 #define servo_NEUTRAL_R 1614
HARUKIDELTA 17:83db05cab3d1 12 #define servo_NEUTRAL_L 1621
HARUKIDELTA 0:84ddd6d354e1 13 #define servo_slow_FORWARD_R 1560
HARUKIDELTA 0:84ddd6d354e1 14 #define servo_slow_FORWARD_L 1560
taknokolat 12:083662bca47d 15 #define servo_high_FORWARD_R 1860
taknokolat 12:083662bca47d 16 #define servo_high_FORWARD_L 1860
HARUKIDELTA 17:83db05cab3d1 17 #define turntable_NEUTRAL 1180 //カメラ台座のサーボ
HARUKIDELTA 17:83db05cab3d1 18 #define matchspeed 1500 + 100 //カメラと方向を合わせるときの車輪の速度
HARUKIDELTA 17:83db05cab3d1 19 #define focus_NEUTRAL 1455 //焦点合わせ用サーボ
HARUKIDELTA 17:83db05cab3d1 20 #define camera_deg_A 1400 //カメラ角度調整
HARUKIDELTA 17:83db05cab3d1 21 #define camera_deg_B 1800
HARUKIDELTA 17:83db05cab3d1 22 #define pint_speed 25
taknokolat 20:011977a37394 23 #define pint_wait 3
HARUKIDELTA 17:83db05cab3d1 24 #define turntable_speed 1800
taknokolat 24:0ad1725c7849 25 #define time360 110
taknokolat 24:0ad1725c7849 26 #define match_wid 5
taknokolat 20:011977a37394 27 #define camera_board_wait 100
HARUKIDELTA 0:84ddd6d354e1 28
taknokolat 32:ab030832d180 29 #define ReturnCount 2
taknokolat 32:ab030832d180 30
HARUKIDELTA 0:84ddd6d354e1 31 #define MOVE_NEUTRAL 0
taknokolat 19:949bab1e9451 32 #define MOVE_FORWARD 1
HARUKIDELTA 0:84ddd6d354e1 33 #define MOVE_LEFT 2
HARUKIDELTA 0:84ddd6d354e1 34 #define MOVE_RIGHT 3
HARUKIDELTA 0:84ddd6d354e1 35 #define MOVE_BACK 4
Skykon 3:c18342e4fddd 36 #define GOAL_FORWARD 5 //ゴール付近_ゆっくり
HARUKIDELTA 0:84ddd6d354e1 37 #define GOAL_LEFT 6
HARUKIDELTA 0:84ddd6d354e1 38 #define GOAL_RIGHT 7
Skykon 3:c18342e4fddd 39 #define MAX_FORWARD 8 //はやい_姿勢修正用
HARUKIDELTA 0:84ddd6d354e1 40 #define MAX_BACK 9
HARUKIDELTA 0:84ddd6d354e1 41
taknokolat 1:290e621741fd 42 void getSF_Serial_jevois();
taknokolat 1:290e621741fd 43 void getSF_Serial_pi();
taknokolat 1:290e621741fd 44
Skykon 3:c18342e4fddd 45 //MPU_check用
Skykon 3:c18342e4fddd 46 void SensingMPU();
taknokolat 7:8989a4b84695 47
taknokolat 7:8989a4b84695 48 void MoveCansat(char g_landingcommand);
Skykon 3:c18342e4fddd 49 void setup();
Skykon 3:c18342e4fddd 50 void Init_sensors();
Skykon 3:c18342e4fddd 51 void DisplayClock();
taknokolat 4:67f705d42f1e 52 void DebugPrint();
taknokolat 6:166746820555 53 void SensingHMC();
taknokolat 7:8989a4b84695 54 void MoveCameraBoard();
taknokolat 7:8989a4b84695 55 void MatchPosition();
taknokolat 7:8989a4b84695 56 void FocusAdjust();
Skykon 3:c18342e4fddd 57
taknokolat 12:083662bca47d 58 //sd設定
taknokolat 12:083662bca47d 59 int GetParameter(FILE *fp, const char *paramName,char parameter[]);
taknokolat 12:083662bca47d 60
taknokolat 13:b088f0db7158 61 int SetOptions(int *Servo_NEUTRAL_R,int *Servo_NEUTRAL_L,
taknokolat 12:083662bca47d 62 int *Servo_high_FORWARD_R,int *Servo_high_FORWARD_L,
taknokolat 12:083662bca47d 63 int *Servo_slow_FORWARD_R,int *Servo_slow_FORWARD_L,
taknokolat 12:083662bca47d 64 int *Turntable_NEUTRAL,int *Matchspeed,int *Focus_NEUTRAL,
taknokolat 16:26cee2aaf61d 65 int *Camera_deg_A, int *Camera_deg_B,
HARUKIDELTA 17:83db05cab3d1 66 int *Pint_speed, float *Pint_wait,
taknokolat 19:949bab1e9451 67 int *Turntable_speed,
taknokolat 24:0ad1725c7849 68 int *Time360, int *Match_wid,
taknokolat 20:011977a37394 69 int *Camera_board_wait
taknokolat 12:083662bca47d 70 );
taknokolat 12:083662bca47d 71
taknokolat 6:166746820555 72 static float nowAngle[3] = {0,0,0},nowAngle_HMC=0;
taknokolat 6:166746820555 73 float FirstROLL = 0.0, FirstPITCH = 0.0 ,FirstYAW = 0.0,g_FirstYAW_HMC;
Skykon 3:c18342e4fddd 74
taknokolat 7:8989a4b84695 75 bool setupFlag = false;
taknokolat 7:8989a4b84695 76 bool CameraDegFlag = false;
taknokolat 30:90252dc48c1a 77 bool jevoisFlag = true;
taknokolat 31:210cc32d3175 78 bool FocusFlag = false;
taknokolat 4:67f705d42f1e 79
taknokolat 24:0ad1725c7849 80 int g_CameraDegCounter = 0; //カメラの回転数をカウント
taknokolat 24:0ad1725c7849 81
Skykon 3:c18342e4fddd 82 enum Angle{ROLL, PITCH, YAW}; //yaw:北を0とした絶対角度
Skykon 3:c18342e4fddd 83
Skykon 3:c18342e4fddd 84 Timer t;
HARUKIDELTA 26:ea86e69563b5 85 Timer t2;
Skykon 3:c18342e4fddd 86
HARUKIDELTA 25:1f938342d5f9 87 FILE *g_fp;
HARUKIDELTA 25:1f938342d5f9 88
taknokolat 14:90e9b44eb819 89 SDFileSystem sd(PB_15, PB_14, PB_13, PB_12, "sd");
taknokolat 14:90e9b44eb819 90
taknokolat 30:90252dc48c1a 91 RawSerial pc(PA_2,PA_3,115200); //uart2 jevoiis
taknokolat 11:d44d137831b9 92 //pa2:UART2_TX,pa3:UART2_RX
taknokolat 30:90252dc48c1a 93 RawSerial pc2(PA_11,PA_12,115200); //uart1 raspberry
taknokolat 11:d44d137831b9 94 //pb6:UART1_TX,pb7:UART1_RX
taknokolat 11:d44d137831b9 95
HARUKIDELTA 5:8bfe95431ec0 96 //PWM pin宣言
taknokolat 6:166746820555 97 PwmOut servoR(PC_6); //TIM3_CH1 車輪右
taknokolat 6:166746820555 98 PwmOut servoL(PC_7); //TIM3_CH2 車輪左
HARUKIDELTA 5:8bfe95431ec0 99 PwmOut servoTurnTable(PB_0); //TIM3_CH3 カメラ台回転Servo
HARUKIDELTA 5:8bfe95431ec0 100 PwmOut servoCameradeg(PB_1); //TIM3_CH4 カメラ角度調節Servo
HARUKIDELTA 5:8bfe95431ec0 101 PwmOut servoCameraPinto(PB_6); //TIM4_CH1 カメラピント合わせ
HARUKIDELTA 5:8bfe95431ec0 102 PwmOut servoCameramount(PA_6); //skipperウラ カメラマウント起動
HARUKIDELTA 5:8bfe95431ec0 103 PwmOut servoGetUP(PC_8); //skipperウラ 起き上がり動作
Skykon 3:c18342e4fddd 104
HARUKIDELTA 5:8bfe95431ec0 105 /*通信用のpinは
HARUKIDELTA 5:8bfe95431ec0 106 PA_3(UART2_Rx) skipperウラ
HARUKIDELTA 5:8bfe95431ec0 107 PA_12(UART6_Rx) skipperオモテ USB端子より
HARUKIDELTA 5:8bfe95431ec0 108 PB_7 (UART1_Rx) skipperオモテ 6番目 TIM4_CH2
HARUKIDELTA 5:8bfe95431ec0 109 */
HARUKIDELTA 5:8bfe95431ec0 110
HARUKIDELTA 5:8bfe95431ec0 111 /*超音波はRaspberryPiに積む*/
HARUKIDELTA 5:8bfe95431ec0 112
HARUKIDELTA 23:29b2722bd753 113 DigitalOut led1(PA_0); //tanakaOK kimuraは動作不良
HARUKIDELTA 23:29b2722bd753 114 DigitalOut led2(PA_1); //tanakaOK kimuraOK
HARUKIDELTA 23:29b2722bd753 115 DigitalOut led3(PB_5); //使ってないよ
HARUKIDELTA 23:29b2722bd753 116 DigitalOut led4(PB_4); //使ってないよ
HARUKIDELTA 17:83db05cab3d1 117
HARUKIDELTA 17:83db05cab3d1 118
HARUKIDELTA 5:8bfe95431ec0 119 //外付けコンパス
taknokolat 24:0ad1725c7849 120 //HMC5883L compass(PB_9, PB_8); //コンパスセンサー TIM4_CH3とCH4
HARUKIDELTA 0:84ddd6d354e1 121
taknokolat 2:f30666d7838b 122 char g_landingcommand='N';
taknokolat 1:290e621741fd 123
Skykon 3:c18342e4fddd 124 //MPU_check用
Skykon 3:c18342e4fddd 125 MPU6050DMP6 mpu6050(PC_0,&pc);
Skykon 3:c18342e4fddd 126
Skykon 3:c18342e4fddd 127
HARUKIDELTA 0:84ddd6d354e1 128 int main() {
taknokolat 1:290e621741fd 129
Skykon 3:c18342e4fddd 130 //MPU_check
Skykon 3:c18342e4fddd 131 setup();
taknokolat 19:949bab1e9451 132 //コンパスチェック用
taknokolat 19:949bab1e9451 133 /*while(1){
taknokolat 22:a19be3b505b7 134 //SensingMPU();
taknokolat 19:949bab1e9451 135 SensingHMC();
taknokolat 22:a19be3b505b7 136 //pc.printf("%3.2f\t",nowAngle[2]);
taknokolat 19:949bab1e9451 137 pc.printf("%3.2f\t",nowAngle_HMC); //HMC
taknokolat 19:949bab1e9451 138 pc.printf("\r\n");
taknokolat 19:949bab1e9451 139 wait_ms(30);
taknokolat 19:949bab1e9451 140 }*/
Skykon 3:c18342e4fddd 141
taknokolat 11:d44d137831b9 142
taknokolat 1:290e621741fd 143 // シリアル通信受信の割り込みイベント登録
taknokolat 1:290e621741fd 144 pc.attach(getSF_Serial_jevois, Serial::RxIrq);
taknokolat 12:083662bca47d 145 pc2.attach(getSF_Serial_pi, Serial::RxIrq);
HARUKIDELTA 27:f67efcee6509 146 t2.start();
taknokolat 1:290e621741fd 147
taknokolat 30:90252dc48c1a 148 /*NVIC_DisableIRQ(USART2_IRQn);
taknokolat 29:5d239812ace6 149 while(g_landingcommand != 'B'){
taknokolat 29:5d239812ace6 150 wait_ms(30);
taknokolat 29:5d239812ace6 151 }
taknokolat 29:5d239812ace6 152
taknokolat 29:5d239812ace6 153 jevoisFlag = true;
taknokolat 29:5d239812ace6 154 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 29:5d239812ace6 155 wait(5);
taknokolat 29:5d239812ace6 156 pc.printf("start\r\n");
taknokolat 30:90252dc48c1a 157 */
taknokolat 31:210cc32d3175 158
taknokolat 31:210cc32d3175 159 servoCameraPinto.pulsewidth_us(Focus_NEUTRAL-200);
taknokolat 31:210cc32d3175 160 wait(1);
taknokolat 31:210cc32d3175 161 servoCameraPinto.pulsewidth_us(Focus_NEUTRAL);
taknokolat 31:210cc32d3175 162
HARUKIDELTA 0:84ddd6d354e1 163 while(1) {
taknokolat 30:90252dc48c1a 164 if(jevoisFlag==true) NVIC_DisableIRQ(USART6_IRQn);
taknokolat 7:8989a4b84695 165 else NVIC_DisableIRQ(USART2_IRQn);
taknokolat 20:011977a37394 166 pc.printf("Move Camera Board\r\n");
taknokolat 10:63fe920595a7 167 MoveCameraBoard();
taknokolat 10:63fe920595a7 168
taknokolat 20:011977a37394 169 pc.printf("Position\r\n");
taknokolat 22:a19be3b505b7 170 pc.printf("g_landingcommand=%c\r\n",g_landingcommand);
HARUKIDELTA 25:1f938342d5f9 171
taknokolat 30:90252dc48c1a 172 NVIC_DisableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 173 NVIC_DisableIRQ(USART2_IRQn);
taknokolat 7:8989a4b84695 174 if(g_landingcommand!='N') MatchPosition();
taknokolat 30:90252dc48c1a 175 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 176 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 8:d11a59d2a2f1 177
taknokolat 30:90252dc48c1a 178 if(jevoisFlag==true) NVIC_DisableIRQ(USART6_IRQn);
taknokolat 8:d11a59d2a2f1 179 else NVIC_DisableIRQ(USART2_IRQn);
taknokolat 8:d11a59d2a2f1 180
taknokolat 20:011977a37394 181 pc.printf("Move Cansat\r\n");
taknokolat 7:8989a4b84695 182 MoveCansat(g_landingcommand);
taknokolat 30:90252dc48c1a 183 if(jevoisFlag==true) NVIC_DisableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 184 else NVIC_DisableIRQ(USART2_IRQn);
Skykon 3:c18342e4fddd 185 wait_ms(23);
taknokolat 8:d11a59d2a2f1 186
taknokolat 20:011977a37394 187 pc.printf("finish\r\n");
taknokolat 30:90252dc48c1a 188 if(jevoisFlag==true) NVIC_EnableIRQ(USART6_IRQn);
taknokolat 7:8989a4b84695 189 else NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 0:84ddd6d354e1 190 }
HARUKIDELTA 0:84ddd6d354e1 191 }
HARUKIDELTA 0:84ddd6d354e1 192
Skykon 3:c18342e4fddd 193
taknokolat 22:a19be3b505b7 194 void MoveCansat(char a)
HARUKIDELTA 0:84ddd6d354e1 195 {
taknokolat 30:90252dc48c1a 196 NVIC_DisableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 197 NVIC_DisableIRQ(USART2_IRQn);
taknokolat 22:a19be3b505b7 198 switch(a){
taknokolat 2:f30666d7838b 199 case 'N': //MOVE_NEUTRAL
HARUKIDELTA 17:83db05cab3d1 200 servoR.pulsewidth_us(Servo_NEUTRAL_R);
HARUKIDELTA 17:83db05cab3d1 201 servoL.pulsewidth_us(Servo_NEUTRAL_L);
taknokolat 30:90252dc48c1a 202 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 203 NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 26:ea86e69563b5 204 g_fp = fopen( "/sd/Datalog01.txt" ,"a" );
HARUKIDELTA 27:f67efcee6509 205 fprintf(g_fp, "Time = %d min %d sec : Goal is not found.\r\n",(int)t2.read()/60,(int)t2.read()%60);
HARUKIDELTA 26:ea86e69563b5 206 fclose(g_fp);
HARUKIDELTA 0:84ddd6d354e1 207 break;
taknokolat 1:290e621741fd 208
taknokolat 2:f30666d7838b 209 case 'Y': //MOVE_FORWARD
HARUKIDELTA 17:83db05cab3d1 210 servoR.pulsewidth_us(Servo_high_FORWARD_R);
HARUKIDELTA 17:83db05cab3d1 211 servoL.pulsewidth_us(Servo_high_FORWARD_L);
taknokolat 30:90252dc48c1a 212 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 213 NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 27:f67efcee6509 214 g_fp = fopen( "/sd/Datalog01.txt" ,"a" );
HARUKIDELTA 27:f67efcee6509 215 fprintf(g_fp, "Time = %d min %d sec : Cansat move forward .\r\n",(int)t2.read()/60,(int)t2.read()%60);
HARUKIDELTA 27:f67efcee6509 216 fclose(g_fp);
HARUKIDELTA 0:84ddd6d354e1 217 break;
taknokolat 1:290e621741fd 218
taknokolat 12:083662bca47d 219 case 'l': //MOVE_LEFT Low Speed
HARUKIDELTA 17:83db05cab3d1 220 servoR.pulsewidth_us(Servo_slow_FORWARD_R);
taknokolat 22:a19be3b505b7 221 servoL.pulsewidth_us(Servo_NEUTRAL_L);
taknokolat 30:90252dc48c1a 222 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 223 NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 27:f67efcee6509 224 g_fp = fopen( "/sd/Datalog01.txt","a" );
HARUKIDELTA 27:f67efcee6509 225 fprintf(g_fp, "Time = %d min %d sec : Cansat move left low speed.\r\n",(int)t2.read()/60,(int)t2.read()%60);
HARUKIDELTA 27:f67efcee6509 226 fclose(g_fp);
HARUKIDELTA 27:f67efcee6509 227 break;
HARUKIDELTA 27:f67efcee6509 228
taknokolat 12:083662bca47d 229 case 'L': //MOVE_LEFT High Speed
HARUKIDELTA 17:83db05cab3d1 230 servoR.pulsewidth_us(Servo_high_FORWARD_R);
taknokolat 22:a19be3b505b7 231 servoL.pulsewidth_us(Servo_NEUTRAL_L);
taknokolat 30:90252dc48c1a 232 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 233 NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 27:f67efcee6509 234 g_fp = fopen( "/sd/Datalog01.txt","a" );
HARUKIDELTA 27:f67efcee6509 235 fprintf(g_fp, "Time = %d min %d sec : Cansat move left high speed.\r\n",(int)t2.read()/60,(int)t2.read()%60);
HARUKIDELTA 27:f67efcee6509 236 fclose(g_fp);
HARUKIDELTA 27:f67efcee6509 237 break;
taknokolat 1:290e621741fd 238
taknokolat 12:083662bca47d 239 case 'r': //MOVE_RIGHT Low Speed
taknokolat 22:a19be3b505b7 240 servoR.pulsewidth_us(Servo_NEUTRAL_R);
HARUKIDELTA 17:83db05cab3d1 241 servoL.pulsewidth_us(Servo_slow_FORWARD_L);
taknokolat 30:90252dc48c1a 242 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 243 NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 27:f67efcee6509 244 g_fp = fopen( "/sd/Datalog01.txt","a" );
HARUKIDELTA 27:f67efcee6509 245 fprintf(g_fp, "Time = %d min %d sec : Cansat move right low speed.\r\n",(int)t2.read()/60,(int)t2.read()%60);
HARUKIDELTA 27:f67efcee6509 246 fclose(g_fp);
HARUKIDELTA 0:84ddd6d354e1 247 break;
taknokolat 12:083662bca47d 248
taknokolat 12:083662bca47d 249 case 'R': //MOVE_RIGHT High Speed
taknokolat 22:a19be3b505b7 250 servoR.pulsewidth_us(Servo_NEUTRAL_R);
HARUKIDELTA 17:83db05cab3d1 251 servoL.pulsewidth_us(Servo_high_FORWARD_L);
taknokolat 30:90252dc48c1a 252 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 253 NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 27:f67efcee6509 254 g_fp = fopen( "/sd/Datalog01.txt","a" );
HARUKIDELTA 27:f67efcee6509 255 fprintf(g_fp, "Time = %d min %d sec : Cansat move left high speed.\r\n",(int)t2.read()/60,(int)t2.read()%60);
HARUKIDELTA 27:f67efcee6509 256 fclose(g_fp);
HARUKIDELTA 0:84ddd6d354e1 257 break;
taknokolat 1:290e621741fd 258
taknokolat 1:290e621741fd 259 case 'G': //GOAL_FORWARD
HARUKIDELTA 17:83db05cab3d1 260 servoR.pulsewidth_us(Servo_slow_FORWARD_R);
HARUKIDELTA 17:83db05cab3d1 261 servoL.pulsewidth_us(Servo_slow_FORWARD_L);
taknokolat 30:90252dc48c1a 262 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 263 NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 27:f67efcee6509 264 g_fp = fopen( "/sd/Datalog01.txt","a" );
HARUKIDELTA 27:f67efcee6509 265 fprintf(g_fp, "Time = %d min %d sec : Cansat move goal forward mode.\r\n",(int)t2.read()/60,(int)t2.read()%60);
HARUKIDELTA 27:f67efcee6509 266 fclose(g_fp);
taknokolat 7:8989a4b84695 267 break;
taknokolat 12:083662bca47d 268
taknokolat 12:083662bca47d 269 case '1': //MOVE_FORWARD Speed Level 1
HARUKIDELTA 17:83db05cab3d1 270 servoR.pulsewidth_us(Servo_high_FORWARD_R);
HARUKIDELTA 17:83db05cab3d1 271 servoL.pulsewidth_us(Servo_high_FORWARD_L);
taknokolat 12:083662bca47d 272 wait(1);
taknokolat 12:083662bca47d 273 do{
taknokolat 22:a19be3b505b7 274 SensingMPU();
taknokolat 22:a19be3b505b7 275 wait_ms(30);
taknokolat 22:a19be3b505b7 276 }while((nowAngle[PITCH]>20||nowAngle[PITCH]<-20)&&(nowAngle[ROLL]>20||nowAngle[ROLL]<-20));
taknokolat 30:90252dc48c1a 277 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 278 NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 27:f67efcee6509 279 g_fp = fopen( "/sd/Datalog01.txt","a" );
HARUKIDELTA 27:f67efcee6509 280 fprintf(g_fp, "Time = %d min %d sec : Cansat move forward 1sec!.\r\n",(int)t2.read()/60,(int)t2.read()%60);
HARUKIDELTA 27:f67efcee6509 281 fclose(g_fp);
taknokolat 12:083662bca47d 282 break;
taknokolat 12:083662bca47d 283
taknokolat 12:083662bca47d 284 case '2': //MOVE_FORWARD Speed Level 2
HARUKIDELTA 17:83db05cab3d1 285 servoR.pulsewidth_us(Servo_high_FORWARD_R);
HARUKIDELTA 17:83db05cab3d1 286 servoL.pulsewidth_us(Servo_high_FORWARD_L);
taknokolat 12:083662bca47d 287 wait(2);
taknokolat 12:083662bca47d 288 do{
taknokolat 22:a19be3b505b7 289 SensingMPU();
taknokolat 22:a19be3b505b7 290 wait_ms(30);
taknokolat 22:a19be3b505b7 291 }while((nowAngle[PITCH]>20||nowAngle[PITCH]<-20)&&(nowAngle[ROLL]>20||nowAngle[ROLL]<-20));
taknokolat 30:90252dc48c1a 292 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 293 NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 27:f67efcee6509 294 g_fp = fopen( "/sd/Datalog01.txt","a" );
HARUKIDELTA 27:f67efcee6509 295 fprintf(g_fp, "Time = %d min %d sec : Cansat move forward 2sec!.\r\n",(int)t2.read()/60,(int)t2.read()%60);
HARUKIDELTA 27:f67efcee6509 296 fclose(g_fp);
taknokolat 12:083662bca47d 297 break;
taknokolat 12:083662bca47d 298
taknokolat 12:083662bca47d 299 case '3': //MOVE_FORWARD Speed Level 3
HARUKIDELTA 17:83db05cab3d1 300 servoR.pulsewidth_us(Servo_high_FORWARD_R);
HARUKIDELTA 17:83db05cab3d1 301 servoL.pulsewidth_us(Servo_high_FORWARD_L);
taknokolat 12:083662bca47d 302 wait(3);
taknokolat 12:083662bca47d 303 do{
taknokolat 22:a19be3b505b7 304 SensingMPU();
taknokolat 22:a19be3b505b7 305 wait_ms(30);
taknokolat 22:a19be3b505b7 306 }while((nowAngle[PITCH]>20||nowAngle[PITCH]<-20)&&(nowAngle[ROLL]>20||nowAngle[ROLL]<-20));
taknokolat 30:90252dc48c1a 307 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 308 NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 27:f67efcee6509 309 g_fp = fopen( "/sd/Datalog01.txt","a" );
HARUKIDELTA 27:f67efcee6509 310 fprintf(g_fp, "Time = %d min %d sec : Cansat move forward 3sec!.\r\n",(int)t2.read()/60,(int)t2.read()%60);
HARUKIDELTA 27:f67efcee6509 311 fclose(g_fp);
taknokolat 12:083662bca47d 312 break;
taknokolat 12:083662bca47d 313
taknokolat 12:083662bca47d 314 case '4': //MOVE_FORWARD Speed Level 4
HARUKIDELTA 17:83db05cab3d1 315 servoR.pulsewidth_us(Servo_high_FORWARD_R);
HARUKIDELTA 17:83db05cab3d1 316 servoL.pulsewidth_us(Servo_high_FORWARD_L);
taknokolat 12:083662bca47d 317 wait(4);
taknokolat 12:083662bca47d 318 do{
taknokolat 22:a19be3b505b7 319 SensingMPU();
taknokolat 22:a19be3b505b7 320 wait_ms(30);
taknokolat 22:a19be3b505b7 321 }while((nowAngle[PITCH]>20||nowAngle[PITCH]<-20)||(nowAngle[ROLL]>20||nowAngle[ROLL]<-20));
taknokolat 30:90252dc48c1a 322 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 323 NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 27:f67efcee6509 324 g_fp = fopen( "/sd/Datalog01.txt","a" );
HARUKIDELTA 27:f67efcee6509 325 fprintf(g_fp, "Time = %d min %d sec : Cansat move forward 4sec!.\r\n",(int)t2.read()/60,(int)t2.read()%60);
HARUKIDELTA 27:f67efcee6509 326 fclose(g_fp);
taknokolat 12:083662bca47d 327 break;
taknokolat 7:8989a4b84695 328
taknokolat 12:083662bca47d 329 case '5': //MOVE_FORWARD Speed Level 5
HARUKIDELTA 17:83db05cab3d1 330 servoR.pulsewidth_us(Servo_high_FORWARD_R);
HARUKIDELTA 17:83db05cab3d1 331 servoL.pulsewidth_us(Servo_high_FORWARD_L);
taknokolat 7:8989a4b84695 332 wait(5);
taknokolat 10:63fe920595a7 333 do{
taknokolat 22:a19be3b505b7 334 SensingMPU();
taknokolat 22:a19be3b505b7 335 wait_ms(30);
taknokolat 22:a19be3b505b7 336 }while((nowAngle[PITCH]>20||nowAngle[PITCH]<-20)&&(nowAngle[ROLL]>20||nowAngle[ROLL]<-20));
taknokolat 30:90252dc48c1a 337 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 338 NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 27:f67efcee6509 339 g_fp = fopen( "/sd/Datalog01.txt","a" );
HARUKIDELTA 27:f67efcee6509 340 fprintf(g_fp, "Time = %d min %d sec : Cansat move forward 5sec!.\r\n",(int)t2.read()/60,(int)t2.read()%60);
HARUKIDELTA 27:f67efcee6509 341 fclose(g_fp);
taknokolat 7:8989a4b84695 342 break;
taknokolat 7:8989a4b84695 343
taknokolat 7:8989a4b84695 344 case 'M': //MatchPosition
HARUKIDELTA 17:83db05cab3d1 345 servoR.pulsewidth_us(Matchspeed);
taknokolat 30:90252dc48c1a 346 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 347 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 7:8989a4b84695 348 break;
taknokolat 7:8989a4b84695 349
taknokolat 12:083662bca47d 350 case 'P': //jevoisからraspberry piへの切り替え
taknokolat 7:8989a4b84695 351 jevoisFlag = false;
taknokolat 28:887df143fa9c 352 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL + Turntable_speed);
taknokolat 28:887df143fa9c 353 wait_ms((float)Time360/(float)2);
taknokolat 28:887df143fa9c 354 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL);
taknokolat 30:90252dc48c1a 355 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 356 NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 0:84ddd6d354e1 357 break;
taknokolat 12:083662bca47d 358
taknokolat 28:887df143fa9c 359 case 'B':
taknokolat 12:083662bca47d 360 /*RasPiからの超音波判定(プログラムスタート部)*/
taknokolat 30:90252dc48c1a 361 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 362 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 12:083662bca47d 363 break;
taknokolat 1:290e621741fd 364
taknokolat 1:290e621741fd 365 default :
taknokolat 30:90252dc48c1a 366 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 367 NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 0:84ddd6d354e1 368 break;
taknokolat 1:290e621741fd 369
HARUKIDELTA 0:84ddd6d354e1 370 }
taknokolat 7:8989a4b84695 371
HARUKIDELTA 0:84ddd6d354e1 372 return;
taknokolat 1:290e621741fd 373 }
taknokolat 1:290e621741fd 374
taknokolat 7:8989a4b84695 375 void MoveCameraBoard(){
taknokolat 22:a19be3b505b7 376 //pc.printf("start\r\n");
taknokolat 7:8989a4b84695 377 MoveCansat('N');
taknokolat 22:a19be3b505b7 378 //pc.printf("ok\r\n");
taknokolat 10:63fe920595a7 379 g_landingcommand='N';
taknokolat 29:5d239812ace6 380 servoCameradeg.pulsewidth_us(Camera_deg_B);
taknokolat 29:5d239812ace6 381 wait_ms(30);
taknokolat 32:ab030832d180 382 if(g_CameraDegCounter==0){
taknokolat 32:ab030832d180 383 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL + Turntable_speed);
taknokolat 32:ab030832d180 384 wait_ms(Camera_board_wait*ReturnCount);
taknokolat 32:ab030832d180 385 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL);
taknokolat 32:ab030832d180 386
taknokolat 32:ab030832d180 387
taknokolat 32:ab030832d180 388 for(int i=200; i<Camera_deg_B-Camera_deg_A;i=i+200){
taknokolat 32:ab030832d180 389
taknokolat 32:ab030832d180 390 servoCameradeg.pulsewidth_us(Camera_deg_B-i);
taknokolat 32:ab030832d180 391 servoR.pulsewidth_us(Servo_NEUTRAL_R); //servo initialize
taknokolat 32:ab030832d180 392 servoL.pulsewidth_us(Servo_NEUTRAL_L);
taknokolat 32:ab030832d180 393 wait_ms(30);
taknokolat 32:ab030832d180 394 //pc.printf("zoom2\r\n");
taknokolat 32:ab030832d180 395 if(jevoisFlag == true) FocusAdjust();
taknokolat 32:ab030832d180 396 else wait(1);
taknokolat 32:ab030832d180 397 if(g_landingcommand!='N') return;
taknokolat 32:ab030832d180 398
taknokolat 32:ab030832d180 399 }
taknokolat 32:ab030832d180 400
taknokolat 32:ab030832d180 401 }
taknokolat 32:ab030832d180 402
taknokolat 24:0ad1725c7849 403 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL - Turntable_speed);
taknokolat 20:011977a37394 404 wait_ms(Camera_board_wait);
taknokolat 24:0ad1725c7849 405 g_CameraDegCounter++;
HARUKIDELTA 17:83db05cab3d1 406 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL);
taknokolat 22:a19be3b505b7 407 //pc.printf("zoom1\r\n");
taknokolat 7:8989a4b84695 408 if(jevoisFlag == true) FocusAdjust();
taknokolat 7:8989a4b84695 409 else wait(1);
taknokolat 32:ab030832d180 410
taknokolat 32:ab030832d180 411
taknokolat 7:8989a4b84695 412 if(g_landingcommand!='N') return;
taknokolat 29:5d239812ace6 413
taknokolat 29:5d239812ace6 414 for(int i=200; i<Camera_deg_B-Camera_deg_A;i=i+200){
taknokolat 29:5d239812ace6 415
taknokolat 32:ab030832d180 416 servoCameradeg.pulsewidth_us(Camera_deg_B-i);
taknokolat 32:ab030832d180 417 servoR.pulsewidth_us(Servo_NEUTRAL_R); //servo initialize
taknokolat 32:ab030832d180 418 servoL.pulsewidth_us(Servo_NEUTRAL_L);
taknokolat 32:ab030832d180 419 wait_ms(30);
taknokolat 29:5d239812ace6 420 //pc.printf("zoom2\r\n");
taknokolat 29:5d239812ace6 421 if(jevoisFlag == true) FocusAdjust();
taknokolat 29:5d239812ace6 422 else wait(1);
taknokolat 29:5d239812ace6 423 if(g_landingcommand!='N') return;
taknokolat 29:5d239812ace6 424
taknokolat 7:8989a4b84695 425 }
taknokolat 7:8989a4b84695 426
taknokolat 20:011977a37394 427
taknokolat 32:ab030832d180 428 pc.printf("g_CameraDegCounter = %d\r\n",g_CameraDegCounter);
taknokolat 22:a19be3b505b7 429 //pc.printf("Move Board Finish\r\n");
taknokolat 7:8989a4b84695 430 return;
taknokolat 7:8989a4b84695 431 }
taknokolat 7:8989a4b84695 432
taknokolat 7:8989a4b84695 433 void MatchPosition(){
taknokolat 32:ab030832d180 434 NVIC_DisableIRQ(USART6_IRQn);
taknokolat 32:ab030832d180 435 NVIC_DisableIRQ(USART2_IRQn);
taknokolat 22:a19be3b505b7 436 pc.printf("MatchPosition\r\n");
taknokolat 24:0ad1725c7849 437
taknokolat 32:ab030832d180 438 int TurnTime ;
taknokolat 32:ab030832d180 439
taknokolat 32:ab030832d180 440 TurnTime = g_CameraDegCounter - ReturnCount;
taknokolat 32:ab030832d180 441
taknokolat 32:ab030832d180 442 if(TurnTime >=0){
taknokolat 32:ab030832d180 443 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL + Turntable_speed);
taknokolat 32:ab030832d180 444 wait_ms(Camera_board_wait*TurnTime);
taknokolat 32:ab030832d180 445 }else{
taknokolat 32:ab030832d180 446 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL - Turntable_speed);
taknokolat 32:ab030832d180 447 wait_ms(-Camera_board_wait*TurnTime);
taknokolat 32:ab030832d180 448 }
taknokolat 24:0ad1725c7849 449 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL);
taknokolat 24:0ad1725c7849 450
taknokolat 22:a19be3b505b7 451 int SetLoop=0;
taknokolat 22:a19be3b505b7 452
taknokolat 22:a19be3b505b7 453 while(SetLoop<30){
taknokolat 7:8989a4b84695 454 SensingMPU();
taknokolat 22:a19be3b505b7 455 wait_ms(20);
taknokolat 24:0ad1725c7849 456 //SensingHMC();
taknokolat 24:0ad1725c7849 457 //wait_ms(20);
taknokolat 22:a19be3b505b7 458 //DebugPrint();
taknokolat 22:a19be3b505b7 459 SetLoop++;
taknokolat 22:a19be3b505b7 460 //pc.printf("nowAngle_HMC=%f\tMPU=%f\r\n",nowAngle_HMC,nowAngle[YAW]);
taknokolat 22:a19be3b505b7 461
taknokolat 22:a19be3b505b7 462 }
taknokolat 7:8989a4b84695 463
taknokolat 24:0ad1725c7849 464 static float TargetDeg = 0;
taknokolat 24:0ad1725c7849 465
taknokolat 32:ab030832d180 466 TargetDeg = 360*(float)Camera_board_wait*((float)g_CameraDegCounter - ReturnCount)/(float)Time360;
taknokolat 24:0ad1725c7849 467
taknokolat 24:0ad1725c7849 468 float HighTargetYaw = TargetDeg + Match_wid;
taknokolat 24:0ad1725c7849 469 float LowTargetYaw = TargetDeg - Match_wid;
taknokolat 21:ca8f35e24e66 470
taknokolat 22:a19be3b505b7 471
taknokolat 21:ca8f35e24e66 472 if(HighTargetYaw >= 360.0) HighTargetYaw = HighTargetYaw - 360.0;
taknokolat 22:a19be3b505b7 473
taknokolat 21:ca8f35e24e66 474 if(LowTargetYaw < 0) LowTargetYaw = LowTargetYaw + 360.0;
taknokolat 21:ca8f35e24e66 475
taknokolat 22:a19be3b505b7 476 pc.printf("\r\nnow=%f\t,high=%f\t,low=%f\r\n",nowAngle[YAW],HighTargetYaw,LowTargetYaw);
taknokolat 22:a19be3b505b7 477
taknokolat 24:0ad1725c7849 478 MoveCansat('r');
taknokolat 22:a19be3b505b7 479
taknokolat 22:a19be3b505b7 480 if(HighTargetYaw-LowTargetYaw<0){
taknokolat 22:a19be3b505b7 481 while(nowAngle[YAW] > HighTargetYaw && nowAngle[YAW] < LowTargetYaw){
taknokolat 22:a19be3b505b7 482 //MoveCansat('r');
taknokolat 22:a19be3b505b7 483 SensingMPU();
taknokolat 22:a19be3b505b7 484 wait_ms(30);
taknokolat 22:a19be3b505b7 485 pc.printf("nowAngle_MPU=%f\r\n",nowAngle[YAW]);
taknokolat 22:a19be3b505b7 486 }
taknokolat 22:a19be3b505b7 487 }else{
taknokolat 22:a19be3b505b7 488 while(nowAngle[YAW] > HighTargetYaw || nowAngle[YAW] < LowTargetYaw){
taknokolat 22:a19be3b505b7 489 //MoveCansat('r');
taknokolat 22:a19be3b505b7 490 SensingMPU();
taknokolat 22:a19be3b505b7 491 wait_ms(30);
taknokolat 22:a19be3b505b7 492 pc.printf("nowAngle_MPU=%f\r\n",nowAngle[YAW]);
taknokolat 22:a19be3b505b7 493 }
taknokolat 7:8989a4b84695 494 }
taknokolat 24:0ad1725c7849 495 g_CameraDegCounter = 0;
taknokolat 32:ab030832d180 496
taknokolat 32:ab030832d180 497 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 32:ab030832d180 498 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 7:8989a4b84695 499 return;
taknokolat 7:8989a4b84695 500 }
taknokolat 7:8989a4b84695 501
taknokolat 7:8989a4b84695 502 void FocusAdjust(){
taknokolat 31:210cc32d3175 503 if(FocusFlag == false){
taknokolat 31:210cc32d3175 504 servoCameraPinto.pulsewidth_us(Focus_NEUTRAL + 200);
taknokolat 31:210cc32d3175 505 wait(1);
taknokolat 31:210cc32d3175 506 FocusFlag = !FocusFlag;
taknokolat 31:210cc32d3175 507 }else{
taknokolat 31:210cc32d3175 508 servoCameraPinto.pulsewidth_us(Focus_NEUTRAL - 200);
taknokolat 31:210cc32d3175 509 wait(1);
taknokolat 31:210cc32d3175 510 FocusFlag = !FocusFlag;
taknokolat 31:210cc32d3175 511 }
HARUKIDELTA 17:83db05cab3d1 512 servoCameraPinto.pulsewidth_us(Focus_NEUTRAL);
taknokolat 11:d44d137831b9 513
taknokolat 7:8989a4b84695 514 return;
taknokolat 15:1519fccfcae3 515 }
taknokolat 7:8989a4b84695 516
taknokolat 1:290e621741fd 517 void getSF_Serial_jevois(){
taknokolat 22:a19be3b505b7 518
taknokolat 22:a19be3b505b7 519 //pc.printf("jevois\r\n");
taknokolat 1:290e621741fd 520
taknokolat 1:290e621741fd 521
taknokolat 1:290e621741fd 522 static char SFbuf[16]={'Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q'};
taknokolat 1:290e621741fd 523
taknokolat 1:290e621741fd 524 static int bufcounter=0;
taknokolat 1:290e621741fd 525
taknokolat 1:290e621741fd 526
taknokolat 1:290e621741fd 527
taknokolat 1:290e621741fd 528 if(pc.readable()) { // 受信確認
taknokolat 1:290e621741fd 529
taknokolat 1:290e621741fd 530 SFbuf[bufcounter] = pc.getc(); // 1文字取り出し
taknokolat 1:290e621741fd 531 if(SFbuf[0]!='S'){
taknokolat 1:290e621741fd 532 //pc.printf("x");
taknokolat 1:290e621741fd 533 return;
taknokolat 1:290e621741fd 534 }
taknokolat 1:290e621741fd 535
taknokolat 1:290e621741fd 536
taknokolat 1:290e621741fd 537
taknokolat 22:a19be3b505b7 538 pc.printf("%c",SFbuf[bufcounter]);
taknokolat 1:290e621741fd 539
Skykon 3:c18342e4fddd 540 if(SFbuf[0]=='S' && bufcounter<5)bufcounter++;
taknokolat 1:290e621741fd 541
taknokolat 1:290e621741fd 542 if(bufcounter==5 && SFbuf[4]=='F'){
taknokolat 1:290e621741fd 543
taknokolat 1:290e621741fd 544 g_landingcommand = SFbuf[1];
taknokolat 2:f30666d7838b 545 wait_ms(31);//信号が速すぎることによる割り込み防止
taknokolat 1:290e621741fd 546 //pc.printf("%c",g_landingcommand);
taknokolat 1:290e621741fd 547 //wait_ms(20);
taknokolat 1:290e621741fd 548 //if(g_landingcommand=='Y')g_SerialTargetYAW = ConvertByteintoFloat(SFbuf[2], SFbuf[3]);
taknokolat 1:290e621741fd 549 bufcounter = 0;
taknokolat 1:290e621741fd 550 memset(SFbuf, 0, sizeof(SFbuf));
taknokolat 1:290e621741fd 551 NVIC_ClearPendingIRQ(USART2_IRQn);
taknokolat 1:290e621741fd 552 //pc.printf("command = %c, commandYAW = %f\r\n", g_landingcommand, g_SerialTargetYAW);
taknokolat 1:290e621741fd 553 }
taknokolat 1:290e621741fd 554
taknokolat 1:290e621741fd 555 else if(bufcounter>=5){
taknokolat 1:290e621741fd 556 //pc.printf("Communication Falsed.\r\n");
taknokolat 1:290e621741fd 557 memset(SFbuf, 0, sizeof(SFbuf));
taknokolat 1:290e621741fd 558 bufcounter = 0;
taknokolat 1:290e621741fd 559 NVIC_ClearPendingIRQ(USART2_IRQn);
taknokolat 1:290e621741fd 560 }
taknokolat 1:290e621741fd 561 }
taknokolat 1:290e621741fd 562
taknokolat 1:290e621741fd 563
taknokolat 1:290e621741fd 564 }
taknokolat 1:290e621741fd 565
taknokolat 1:290e621741fd 566
taknokolat 12:083662bca47d 567 void getSF_Serial_pi(){
taknokolat 2:f30666d7838b 568
taknokolat 7:8989a4b84695 569 //NVIC_DisableIRQ(USART2_IRQn);
taknokolat 1:290e621741fd 570
taknokolat 1:290e621741fd 571 static char SFbuf[16]={'Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q'};
taknokolat 1:290e621741fd 572
taknokolat 1:290e621741fd 573 static int bufcounter=0;
taknokolat 1:290e621741fd 574
taknokolat 1:290e621741fd 575
taknokolat 1:290e621741fd 576
taknokolat 1:290e621741fd 577 if(pc2.readable()) { // 受信確認
taknokolat 1:290e621741fd 578
taknokolat 1:290e621741fd 579 SFbuf[bufcounter] = pc2.getc(); // 1文字取り出し
taknokolat 1:290e621741fd 580 if(SFbuf[0]!='S'){
taknokolat 1:290e621741fd 581 //pc.printf("x");
taknokolat 1:290e621741fd 582 return;
taknokolat 1:290e621741fd 583 }
taknokolat 1:290e621741fd 584
taknokolat 1:290e621741fd 585
taknokolat 1:290e621741fd 586
taknokolat 30:90252dc48c1a 587 pc.printf("%c",SFbuf[bufcounter]);
taknokolat 1:290e621741fd 588
taknokolat 1:290e621741fd 589 if(SFbuf[0]=='S'&&bufcounter<5)bufcounter++;
taknokolat 1:290e621741fd 590
taknokolat 1:290e621741fd 591 if(bufcounter==5 && SFbuf[4]=='F'){
taknokolat 1:290e621741fd 592
taknokolat 1:290e621741fd 593 g_landingcommand = SFbuf[1];
taknokolat 2:f30666d7838b 594 wait_ms(31);//信号が速すぎることによる割り込み防止
taknokolat 1:290e621741fd 595 //pc.printf("%c",g_landingcommand);
taknokolat 1:290e621741fd 596 //wait_ms(20);
taknokolat 1:290e621741fd 597 //if(g_landingcommand=='Y')g_SerialTargetYAW = ConvertByteintoFloat(SFbuf[2], SFbuf[3]);
taknokolat 1:290e621741fd 598 bufcounter = 0;
taknokolat 1:290e621741fd 599 memset(SFbuf, 0, sizeof(SFbuf));
taknokolat 1:290e621741fd 600 NVIC_ClearPendingIRQ(USART2_IRQn);
taknokolat 1:290e621741fd 601 //pc.printf("command = %c, commandYAW = %f\r\n", g_landingcommand, g_SerialTargetYAW);
taknokolat 1:290e621741fd 602 }
taknokolat 1:290e621741fd 603
taknokolat 1:290e621741fd 604 else if(bufcounter>=5){
taknokolat 1:290e621741fd 605 //pc.printf("Communication Falsed.\r\n");
taknokolat 1:290e621741fd 606 memset(SFbuf, 0, sizeof(SFbuf));
taknokolat 1:290e621741fd 607 bufcounter = 0;
taknokolat 1:290e621741fd 608 NVIC_ClearPendingIRQ(USART2_IRQn);
taknokolat 1:290e621741fd 609 }
taknokolat 1:290e621741fd 610 }
taknokolat 2:f30666d7838b 611
taknokolat 7:8989a4b84695 612 //NVIC_EnableIRQ(USART2_IRQn);
taknokolat 1:290e621741fd 613
taknokolat 12:083662bca47d 614 }
taknokolat 1:290e621741fd 615
Skykon 3:c18342e4fddd 616
Skykon 3:c18342e4fddd 617 void setup(){
HARUKIDELTA 23:29b2722bd753 618
HARUKIDELTA 23:29b2722bd753 619 led1 = 1;
HARUKIDELTA 23:29b2722bd753 620 led2 = 1;
HARUKIDELTA 23:29b2722bd753 621 led3 = 1;
HARUKIDELTA 23:29b2722bd753 622 led4 = 1;
HARUKIDELTA 26:ea86e69563b5 623
HARUKIDELTA 26:ea86e69563b5 624 servoR.pulsewidth_us(Servo_NEUTRAL_R); //servo initialize
HARUKIDELTA 26:ea86e69563b5 625 servoL.pulsewidth_us(Servo_NEUTRAL_L);
HARUKIDELTA 26:ea86e69563b5 626 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL);
taknokolat 29:5d239812ace6 627 servoCameradeg.pulsewidth_us(Camera_deg_B);
HARUKIDELTA 26:ea86e69563b5 628 servoCameraPinto.pulsewidth_us(focus_NEUTRAL);
Skykon 3:c18342e4fddd 629
taknokolat 13:b088f0db7158 630 SetOptions(&Servo_NEUTRAL_R, &Servo_NEUTRAL_L,
taknokolat 12:083662bca47d 631 &Servo_high_FORWARD_R, &Servo_high_FORWARD_L,
taknokolat 12:083662bca47d 632 &Servo_slow_FORWARD_R,&Servo_slow_FORWARD_L,
taknokolat 12:083662bca47d 633 &Turntable_NEUTRAL,&Matchspeed,&Focus_NEUTRAL,
taknokolat 16:26cee2aaf61d 634 &Camera_deg_A, &Camera_deg_B,
HARUKIDELTA 17:83db05cab3d1 635 &Pint_speed,&Pint_wait,
taknokolat 19:949bab1e9451 636 &Turntable_speed,
taknokolat 24:0ad1725c7849 637 &Time360, &Match_wid,
taknokolat 20:011977a37394 638 &Camera_board_wait
taknokolat 13:b088f0db7158 639 );
taknokolat 12:083662bca47d 640
Skykon 3:c18342e4fddd 641 Init_sensors();
Skykon 3:c18342e4fddd 642 //switch2.rise(ResetTrim);
Skykon 3:c18342e4fddd 643
taknokolat 30:90252dc48c1a 644 //NVIC_SetPriority(USART6_IRQn,0);
taknokolat 7:8989a4b84695 645 //NVIC_SetPriority(EXTI0_IRQn,1);
taknokolat 7:8989a4b84695 646 //NVIC_SetPriority(TIM5_IRQn,2);
taknokolat 7:8989a4b84695 647 //NVIC_SetPriority(EXTI9_5_IRQn,3);
taknokolat 7:8989a4b84695 648 //NVIC_SetPriority(USART2_IRQn,4);
taknokolat 7:8989a4b84695 649
taknokolat 30:90252dc48c1a 650 NVIC_SetPriority(USART6_IRQn,0);//割り込み優先度
taknokolat 7:8989a4b84695 651 NVIC_SetPriority(USART2_IRQn,1);
taknokolat 7:8989a4b84695 652
Skykon 3:c18342e4fddd 653 DisplayClock();
Skykon 3:c18342e4fddd 654 t.start();
Skykon 3:c18342e4fddd 655
Skykon 3:c18342e4fddd 656 pc.printf("MPU calibration start\r\n");
taknokolat 24:0ad1725c7849 657 //pc.printf("HMC calibration start\r\n");
Skykon 3:c18342e4fddd 658
Skykon 3:c18342e4fddd 659 float offsetstart = t.read();
Skykon 3:c18342e4fddd 660 while(t.read() - offsetstart < 26){
Skykon 3:c18342e4fddd 661 SensingMPU();
taknokolat 24:0ad1725c7849 662 //SensingHMC();
Skykon 3:c18342e4fddd 663 for(uint8_t i=0; i<3; i++) pc.printf("%3.2f\t",nowAngle[i]);
taknokolat 24:0ad1725c7849 664 //pc.printf("\t%3.2f\t",nowAngle_HMC);
Skykon 3:c18342e4fddd 665 pc.printf("\r\n");
HARUKIDELTA 23:29b2722bd753 666 led1 = !led1;
HARUKIDELTA 23:29b2722bd753 667 led2 = !led2;
HARUKIDELTA 23:29b2722bd753 668 led3 = !led3;
HARUKIDELTA 23:29b2722bd753 669 led4 = !led4;
Skykon 3:c18342e4fddd 670 }
Skykon 3:c18342e4fddd 671
Skykon 3:c18342e4fddd 672 FirstROLL = nowAngle[ROLL];
Skykon 3:c18342e4fddd 673 FirstPITCH = nowAngle[PITCH];
Skykon 3:c18342e4fddd 674 nowAngle[ROLL] -=FirstROLL;
Skykon 3:c18342e4fddd 675 nowAngle[PITCH] -=FirstPITCH;
taknokolat 6:166746820555 676 FirstYAW = nowAngle[YAW];
taknokolat 6:166746820555 677 nowAngle[YAW] -= FirstYAW;
taknokolat 6:166746820555 678
taknokolat 24:0ad1725c7849 679 //g_FirstYAW_HMC = nowAngle_HMC;
taknokolat 24:0ad1725c7849 680 //nowAngle_HMC -=g_FirstYAW_HMC;
taknokolat 24:0ad1725c7849 681 //if(nowAngle_HMC<0)nowAngle_HMC+=360;
Skykon 3:c18342e4fddd 682
HARUKIDELTA 23:29b2722bd753 683 led1 = 0;
HARUKIDELTA 23:29b2722bd753 684 led2 = 0;
HARUKIDELTA 23:29b2722bd753 685 led3 = 0;
HARUKIDELTA 23:29b2722bd753 686 led4 = 0;
HARUKIDELTA 23:29b2722bd753 687
Skykon 3:c18342e4fddd 688 wait(0.2);
Skykon 3:c18342e4fddd 689
HARUKIDELTA 26:ea86e69563b5 690
HARUKIDELTA 26:ea86e69563b5 691 g_fp = fopen( "/sd/Datalog01.txt" ,"a" );
HARUKIDELTA 26:ea86e69563b5 692 if( g_fp == NULL ) {
HARUKIDELTA 26:ea86e69563b5 693 pc.printf( "ファイルオープンエラー\r\n" );
HARUKIDELTA 26:ea86e69563b5 694 }
HARUKIDELTA 27:f67efcee6509 695 fprintf(g_fp,"\r\n-------------------------\r\n");
HARUKIDELTA 26:ea86e69563b5 696 fprintf(g_fp,"All initialized.\r\n");
HARUKIDELTA 26:ea86e69563b5 697 fclose( g_fp );
HARUKIDELTA 26:ea86e69563b5 698
HARUKIDELTA 26:ea86e69563b5 699
Skykon 3:c18342e4fddd 700 pc.printf("All initialized\r\n");
taknokolat 4:67f705d42f1e 701 setupFlag=true;
taknokolat 1:290e621741fd 702 }
taknokolat 1:290e621741fd 703
Skykon 3:c18342e4fddd 704
Skykon 3:c18342e4fddd 705 void SensingMPU(){
Skykon 3:c18342e4fddd 706 //static int16_t deltaT = 0, t_start = 0;
Skykon 3:c18342e4fddd 707 //t_start = t.read_us();
Skykon 3:c18342e4fddd 708
taknokolat 7:8989a4b84695 709 float rpy[3] = {0};
Skykon 3:c18342e4fddd 710 static uint16_t count_changeRPY = 0;
Skykon 3:c18342e4fddd 711 static bool flg_checkoutlier = false;
taknokolat 30:90252dc48c1a 712 NVIC_DisableIRQ(USART6_IRQn);
Skykon 3:c18342e4fddd 713 NVIC_DisableIRQ(USART2_IRQn);
Skykon 3:c18342e4fddd 714 NVIC_DisableIRQ(TIM5_IRQn);
Skykon 3:c18342e4fddd 715 NVIC_DisableIRQ(EXTI0_IRQn);
Skykon 3:c18342e4fddd 716 NVIC_DisableIRQ(EXTI9_5_IRQn);
Skykon 3:c18342e4fddd 717
Skykon 3:c18342e4fddd 718 mpu6050.getRollPitchYaw_Skipper(rpy);
Skykon 3:c18342e4fddd 719
taknokolat 30:90252dc48c1a 720 NVIC_EnableIRQ(USART6_IRQn);
Skykon 3:c18342e4fddd 721 NVIC_EnableIRQ(USART2_IRQn);
Skykon 3:c18342e4fddd 722 NVIC_EnableIRQ(TIM5_IRQn);
Skykon 3:c18342e4fddd 723 NVIC_EnableIRQ(EXTI0_IRQn);
Skykon 3:c18342e4fddd 724 NVIC_EnableIRQ(EXTI9_5_IRQn);
Skykon 3:c18342e4fddd 725
Skykon 3:c18342e4fddd 726
Skykon 3:c18342e4fddd 727 //外れ値対策
Skykon 3:c18342e4fddd 728 for(uint8_t i=0; i<3; i++) rpy[i] *= 180.0f/PI;
Skykon 3:c18342e4fddd 729 rpy[ROLL] -= FirstROLL;
Skykon 3:c18342e4fddd 730 rpy[PITCH] -= FirstPITCH;
taknokolat 4:67f705d42f1e 731 if(!setupFlag){
taknokolat 4:67f705d42f1e 732 rpy[YAW] -= FirstYAW;
taknokolat 4:67f705d42f1e 733 }else{
taknokolat 4:67f705d42f1e 734 if(rpy[YAW] >= FirstYAW){
taknokolat 4:67f705d42f1e 735 rpy[YAW] -= FirstYAW;
taknokolat 4:67f705d42f1e 736 }else{
taknokolat 4:67f705d42f1e 737 rpy[YAW] += 360.0f;
taknokolat 4:67f705d42f1e 738 rpy[YAW] -= FirstYAW;
taknokolat 4:67f705d42f1e 739 }
taknokolat 4:67f705d42f1e 740 }
Skykon 3:c18342e4fddd 741
Skykon 3:c18342e4fddd 742 for(uint8_t i=0; i<3; i++) {if(rpy[i] < nowAngle[i]-10 || rpy[i] > nowAngle[i]+10) {flg_checkoutlier = true;}}
Skykon 3:c18342e4fddd 743 if(!flg_checkoutlier || count_changeRPY >= 2){
Skykon 3:c18342e4fddd 744 for(uint8_t i=0; i<3; i++){
Skykon 3:c18342e4fddd 745 nowAngle[i] = (rpy[i] + nowAngle[i])/2.0f; //2つの移動平均
Skykon 3:c18342e4fddd 746 }
Skykon 3:c18342e4fddd 747 count_changeRPY = 0;
Skykon 3:c18342e4fddd 748 }else count_changeRPY++;
Skykon 3:c18342e4fddd 749 flg_checkoutlier = false;
Skykon 3:c18342e4fddd 750
Skykon 3:c18342e4fddd 751 }
Skykon 3:c18342e4fddd 752
Skykon 3:c18342e4fddd 753
Skykon 3:c18342e4fddd 754 void Init_sensors(){
Skykon 3:c18342e4fddd 755 if(mpu6050.setup() == -1){
Skykon 3:c18342e4fddd 756 pc.printf("failed initialize\r\n");
Skykon 3:c18342e4fddd 757 }
Skykon 3:c18342e4fddd 758 }
Skykon 3:c18342e4fddd 759
Skykon 3:c18342e4fddd 760
Skykon 3:c18342e4fddd 761 void DisplayClock(){
Skykon 3:c18342e4fddd 762 pc.printf("System Clock = %d[MHz]\r\n", HAL_RCC_GetSysClockFreq()/1000000);
Skykon 3:c18342e4fddd 763 pc.printf("HCLK Clock = %d[MHz]\r\n", HAL_RCC_GetHCLKFreq()/1000000);
Skykon 3:c18342e4fddd 764 pc.printf("PCLK1 Clock = %d[MHz]\r\n", HAL_RCC_GetPCLK1Freq()/1000000);
Skykon 3:c18342e4fddd 765 pc.printf("PCLK2 Clock = %d[MHz]\r\n", HAL_RCC_GetPCLK2Freq()/1000000);
Skykon 3:c18342e4fddd 766 pc.printf("\r\n");
taknokolat 4:67f705d42f1e 767 }
taknokolat 6:166746820555 768
taknokolat 24:0ad1725c7849 769 /*void SensingHMC(){
taknokolat 6:166746820555 770 //static int16_t deltaT = 0, t_start = 0;
taknokolat 6:166746820555 771 //t_start = t.read_us();
taknokolat 6:166746820555 772
taknokolat 7:8989a4b84695 773 float rpy=0;
taknokolat 6:166746820555 774 static uint16_t count_changeRPY = 0;
taknokolat 6:166746820555 775 static bool flg_checkoutlier = false;
taknokolat 30:90252dc48c1a 776 NVIC_DisableIRQ(USART6_IRQn);
taknokolat 6:166746820555 777 NVIC_DisableIRQ(USART2_IRQn);
taknokolat 19:949bab1e9451 778 //NVIC_DisableIRQ(TIM5_IRQn);
taknokolat 19:949bab1e9451 779 //NVIC_DisableIRQ(EXTI0_IRQn);
taknokolat 19:949bab1e9451 780 //NVIC_DisableIRQ(EXTI9_5_IRQn);
taknokolat 4:67f705d42f1e 781
taknokolat 24:0ad1725c7849 782 rpy= compass.getHeadingXYDeg(Time360,Match_wid);
taknokolat 6:166746820555 783
taknokolat 30:90252dc48c1a 784 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 6:166746820555 785 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 19:949bab1e9451 786 //NVIC_EnableIRQ(TIM5_IRQn);
taknokolat 19:949bab1e9451 787 //NVIC_EnableIRQ(EXTI0_IRQn);
taknokolat 19:949bab1e9451 788 //NVIC_EnableIRQ(EXTI9_5_IRQn);
taknokolat 6:166746820555 789
taknokolat 6:166746820555 790
taknokolat 6:166746820555 791 //外れ値対策
taknokolat 6:166746820555 792 //rpy*= 180.0f/PI;
taknokolat 6:166746820555 793 if(!setupFlag){
taknokolat 6:166746820555 794 rpy -= g_FirstYAW_HMC;
taknokolat 6:166746820555 795 }else{
taknokolat 6:166746820555 796 if(rpy >= g_FirstYAW_HMC){
taknokolat 6:166746820555 797 rpy -= g_FirstYAW_HMC;
taknokolat 6:166746820555 798 }else{
taknokolat 6:166746820555 799 rpy += 360.0f;
taknokolat 6:166746820555 800 rpy -= g_FirstYAW_HMC;
taknokolat 6:166746820555 801 }
taknokolat 6:166746820555 802 }
taknokolat 6:166746820555 803
taknokolat 6:166746820555 804 if(rpy < nowAngle_HMC-10 || rpy > nowAngle_HMC+10) {flg_checkoutlier = true;}
taknokolat 6:166746820555 805 if(!flg_checkoutlier || count_changeRPY >= 2){
taknokolat 6:166746820555 806
taknokolat 6:166746820555 807 nowAngle_HMC = (rpy + nowAngle_HMC)/2.0f; //2つの移動平均
taknokolat 6:166746820555 808
taknokolat 6:166746820555 809 count_changeRPY = 0;
taknokolat 6:166746820555 810 }else count_changeRPY++;
taknokolat 6:166746820555 811 flg_checkoutlier = false;
taknokolat 6:166746820555 812
taknokolat 24:0ad1725c7849 813 }*/
taknokolat 12:083662bca47d 814
taknokolat 12:083662bca47d 815 int SetOptions(int *Servo_NEUTRAL_R, int *Servo_NEUTRAL_L,
taknokolat 12:083662bca47d 816 int *Servo_high_FORWARD_R, int *Servo_high_FORWARD_L,
taknokolat 12:083662bca47d 817 int *Servo_slow_FORWARD_R,int *Servo_slow_FORWARD_L,
taknokolat 12:083662bca47d 818 int *Turntable_NEUTRAL,int *Matchspeed,int *Focus_NEUTRAL,
taknokolat 16:26cee2aaf61d 819 int *Camera_deg_A, int *Camera_deg_B,
HARUKIDELTA 17:83db05cab3d1 820 int *Pint_speed, float *Pint_wait,
taknokolat 19:949bab1e9451 821 int *Turntable_speed,
taknokolat 24:0ad1725c7849 822 int *Time360, int *Match_wid,
taknokolat 20:011977a37394 823 int *Camera_board_wait
taknokolat 12:083662bca47d 824 ){
taknokolat 12:083662bca47d 825
taknokolat 12:083662bca47d 826 pc.printf("SDsetup start.\r\n");
taknokolat 12:083662bca47d 827
taknokolat 12:083662bca47d 828 FILE *fp;
taknokolat 12:083662bca47d 829 char parameter[20]; //文字列渡す用の配列
taknokolat 12:083662bca47d 830 int SDerrorcount = 0; //取得できなかった数を返す
taknokolat 12:083662bca47d 831 const char *paramNames[] = {
taknokolat 12:083662bca47d 832 "SERVO_NEUTRAL_R",
taknokolat 12:083662bca47d 833 "SERVO_NEUTRAL_L",
taknokolat 12:083662bca47d 834 "SERVO_HIGH_FORWARD_R",
taknokolat 12:083662bca47d 835 "SERVO_HIGH_FORWARD_L",
taknokolat 12:083662bca47d 836 "SERVO_SLOW_FORWARD_R",
taknokolat 12:083662bca47d 837 "SERVO_SLOW_FORWARD_L",
taknokolat 12:083662bca47d 838 "TURNTABLE_NEUTRAL",
taknokolat 12:083662bca47d 839 "MATCH_SPEED",
taknokolat 12:083662bca47d 840 "FOCUS_NEUTRAL",
taknokolat 12:083662bca47d 841 "CAMERA_DEG_A",
taknokolat 16:26cee2aaf61d 842 "CAMERA_DEG_B",
taknokolat 16:26cee2aaf61d 843 "PINT_SPEED",
HARUKIDELTA 17:83db05cab3d1 844 "PINT_WAIT",
taknokolat 19:949bab1e9451 845 "TURNTABLE_SPEED",
taknokolat 24:0ad1725c7849 846 "TIME360",
taknokolat 24:0ad1725c7849 847 "MATCH_WID",
taknokolat 20:011977a37394 848 "CAMERA_BOARD_WAIT"
taknokolat 12:083662bca47d 849 };
taknokolat 12:083662bca47d 850
taknokolat 12:083662bca47d 851 fp = fopen("/sd/option.txt","r");
taknokolat 12:083662bca47d 852
taknokolat 12:083662bca47d 853 if(fp != NULL){ //開けたら
taknokolat 12:083662bca47d 854 pc.printf("File was openned.\r\n");
taknokolat 12:083662bca47d 855 if(GetParameter(fp,paramNames[0],parameter)) *Servo_NEUTRAL_R = atof(parameter);
taknokolat 12:083662bca47d 856 else{ *Servo_NEUTRAL_R = servo_NEUTRAL_R;
taknokolat 12:083662bca47d 857 SDerrorcount++;
taknokolat 12:083662bca47d 858 }
taknokolat 12:083662bca47d 859 if(GetParameter(fp,paramNames[1],parameter)) *Servo_NEUTRAL_L = atof(parameter);
taknokolat 12:083662bca47d 860 else{ *Servo_NEUTRAL_L = servo_NEUTRAL_L;
taknokolat 12:083662bca47d 861 SDerrorcount++;
taknokolat 12:083662bca47d 862 }
taknokolat 12:083662bca47d 863 if(GetParameter(fp,paramNames[2],parameter)) *Servo_high_FORWARD_R = atof(parameter);
taknokolat 12:083662bca47d 864 else{ *Servo_high_FORWARD_R = servo_high_FORWARD_R;
taknokolat 12:083662bca47d 865 SDerrorcount++;
taknokolat 12:083662bca47d 866 }
taknokolat 12:083662bca47d 867 if(GetParameter(fp,paramNames[3],parameter)) *Servo_high_FORWARD_L = atof(parameter);
taknokolat 12:083662bca47d 868 else{ *Servo_high_FORWARD_L = servo_high_FORWARD_L;
taknokolat 12:083662bca47d 869 SDerrorcount++;
taknokolat 12:083662bca47d 870 }
taknokolat 12:083662bca47d 871 if(GetParameter(fp,paramNames[4],parameter)) *Servo_slow_FORWARD_R = atof(parameter);
taknokolat 12:083662bca47d 872 else{ *Servo_slow_FORWARD_R = servo_slow_FORWARD_R;
taknokolat 12:083662bca47d 873 SDerrorcount++;
taknokolat 12:083662bca47d 874 }
taknokolat 12:083662bca47d 875 if(GetParameter(fp,paramNames[5],parameter)) *Servo_slow_FORWARD_L = atof(parameter);
taknokolat 12:083662bca47d 876 else{ *Servo_slow_FORWARD_L = servo_slow_FORWARD_L;
taknokolat 12:083662bca47d 877 SDerrorcount++;
taknokolat 12:083662bca47d 878 }
taknokolat 12:083662bca47d 879
taknokolat 12:083662bca47d 880 if(GetParameter(fp,paramNames[6],parameter)) *Turntable_NEUTRAL = atof(parameter);
taknokolat 12:083662bca47d 881 else{ *Turntable_NEUTRAL = turntable_NEUTRAL;
taknokolat 12:083662bca47d 882 SDerrorcount++;
taknokolat 12:083662bca47d 883 }
taknokolat 12:083662bca47d 884 if(GetParameter(fp,paramNames[7],parameter)) *Matchspeed = atof(parameter);
taknokolat 12:083662bca47d 885 else{ *Matchspeed = matchspeed;
taknokolat 12:083662bca47d 886 SDerrorcount++;
taknokolat 12:083662bca47d 887 }
taknokolat 12:083662bca47d 888 if(GetParameter(fp,paramNames[8],parameter)) *Focus_NEUTRAL = atof(parameter);
taknokolat 12:083662bca47d 889 else{ *Focus_NEUTRAL = focus_NEUTRAL;
taknokolat 12:083662bca47d 890 SDerrorcount++;
taknokolat 12:083662bca47d 891 }
taknokolat 19:949bab1e9451 892 if(GetParameter(fp,paramNames[9],parameter)) *Camera_deg_A = atof(parameter);
taknokolat 12:083662bca47d 893 else{ *Camera_deg_A = camera_deg_A;
taknokolat 12:083662bca47d 894 SDerrorcount++;
taknokolat 12:083662bca47d 895 }
taknokolat 19:949bab1e9451 896 if(GetParameter(fp,paramNames[10],parameter)) *Camera_deg_B = atof(parameter);
taknokolat 12:083662bca47d 897 else{ *Camera_deg_B = camera_deg_B;
taknokolat 12:083662bca47d 898 SDerrorcount++;
taknokolat 12:083662bca47d 899 }
taknokolat 19:949bab1e9451 900 if(GetParameter(fp,paramNames[11],parameter)) *Pint_speed = atof(parameter);
taknokolat 16:26cee2aaf61d 901 else{ *Pint_speed = pint_speed;
taknokolat 16:26cee2aaf61d 902 SDerrorcount++;
taknokolat 16:26cee2aaf61d 903 }
taknokolat 20:011977a37394 904 if(GetParameter(fp,paramNames[12],parameter)) *Pint_wait = atof(parameter);
taknokolat 20:011977a37394 905 else{ *Pint_wait = pint_wait;
taknokolat 16:26cee2aaf61d 906 SDerrorcount++;
taknokolat 16:26cee2aaf61d 907 }
taknokolat 19:949bab1e9451 908 if(GetParameter(fp,paramNames[13],parameter)) *Turntable_speed = atof(parameter);
HARUKIDELTA 17:83db05cab3d1 909 else{ *Turntable_speed = turntable_speed;
HARUKIDELTA 17:83db05cab3d1 910 SDerrorcount++;
HARUKIDELTA 17:83db05cab3d1 911 }
taknokolat 24:0ad1725c7849 912 if(GetParameter(fp,paramNames[14],parameter)) *Time360 = atof(parameter);
taknokolat 24:0ad1725c7849 913 else{ *Time360 = time360;
taknokolat 19:949bab1e9451 914 SDerrorcount++;
taknokolat 19:949bab1e9451 915 }
taknokolat 24:0ad1725c7849 916 if(GetParameter(fp,paramNames[15],parameter)) *Match_wid = atof(parameter);
taknokolat 24:0ad1725c7849 917 else{ *Match_wid = match_wid;
taknokolat 19:949bab1e9451 918 SDerrorcount++;
taknokolat 19:949bab1e9451 919 }
taknokolat 20:011977a37394 920 if(GetParameter(fp,paramNames[16],parameter)) *Camera_board_wait = atof(parameter);
taknokolat 20:011977a37394 921 else{ *Camera_board_wait = camera_board_wait;
taknokolat 20:011977a37394 922 SDerrorcount++;
taknokolat 20:011977a37394 923 }
taknokolat 12:083662bca47d 924 fclose(fp);
taknokolat 12:083662bca47d 925
taknokolat 12:083662bca47d 926 }else{ //ファイルがなかったら
taknokolat 12:083662bca47d 927 pc.printf("fp was null.\r\n");
taknokolat 12:083662bca47d 928
taknokolat 12:083662bca47d 929 *Servo_NEUTRAL_R = servo_NEUTRAL_R;
taknokolat 12:083662bca47d 930 *Servo_NEUTRAL_L = servo_NEUTRAL_L;
taknokolat 12:083662bca47d 931 *Servo_high_FORWARD_R = servo_high_FORWARD_R;
taknokolat 12:083662bca47d 932 *Servo_high_FORWARD_L = servo_high_FORWARD_L;
taknokolat 12:083662bca47d 933 *Servo_slow_FORWARD_R = servo_slow_FORWARD_R;
taknokolat 12:083662bca47d 934 *Servo_slow_FORWARD_L = servo_slow_FORWARD_L;
taknokolat 12:083662bca47d 935 *Turntable_NEUTRAL = turntable_NEUTRAL;
taknokolat 12:083662bca47d 936 *Matchspeed = matchspeed;
taknokolat 12:083662bca47d 937 *Focus_NEUTRAL = focus_NEUTRAL;
taknokolat 12:083662bca47d 938 *Camera_deg_A = camera_deg_A;
taknokolat 12:083662bca47d 939 *Camera_deg_B = camera_deg_B;
taknokolat 16:26cee2aaf61d 940 *Pint_speed = pint_speed;
taknokolat 16:26cee2aaf61d 941 *Pint_wait = pint_wait;
HARUKIDELTA 17:83db05cab3d1 942 *Turntable_speed = turntable_speed;
taknokolat 24:0ad1725c7849 943 *Time360 = time360;
taknokolat 24:0ad1725c7849 944 *Match_wid = match_wid;
taknokolat 22:a19be3b505b7 945 *Camera_board_wait = camera_board_wait;
taknokolat 12:083662bca47d 946 SDerrorcount = -1;
taknokolat 12:083662bca47d 947 }
taknokolat 12:083662bca47d 948 pc.printf("SDsetup finished.\r\n");
taknokolat 12:083662bca47d 949 if(SDerrorcount == 0) pc.printf("setting option is success\r\n");
taknokolat 12:083662bca47d 950 else if(SDerrorcount == -1) pc.printf("ERROR 1. cannot open option\r\n");
taknokolat 12:083662bca47d 951 else if(SDerrorcount > 0) pc.printf("ERROR 2. reading parameter is failed[%d]\r\n",SDerrorcount);
taknokolat 12:083662bca47d 952
taknokolat 12:083662bca47d 953 pc.printf("Servo_NEUTRAL_R = %d, Servo_NEUTRAL_L = %d\r\n", *Servo_NEUTRAL_R, *Servo_NEUTRAL_L);
taknokolat 13:b088f0db7158 954 pc.printf("Servo_high_FORWARD_R = %d, Servo_high_FORWARD_L = %d\r\n", *Servo_high_FORWARD_R, *Servo_high_FORWARD_L);
taknokolat 13:b088f0db7158 955 pc.printf("Servo_slow_FORWARD_R = %d, Servo_slow_FORWARD_L = %d\r\n", *Servo_slow_FORWARD_R, *Servo_slow_FORWARD_L);
taknokolat 13:b088f0db7158 956 pc.printf("Turntable_NEUTRAL = %d, Matchspeed = %d\r\n", *Turntable_NEUTRAL, *Matchspeed);
taknokolat 13:b088f0db7158 957 pc.printf("Focus_NEUTRAL = %d\r\n", *Focus_NEUTRAL);
taknokolat 13:b088f0db7158 958 pc.printf("Camera_deg_A = %d, Camera_deg_B = %d\r\n", *Camera_deg_A, *Camera_deg_B);
taknokolat 16:26cee2aaf61d 959 pc.printf("Pint_speed = %d, Pint_wait = %f\r\n", *Pint_speed, *Pint_wait);
HARUKIDELTA 17:83db05cab3d1 960 pc.printf("Turntable_speed = %d\r\n",*Turntable_speed);
taknokolat 24:0ad1725c7849 961 pc.printf("Time360 = %d, Match_wid = %d\r\n", *Time360, *Match_wid);
taknokolat 20:011977a37394 962 pc.printf("Camera_board_wait = %d\r\n", *Camera_board_wait);
taknokolat 12:083662bca47d 963
taknokolat 12:083662bca47d 964 return SDerrorcount;
taknokolat 12:083662bca47d 965 }
taknokolat 12:083662bca47d 966 int GetParameter(FILE *fp, const char *paramName,char parameter[]){
taknokolat 12:083662bca47d 967 int i=0, j=0;
taknokolat 12:083662bca47d 968 int strmax = 200;
taknokolat 12:083662bca47d 969 char str[strmax];
taknokolat 12:083662bca47d 970
taknokolat 12:083662bca47d 971 rewind(fp); //ファイル位置を先頭に
taknokolat 12:083662bca47d 972 while(1){
taknokolat 12:083662bca47d 973 if (fgets(str, strmax, fp) == NULL) {
taknokolat 12:083662bca47d 974 return 0;
taknokolat 12:083662bca47d 975 }
taknokolat 12:083662bca47d 976 if (!strncmp(str, paramName, strlen(paramName))) {
taknokolat 12:083662bca47d 977 while (str[i++] != '=') {}
taknokolat 12:083662bca47d 978 while (str[i] != '\n') {
taknokolat 12:083662bca47d 979 parameter[j++] = str[i++];
taknokolat 12:083662bca47d 980 }
taknokolat 12:083662bca47d 981 parameter[j] = '\0';
taknokolat 12:083662bca47d 982 return 1;
taknokolat 12:083662bca47d 983 }
taknokolat 12:083662bca47d 984 }
taknokolat 12:083662bca47d 985 }
taknokolat 12:083662bca47d 986
taknokolat 12:083662bca47d 987
taknokolat 6:166746820555 988
taknokolat 4:67f705d42f1e 989 void DebugPrint(){
taknokolat 4:67f705d42f1e 990 //for(uint8_t i=0; i<3; i++) pc.printf("%3.2f\t",nowAngle[i]); //skipper地磁気センサ_デバック用
taknokolat 7:8989a4b84695 991 //pc.printf("%3.2f\t",nowAngle[2]);
taknokolat 7:8989a4b84695 992 //pc.printf("%3.2f\t",nowAngle_HMC); //HMC
taknokolat 7:8989a4b84695 993 //pc.printf("\r\n");
taknokolat 6:166746820555 994 }