skipper_raspi_uart_test

Dependencies:   mbed MPU6050_2 HMC5883L_4 SDFileSystem3

Committer:
taknokolat
Date:
Tue Mar 05 16:46:01 2019 +0000
Revision:
40:917b50b9e863
Parent:
39:3faddfc87351
Child:
41:d142afd3c2f7
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 37:8e273677500d 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 40:917b50b9e863 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 カメラピント合わせ
taknokolat 35:0f89eff001a7 102 PwmOut servoCameramount(PC_8); //skipperウラ カメラマウント起動
taknokolat 35:0f89eff001a7 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
taknokolat 38:7c323abc62fb 115 DigitalIn BoardCheck(PB_8);
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 38:7c323abc62fb 129 BoardCheck.mode(PullDown);
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 40:917b50b9e863 147 /*
taknokolat 37:8e273677500d 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 35:0f89eff001a7 152 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 29:5d239812ace6 153 jevoisFlag = true;
taknokolat 35:0f89eff001a7 154 g_landingcommand='N';
taknokolat 39:3faddfc87351 155 g_fp = fopen( "/sd/Datalog01.txt","a" );
taknokolat 39:3faddfc87351 156 fprintf(g_fp, "Time = %d min %d sec : Parachute cut.\r\n",(int)t2.read()/60,(int)t2.read()%60);
taknokolat 39:3faddfc87351 157 fclose(g_fp);
taknokolat 29:5d239812ace6 158 wait(5);
taknokolat 39:3faddfc87351 159 MoveCansat('1');
taknokolat 39:3faddfc87351 160 servoR.pulsewidth_us(Servo_NEUTRAL_R);
taknokolat 39:3faddfc87351 161 servoL.pulsewidth_us(Servo_NEUTRAL_L);
taknokolat 38:7c323abc62fb 162 wait(10);
taknokolat 39:3faddfc87351 163 pc.printf("start\r\n");
taknokolat 39:3faddfc87351 164 g_fp = fopen( "/sd/Datalog01.txt","a" );
taknokolat 39:3faddfc87351 165 fprintf(g_fp, "Time = %d min %d sec : Start sarching target .\r\n",(int)t2.read()/60,(int)t2.read()%60);
taknokolat 39:3faddfc87351 166 fclose(g_fp);
taknokolat 40:917b50b9e863 167 */
taknokolat 31:210cc32d3175 168
taknokolat 38:7c323abc62fb 169 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL + Turntable_speed);
taknokolat 38:7c323abc62fb 170 pc.printf("MatchPosition\r\n");
taknokolat 38:7c323abc62fb 171 while(BoardCheck == 0){
taknokolat 38:7c323abc62fb 172 }
taknokolat 38:7c323abc62fb 173 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL);
taknokolat 38:7c323abc62fb 174
taknokolat 31:210cc32d3175 175 servoCameraPinto.pulsewidth_us(Focus_NEUTRAL-200);
taknokolat 31:210cc32d3175 176 wait(1);
taknokolat 31:210cc32d3175 177 servoCameraPinto.pulsewidth_us(Focus_NEUTRAL);
taknokolat 31:210cc32d3175 178
HARUKIDELTA 0:84ddd6d354e1 179 while(1) {
taknokolat 30:90252dc48c1a 180 if(jevoisFlag==true) NVIC_DisableIRQ(USART6_IRQn);
taknokolat 7:8989a4b84695 181 else NVIC_DisableIRQ(USART2_IRQn);
taknokolat 20:011977a37394 182 pc.printf("Move Camera Board\r\n");
taknokolat 10:63fe920595a7 183 MoveCameraBoard();
taknokolat 35:0f89eff001a7 184 if(jevoisFlag==true) NVIC_DisableIRQ(USART6_IRQn);
taknokolat 35:0f89eff001a7 185 else NVIC_DisableIRQ(USART2_IRQn);
taknokolat 10:63fe920595a7 186
taknokolat 20:011977a37394 187 pc.printf("Position\r\n");
taknokolat 22:a19be3b505b7 188 pc.printf("g_landingcommand=%c\r\n",g_landingcommand);
HARUKIDELTA 25:1f938342d5f9 189
taknokolat 30:90252dc48c1a 190 NVIC_DisableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 191 NVIC_DisableIRQ(USART2_IRQn);
taknokolat 38:7c323abc62fb 192 if(g_landingcommand!='N') MatchPosition();
taknokolat 30:90252dc48c1a 193 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 194 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 8:d11a59d2a2f1 195
taknokolat 30:90252dc48c1a 196 if(jevoisFlag==true) NVIC_DisableIRQ(USART6_IRQn);
taknokolat 8:d11a59d2a2f1 197 else NVIC_DisableIRQ(USART2_IRQn);
taknokolat 8:d11a59d2a2f1 198
taknokolat 20:011977a37394 199 pc.printf("Move Cansat\r\n");
taknokolat 7:8989a4b84695 200 MoveCansat(g_landingcommand);
taknokolat 30:90252dc48c1a 201 if(jevoisFlag==true) NVIC_DisableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 202 else NVIC_DisableIRQ(USART2_IRQn);
Skykon 3:c18342e4fddd 203 wait_ms(23);
taknokolat 8:d11a59d2a2f1 204
taknokolat 20:011977a37394 205 pc.printf("finish\r\n");
taknokolat 30:90252dc48c1a 206 if(jevoisFlag==true) NVIC_EnableIRQ(USART6_IRQn);
taknokolat 7:8989a4b84695 207 else NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 0:84ddd6d354e1 208 }
HARUKIDELTA 0:84ddd6d354e1 209 }
HARUKIDELTA 0:84ddd6d354e1 210
Skykon 3:c18342e4fddd 211
taknokolat 22:a19be3b505b7 212 void MoveCansat(char a)
HARUKIDELTA 0:84ddd6d354e1 213 {
taknokolat 30:90252dc48c1a 214 NVIC_DisableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 215 NVIC_DisableIRQ(USART2_IRQn);
taknokolat 22:a19be3b505b7 216 switch(a){
taknokolat 2:f30666d7838b 217 case 'N': //MOVE_NEUTRAL
HARUKIDELTA 17:83db05cab3d1 218 servoR.pulsewidth_us(Servo_NEUTRAL_R);
HARUKIDELTA 17:83db05cab3d1 219 servoL.pulsewidth_us(Servo_NEUTRAL_L);
taknokolat 30:90252dc48c1a 220 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 221 NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 26:ea86e69563b5 222 g_fp = fopen( "/sd/Datalog01.txt" ,"a" );
HARUKIDELTA 27:f67efcee6509 223 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 224 fclose(g_fp);
taknokolat 35:0f89eff001a7 225 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 35:0f89eff001a7 226 NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 0:84ddd6d354e1 227 break;
taknokolat 1:290e621741fd 228
taknokolat 2:f30666d7838b 229 case 'Y': //MOVE_FORWARD
HARUKIDELTA 17:83db05cab3d1 230 servoR.pulsewidth_us(Servo_high_FORWARD_R);
HARUKIDELTA 17:83db05cab3d1 231 servoL.pulsewidth_us(Servo_high_FORWARD_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 forward .\r\n",(int)t2.read()/60,(int)t2.read()%60);
HARUKIDELTA 27:f67efcee6509 236 fclose(g_fp);
taknokolat 35:0f89eff001a7 237 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 35:0f89eff001a7 238 NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 0:84ddd6d354e1 239 break;
taknokolat 1:290e621741fd 240
taknokolat 12:083662bca47d 241 case 'l': //MOVE_LEFT Low Speed
HARUKIDELTA 17:83db05cab3d1 242 servoR.pulsewidth_us(Servo_slow_FORWARD_R);
taknokolat 35:0f89eff001a7 243 servoL.pulsewidth_us(Servo_NEUTRAL_L);
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 left low speed.\r\n",(int)t2.read()/60,(int)t2.read()%60);
HARUKIDELTA 27:f67efcee6509 246 fclose(g_fp);
taknokolat 35:0f89eff001a7 247 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 35:0f89eff001a7 248 NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 27:f67efcee6509 249 break;
HARUKIDELTA 27:f67efcee6509 250
taknokolat 12:083662bca47d 251 case 'L': //MOVE_LEFT High Speed
HARUKIDELTA 17:83db05cab3d1 252 servoR.pulsewidth_us(Servo_high_FORWARD_R);
taknokolat 35:0f89eff001a7 253 servoL.pulsewidth_us(Servo_NEUTRAL_L);
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);
taknokolat 35:0f89eff001a7 257 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 35:0f89eff001a7 258 NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 27:f67efcee6509 259 break;
taknokolat 1:290e621741fd 260
taknokolat 12:083662bca47d 261 case 'r': //MOVE_RIGHT Low Speed
taknokolat 22:a19be3b505b7 262 servoR.pulsewidth_us(Servo_NEUTRAL_R);
HARUKIDELTA 17:83db05cab3d1 263 servoL.pulsewidth_us(Servo_slow_FORWARD_L);
taknokolat 30:90252dc48c1a 264 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 265 NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 27:f67efcee6509 266 g_fp = fopen( "/sd/Datalog01.txt","a" );
HARUKIDELTA 27:f67efcee6509 267 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 268 fclose(g_fp);
taknokolat 35:0f89eff001a7 269 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 35:0f89eff001a7 270 NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 0:84ddd6d354e1 271 break;
taknokolat 12:083662bca47d 272
taknokolat 12:083662bca47d 273 case 'R': //MOVE_RIGHT High Speed
taknokolat 22:a19be3b505b7 274 servoR.pulsewidth_us(Servo_NEUTRAL_R);
HARUKIDELTA 17:83db05cab3d1 275 servoL.pulsewidth_us(Servo_high_FORWARD_L);
taknokolat 30:90252dc48c1a 276 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 277 NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 27:f67efcee6509 278 g_fp = fopen( "/sd/Datalog01.txt","a" );
HARUKIDELTA 27:f67efcee6509 279 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 280 fclose(g_fp);
taknokolat 35:0f89eff001a7 281 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 35:0f89eff001a7 282 NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 0:84ddd6d354e1 283 break;
taknokolat 1:290e621741fd 284
taknokolat 1:290e621741fd 285 case 'G': //GOAL_FORWARD
HARUKIDELTA 17:83db05cab3d1 286 servoR.pulsewidth_us(Servo_slow_FORWARD_R);
HARUKIDELTA 17:83db05cab3d1 287 servoL.pulsewidth_us(Servo_slow_FORWARD_L);
HARUKIDELTA 27:f67efcee6509 288 g_fp = fopen( "/sd/Datalog01.txt","a" );
HARUKIDELTA 27:f67efcee6509 289 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 290 fclose(g_fp);
taknokolat 35:0f89eff001a7 291 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 35:0f89eff001a7 292 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 7:8989a4b84695 293 break;
taknokolat 37:8e273677500d 294
taknokolat 37:8e273677500d 295 case '0': //MOVE_FORWARD Speed Level 1
taknokolat 37:8e273677500d 296 servoR.pulsewidth_us(Servo_high_FORWARD_R);
taknokolat 37:8e273677500d 297 servoL.pulsewidth_us(Servo_high_FORWARD_L);
taknokolat 37:8e273677500d 298 wait(5);
taknokolat 37:8e273677500d 299 g_fp = fopen( "/sd/Datalog01.txt","a" );
taknokolat 37:8e273677500d 300 fprintf(g_fp, "Time = %d min %d sec : Finish!.\r\n",(int)t2.read()/60,(int)t2.read()%60);
taknokolat 37:8e273677500d 301 fclose(g_fp);
taknokolat 37:8e273677500d 302 servoR.pulsewidth_us(Servo_NEUTRAL_R);
taknokolat 37:8e273677500d 303 servoL.pulsewidth_us(Servo_NEUTRAL_L);
taknokolat 37:8e273677500d 304 exit(0);
taknokolat 37:8e273677500d 305 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 37:8e273677500d 306 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 37:8e273677500d 307 break;
taknokolat 12:083662bca47d 308
taknokolat 12:083662bca47d 309 case '1': //MOVE_FORWARD Speed Level 1
HARUKIDELTA 17:83db05cab3d1 310 servoR.pulsewidth_us(Servo_high_FORWARD_R);
HARUKIDELTA 17:83db05cab3d1 311 servoL.pulsewidth_us(Servo_high_FORWARD_L);
taknokolat 36:e13fca1666a4 312 wait(5);
taknokolat 38:7c323abc62fb 313 /*do{
taknokolat 22:a19be3b505b7 314 SensingMPU();
taknokolat 22:a19be3b505b7 315 wait_ms(30);
taknokolat 38:7c323abc62fb 316 }while((nowAngle[PITCH]>20||nowAngle[PITCH]<-20)&&(nowAngle[ROLL]>20||nowAngle[ROLL]<-20)); */
HARUKIDELTA 27:f67efcee6509 317 g_fp = fopen( "/sd/Datalog01.txt","a" );
HARUKIDELTA 27:f67efcee6509 318 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 319 fclose(g_fp);
taknokolat 35:0f89eff001a7 320 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 35:0f89eff001a7 321 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 12:083662bca47d 322 break;
taknokolat 12:083662bca47d 323
taknokolat 12:083662bca47d 324 case '2': //MOVE_FORWARD Speed Level 2
HARUKIDELTA 17:83db05cab3d1 325 servoR.pulsewidth_us(Servo_high_FORWARD_R);
HARUKIDELTA 17:83db05cab3d1 326 servoL.pulsewidth_us(Servo_high_FORWARD_L);
taknokolat 36:e13fca1666a4 327 wait(10);
HARUKIDELTA 27:f67efcee6509 328 g_fp = fopen( "/sd/Datalog01.txt","a" );
HARUKIDELTA 27:f67efcee6509 329 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 330 fclose(g_fp);
taknokolat 35:0f89eff001a7 331 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 35:0f89eff001a7 332 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 12:083662bca47d 333 break;
taknokolat 12:083662bca47d 334
taknokolat 12:083662bca47d 335 case '3': //MOVE_FORWARD Speed Level 3
HARUKIDELTA 17:83db05cab3d1 336 servoR.pulsewidth_us(Servo_high_FORWARD_R);
HARUKIDELTA 17:83db05cab3d1 337 servoL.pulsewidth_us(Servo_high_FORWARD_L);
taknokolat 36:e13fca1666a4 338 //Camera_board_wait =
taknokolat 36:e13fca1666a4 339 wait(15);
HARUKIDELTA 27:f67efcee6509 340 g_fp = fopen( "/sd/Datalog01.txt","a" );
HARUKIDELTA 27:f67efcee6509 341 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 342 fclose(g_fp);
taknokolat 35:0f89eff001a7 343 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 35:0f89eff001a7 344 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 12:083662bca47d 345 break;
taknokolat 12:083662bca47d 346
taknokolat 12:083662bca47d 347 case '4': //MOVE_FORWARD Speed Level 4
HARUKIDELTA 17:83db05cab3d1 348 servoR.pulsewidth_us(Servo_high_FORWARD_R);
HARUKIDELTA 17:83db05cab3d1 349 servoL.pulsewidth_us(Servo_high_FORWARD_L);
taknokolat 36:e13fca1666a4 350 wait(20);
HARUKIDELTA 27:f67efcee6509 351 g_fp = fopen( "/sd/Datalog01.txt","a" );
HARUKIDELTA 27:f67efcee6509 352 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 353 fclose(g_fp);
taknokolat 35:0f89eff001a7 354 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 35:0f89eff001a7 355 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 12:083662bca47d 356 break;
taknokolat 7:8989a4b84695 357
taknokolat 12:083662bca47d 358 case '5': //MOVE_FORWARD Speed Level 5
HARUKIDELTA 17:83db05cab3d1 359 servoR.pulsewidth_us(Servo_high_FORWARD_R);
HARUKIDELTA 17:83db05cab3d1 360 servoL.pulsewidth_us(Servo_high_FORWARD_L);
taknokolat 36:e13fca1666a4 361 wait(25);
HARUKIDELTA 27:f67efcee6509 362 g_fp = fopen( "/sd/Datalog01.txt","a" );
HARUKIDELTA 27:f67efcee6509 363 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 364 fclose(g_fp);
taknokolat 35:0f89eff001a7 365 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 35:0f89eff001a7 366 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 7:8989a4b84695 367 break;
taknokolat 7:8989a4b84695 368
taknokolat 7:8989a4b84695 369 case 'M': //MatchPosition
HARUKIDELTA 17:83db05cab3d1 370 servoR.pulsewidth_us(Matchspeed);
taknokolat 30:90252dc48c1a 371 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 372 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 7:8989a4b84695 373 break;
taknokolat 7:8989a4b84695 374
taknokolat 12:083662bca47d 375 case 'P': //jevoisからraspberry piへの切り替え
taknokolat 7:8989a4b84695 376 jevoisFlag = false;
taknokolat 38:7c323abc62fb 377 servoR.pulsewidth_us(Servo_high_FORWARD_R);
taknokolat 38:7c323abc62fb 378 servoL.pulsewidth_us(Servo_high_FORWARD_L);
taknokolat 38:7c323abc62fb 379 //Camera_board_wait =
taknokolat 38:7c323abc62fb 380 wait(15);
taknokolat 38:7c323abc62fb 381 servoR.pulsewidth_us(Servo_NEUTRAL_R);
taknokolat 38:7c323abc62fb 382 servoL.pulsewidth_us(Servo_NEUTRAL_L);
taknokolat 28:887df143fa9c 383 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL + Turntable_speed);
taknokolat 28:887df143fa9c 384 wait_ms((float)Time360/(float)2);
taknokolat 28:887df143fa9c 385 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL);
taknokolat 30:90252dc48c1a 386 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 387 NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 0:84ddd6d354e1 388 break;
taknokolat 12:083662bca47d 389
taknokolat 28:887df143fa9c 390 case 'B':
taknokolat 12:083662bca47d 391 /*RasPiからの超音波判定(プログラムスタート部)*/
taknokolat 30:90252dc48c1a 392 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 393 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 12:083662bca47d 394 break;
taknokolat 1:290e621741fd 395
taknokolat 1:290e621741fd 396 default :
taknokolat 30:90252dc48c1a 397 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 22:a19be3b505b7 398 NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 0:84ddd6d354e1 399 break;
taknokolat 1:290e621741fd 400
HARUKIDELTA 0:84ddd6d354e1 401 }
taknokolat 7:8989a4b84695 402
HARUKIDELTA 0:84ddd6d354e1 403 return;
taknokolat 1:290e621741fd 404 }
taknokolat 1:290e621741fd 405
taknokolat 7:8989a4b84695 406 void MoveCameraBoard(){
taknokolat 35:0f89eff001a7 407 if(jevoisFlag==true) NVIC_DisableIRQ(USART6_IRQn);
taknokolat 35:0f89eff001a7 408 else NVIC_DisableIRQ(USART2_IRQn);
taknokolat 22:a19be3b505b7 409 //pc.printf("start\r\n");
taknokolat 7:8989a4b84695 410 MoveCansat('N');
taknokolat 35:0f89eff001a7 411 if(jevoisFlag==true) NVIC_DisableIRQ(USART6_IRQn);
taknokolat 35:0f89eff001a7 412 else NVIC_DisableIRQ(USART2_IRQn);
taknokolat 22:a19be3b505b7 413 //pc.printf("ok\r\n");
taknokolat 10:63fe920595a7 414 g_landingcommand='N';
taknokolat 29:5d239812ace6 415 servoCameradeg.pulsewidth_us(Camera_deg_B);
taknokolat 29:5d239812ace6 416 wait_ms(30);
taknokolat 32:ab030832d180 417 if(g_CameraDegCounter==0){
taknokolat 32:ab030832d180 418 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL + Turntable_speed);
taknokolat 32:ab030832d180 419 wait_ms(Camera_board_wait*ReturnCount);
taknokolat 32:ab030832d180 420 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL);
taknokolat 32:ab030832d180 421
taknokolat 32:ab030832d180 422
taknokolat 32:ab030832d180 423 for(int i=200; i<Camera_deg_B-Camera_deg_A;i=i+200){
taknokolat 32:ab030832d180 424
taknokolat 32:ab030832d180 425 servoCameradeg.pulsewidth_us(Camera_deg_B-i);
taknokolat 32:ab030832d180 426 servoR.pulsewidth_us(Servo_NEUTRAL_R); //servo initialize
taknokolat 32:ab030832d180 427 servoL.pulsewidth_us(Servo_NEUTRAL_L);
taknokolat 36:e13fca1666a4 428 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL);
taknokolat 32:ab030832d180 429 wait_ms(30);
taknokolat 32:ab030832d180 430 //pc.printf("zoom2\r\n");
taknokolat 32:ab030832d180 431 if(jevoisFlag == true) FocusAdjust();
taknokolat 32:ab030832d180 432 else wait(1);
taknokolat 35:0f89eff001a7 433
taknokolat 35:0f89eff001a7 434 if(jevoisFlag==true) NVIC_DisableIRQ(USART6_IRQn);
taknokolat 35:0f89eff001a7 435 else NVIC_DisableIRQ(USART2_IRQn);
taknokolat 35:0f89eff001a7 436
taknokolat 32:ab030832d180 437 if(g_landingcommand!='N') return;
taknokolat 32:ab030832d180 438
taknokolat 32:ab030832d180 439 }
taknokolat 32:ab030832d180 440
taknokolat 32:ab030832d180 441 }
taknokolat 32:ab030832d180 442
taknokolat 24:0ad1725c7849 443 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL - Turntable_speed);
taknokolat 20:011977a37394 444 wait_ms(Camera_board_wait);
taknokolat 24:0ad1725c7849 445 g_CameraDegCounter++;
HARUKIDELTA 17:83db05cab3d1 446 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL);
taknokolat 22:a19be3b505b7 447 //pc.printf("zoom1\r\n");
taknokolat 7:8989a4b84695 448 if(jevoisFlag == true) FocusAdjust();
taknokolat 7:8989a4b84695 449 else wait(1);
taknokolat 35:0f89eff001a7 450
taknokolat 35:0f89eff001a7 451 if(jevoisFlag==true) NVIC_DisableIRQ(USART6_IRQn);
taknokolat 35:0f89eff001a7 452 else NVIC_DisableIRQ(USART2_IRQn);
taknokolat 32:ab030832d180 453
taknokolat 32:ab030832d180 454
taknokolat 7:8989a4b84695 455 if(g_landingcommand!='N') return;
taknokolat 29:5d239812ace6 456
taknokolat 29:5d239812ace6 457 for(int i=200; i<Camera_deg_B-Camera_deg_A;i=i+200){
taknokolat 29:5d239812ace6 458
taknokolat 32:ab030832d180 459 servoCameradeg.pulsewidth_us(Camera_deg_B-i);
taknokolat 32:ab030832d180 460 servoR.pulsewidth_us(Servo_NEUTRAL_R); //servo initialize
taknokolat 32:ab030832d180 461 servoL.pulsewidth_us(Servo_NEUTRAL_L);
taknokolat 36:e13fca1666a4 462 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL);
taknokolat 32:ab030832d180 463 wait_ms(30);
taknokolat 29:5d239812ace6 464 //pc.printf("zoom2\r\n");
taknokolat 29:5d239812ace6 465 if(jevoisFlag == true) FocusAdjust();
taknokolat 29:5d239812ace6 466 else wait(1);
taknokolat 35:0f89eff001a7 467
taknokolat 35:0f89eff001a7 468 if(jevoisFlag==true) NVIC_DisableIRQ(USART6_IRQn);
taknokolat 35:0f89eff001a7 469 else NVIC_DisableIRQ(USART2_IRQn);
taknokolat 35:0f89eff001a7 470
taknokolat 29:5d239812ace6 471 if(g_landingcommand!='N') return;
taknokolat 29:5d239812ace6 472
taknokolat 7:8989a4b84695 473 }
taknokolat 7:8989a4b84695 474
taknokolat 20:011977a37394 475
taknokolat 32:ab030832d180 476 pc.printf("g_CameraDegCounter = %d\r\n",g_CameraDegCounter);
taknokolat 40:917b50b9e863 477
taknokolat 40:917b50b9e863 478 //ターゲットを発見できなかった場合
taknokolat 40:917b50b9e863 479 if(g_CameraDegCounter-2 > (float)Time360/(float)Camera_board_wait){
taknokolat 40:917b50b9e863 480
taknokolat 40:917b50b9e863 481 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL + Turntable_speed);
taknokolat 40:917b50b9e863 482 wait(1);
taknokolat 40:917b50b9e863 483 while(BoardCheck == 0){
taknokolat 40:917b50b9e863 484 }
taknokolat 40:917b50b9e863 485 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL);
taknokolat 40:917b50b9e863 486
taknokolat 40:917b50b9e863 487 if(jevoisFlag == true ) {
taknokolat 40:917b50b9e863 488 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL + Turntable_speed);
taknokolat 40:917b50b9e863 489 wait_ms((float)Time360/(float)2);
taknokolat 40:917b50b9e863 490 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL);
taknokolat 40:917b50b9e863 491 }
taknokolat 40:917b50b9e863 492 if(jevoisFlag == false) MoveCansat('4');
taknokolat 40:917b50b9e863 493
taknokolat 40:917b50b9e863 494 jevoisFlag = !jevoisFlag;
taknokolat 40:917b50b9e863 495
taknokolat 40:917b50b9e863 496 g_CameraDegCounter = 0;
taknokolat 40:917b50b9e863 497 }
taknokolat 40:917b50b9e863 498
taknokolat 22:a19be3b505b7 499 //pc.printf("Move Board Finish\r\n");
taknokolat 7:8989a4b84695 500 return;
taknokolat 7:8989a4b84695 501 }
taknokolat 7:8989a4b84695 502
taknokolat 7:8989a4b84695 503 void MatchPosition(){
taknokolat 32:ab030832d180 504 NVIC_DisableIRQ(USART6_IRQn);
taknokolat 32:ab030832d180 505 NVIC_DisableIRQ(USART2_IRQn);
taknokolat 24:0ad1725c7849 506
taknokolat 32:ab030832d180 507 int TurnTime ;
taknokolat 32:ab030832d180 508
taknokolat 32:ab030832d180 509 TurnTime = g_CameraDegCounter - ReturnCount;
taknokolat 32:ab030832d180 510
taknokolat 32:ab030832d180 511 if(TurnTime >=0){
taknokolat 32:ab030832d180 512 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL + Turntable_speed);
taknokolat 38:7c323abc62fb 513 //wait_ms(Camera_board_wait*TurnTime);
taknokolat 38:7c323abc62fb 514 pc.printf("MatchPosition\r\n");
taknokolat 38:7c323abc62fb 515 while(BoardCheck == 0){
taknokolat 38:7c323abc62fb 516 }
taknokolat 32:ab030832d180 517 }else{
taknokolat 32:ab030832d180 518 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL - Turntable_speed);
taknokolat 38:7c323abc62fb 519 //wait_ms(-Camera_board_wait*TurnTime);
taknokolat 38:7c323abc62fb 520 pc.printf("MatchPosition\r\n");
taknokolat 38:7c323abc62fb 521 while(BoardCheck == 0){
taknokolat 38:7c323abc62fb 522 }
taknokolat 32:ab030832d180 523 }
taknokolat 24:0ad1725c7849 524 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL);
taknokolat 24:0ad1725c7849 525
taknokolat 38:7c323abc62fb 526 if(jevoisFlag == false ){
taknokolat 37:8e273677500d 527 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL + Turntable_speed);
taknokolat 37:8e273677500d 528 wait_ms((float)Time360/(float)2);
taknokolat 37:8e273677500d 529 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL);
taknokolat 38:7c323abc62fb 530 }
taknokolat 37:8e273677500d 531
taknokolat 22:a19be3b505b7 532 int SetLoop=0;
taknokolat 22:a19be3b505b7 533
taknokolat 22:a19be3b505b7 534 while(SetLoop<30){
taknokolat 7:8989a4b84695 535 SensingMPU();
taknokolat 37:8e273677500d 536 wait_ms(10);
taknokolat 24:0ad1725c7849 537 //SensingHMC();
taknokolat 24:0ad1725c7849 538 //wait_ms(20);
taknokolat 22:a19be3b505b7 539 //DebugPrint();
taknokolat 22:a19be3b505b7 540 SetLoop++;
taknokolat 22:a19be3b505b7 541 //pc.printf("nowAngle_HMC=%f\tMPU=%f\r\n",nowAngle_HMC,nowAngle[YAW]);
taknokolat 22:a19be3b505b7 542
taknokolat 22:a19be3b505b7 543 }
taknokolat 7:8989a4b84695 544
taknokolat 24:0ad1725c7849 545 static float TargetDeg = 0;
taknokolat 24:0ad1725c7849 546
taknokolat 32:ab030832d180 547 TargetDeg = 360*(float)Camera_board_wait*((float)g_CameraDegCounter - ReturnCount)/(float)Time360;
taknokolat 24:0ad1725c7849 548
taknokolat 37:8e273677500d 549 if(TargetDeg > 360)TargetDeg = TargetDeg - 360;
taknokolat 37:8e273677500d 550 if(TargetDeg < 0)TargetDeg = TargetDeg + 360;
taknokolat 33:5f77118eacd5 551
taknokolat 37:8e273677500d 552 float HighTargetYaw = nowAngle[YAW] + TargetDeg + Match_wid;
taknokolat 37:8e273677500d 553 float LowTargetYaw = nowAngle[YAW] + TargetDeg - Match_wid;
taknokolat 21:ca8f35e24e66 554
taknokolat 22:a19be3b505b7 555
taknokolat 37:8e273677500d 556 if(HighTargetYaw >= 360.0f) HighTargetYaw = HighTargetYaw - 360.0f;
taknokolat 37:8e273677500d 557 if(LowTargetYaw >= 360.0f) LowTargetYaw = LowTargetYaw - 360.0f;
taknokolat 37:8e273677500d 558 if(LowTargetYaw < 0.0f) LowTargetYaw = LowTargetYaw + 360.0f;
taknokolat 21:ca8f35e24e66 559
taknokolat 22:a19be3b505b7 560 pc.printf("\r\nnow=%f\t,high=%f\t,low=%f\r\n",nowAngle[YAW],HighTargetYaw,LowTargetYaw);
taknokolat 22:a19be3b505b7 561
taknokolat 24:0ad1725c7849 562 MoveCansat('r');
taknokolat 22:a19be3b505b7 563
taknokolat 22:a19be3b505b7 564 if(HighTargetYaw-LowTargetYaw<0){
taknokolat 22:a19be3b505b7 565 while(nowAngle[YAW] > HighTargetYaw && nowAngle[YAW] < LowTargetYaw){
taknokolat 22:a19be3b505b7 566 //MoveCansat('r');
taknokolat 22:a19be3b505b7 567 SensingMPU();
taknokolat 35:0f89eff001a7 568 wait_ms(10);
taknokolat 22:a19be3b505b7 569 pc.printf("nowAngle_MPU=%f\r\n",nowAngle[YAW]);
taknokolat 22:a19be3b505b7 570 }
taknokolat 22:a19be3b505b7 571 }else{
taknokolat 22:a19be3b505b7 572 while(nowAngle[YAW] > HighTargetYaw || nowAngle[YAW] < LowTargetYaw){
taknokolat 22:a19be3b505b7 573 //MoveCansat('r');
taknokolat 22:a19be3b505b7 574 SensingMPU();
taknokolat 35:0f89eff001a7 575 wait_ms(10);
taknokolat 22:a19be3b505b7 576 pc.printf("nowAngle_MPU=%f\r\n",nowAngle[YAW]);
taknokolat 22:a19be3b505b7 577 }
taknokolat 7:8989a4b84695 578 }
taknokolat 24:0ad1725c7849 579 g_CameraDegCounter = 0;
taknokolat 32:ab030832d180 580
taknokolat 39:3faddfc87351 581 g_fp = fopen( "/sd/Datalog01.txt","a" );
taknokolat 39:3faddfc87351 582 fprintf(g_fp, "Time = %d min %d sec : Cansat move %fdeg.\r\n",(int)t2.read()/60,(int)t2.read()%60,TargetDeg);
taknokolat 39:3faddfc87351 583 fclose(g_fp);
taknokolat 39:3faddfc87351 584
taknokolat 32:ab030832d180 585 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 32:ab030832d180 586 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 7:8989a4b84695 587 return;
taknokolat 7:8989a4b84695 588 }
taknokolat 7:8989a4b84695 589
taknokolat 7:8989a4b84695 590 void FocusAdjust(){
taknokolat 35:0f89eff001a7 591 if(jevoisFlag==true) NVIC_DisableIRQ(USART6_IRQn);
taknokolat 35:0f89eff001a7 592 else NVIC_DisableIRQ(USART2_IRQn);
taknokolat 35:0f89eff001a7 593
taknokolat 31:210cc32d3175 594 if(FocusFlag == false){
taknokolat 33:5f77118eacd5 595 servoCameraPinto.pulsewidth_us(Focus_NEUTRAL + Pint_speed);
taknokolat 33:5f77118eacd5 596 servoR.pulsewidth_us(Servo_NEUTRAL_R); //servo initialize
taknokolat 33:5f77118eacd5 597 servoL.pulsewidth_us(Servo_NEUTRAL_L);
taknokolat 36:e13fca1666a4 598 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL);
taknokolat 33:5f77118eacd5 599 wait(Pint_wait);
taknokolat 31:210cc32d3175 600 FocusFlag = !FocusFlag;
taknokolat 31:210cc32d3175 601 }else{
taknokolat 33:5f77118eacd5 602 servoCameraPinto.pulsewidth_us(Focus_NEUTRAL - Pint_speed);
taknokolat 33:5f77118eacd5 603 servoR.pulsewidth_us(Servo_NEUTRAL_R); //servo initialize
taknokolat 33:5f77118eacd5 604 servoL.pulsewidth_us(Servo_NEUTRAL_L);
taknokolat 36:e13fca1666a4 605 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL);
taknokolat 33:5f77118eacd5 606 wait(Pint_wait);
taknokolat 31:210cc32d3175 607 FocusFlag = !FocusFlag;
taknokolat 31:210cc32d3175 608 }
HARUKIDELTA 17:83db05cab3d1 609 servoCameraPinto.pulsewidth_us(Focus_NEUTRAL);
taknokolat 11:d44d137831b9 610
taknokolat 7:8989a4b84695 611 return;
taknokolat 15:1519fccfcae3 612 }
taknokolat 7:8989a4b84695 613
taknokolat 1:290e621741fd 614 void getSF_Serial_jevois(){
taknokolat 22:a19be3b505b7 615
taknokolat 22:a19be3b505b7 616 //pc.printf("jevois\r\n");
taknokolat 1:290e621741fd 617
taknokolat 1:290e621741fd 618
taknokolat 1:290e621741fd 619 static char SFbuf[16]={'Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q'};
taknokolat 1:290e621741fd 620
taknokolat 1:290e621741fd 621 static int bufcounter=0;
taknokolat 1:290e621741fd 622
taknokolat 1:290e621741fd 623
taknokolat 1:290e621741fd 624
taknokolat 1:290e621741fd 625 if(pc.readable()) { // 受信確認
taknokolat 1:290e621741fd 626
taknokolat 1:290e621741fd 627 SFbuf[bufcounter] = pc.getc(); // 1文字取り出し
taknokolat 1:290e621741fd 628 if(SFbuf[0]!='S'){
taknokolat 1:290e621741fd 629 //pc.printf("x");
taknokolat 1:290e621741fd 630 return;
taknokolat 1:290e621741fd 631 }
taknokolat 1:290e621741fd 632
taknokolat 1:290e621741fd 633
taknokolat 1:290e621741fd 634
taknokolat 22:a19be3b505b7 635 pc.printf("%c",SFbuf[bufcounter]);
taknokolat 1:290e621741fd 636
Skykon 3:c18342e4fddd 637 if(SFbuf[0]=='S' && bufcounter<5)bufcounter++;
taknokolat 1:290e621741fd 638
taknokolat 1:290e621741fd 639 if(bufcounter==5 && SFbuf[4]=='F'){
taknokolat 1:290e621741fd 640
taknokolat 1:290e621741fd 641 g_landingcommand = SFbuf[1];
taknokolat 2:f30666d7838b 642 wait_ms(31);//信号が速すぎることによる割り込み防止
taknokolat 1:290e621741fd 643 //pc.printf("%c",g_landingcommand);
taknokolat 1:290e621741fd 644 //wait_ms(20);
taknokolat 1:290e621741fd 645 //if(g_landingcommand=='Y')g_SerialTargetYAW = ConvertByteintoFloat(SFbuf[2], SFbuf[3]);
taknokolat 1:290e621741fd 646 bufcounter = 0;
taknokolat 1:290e621741fd 647 memset(SFbuf, 0, sizeof(SFbuf));
taknokolat 1:290e621741fd 648 NVIC_ClearPendingIRQ(USART2_IRQn);
taknokolat 1:290e621741fd 649 //pc.printf("command = %c, commandYAW = %f\r\n", g_landingcommand, g_SerialTargetYAW);
taknokolat 1:290e621741fd 650 }
taknokolat 1:290e621741fd 651
taknokolat 1:290e621741fd 652 else if(bufcounter>=5){
taknokolat 1:290e621741fd 653 //pc.printf("Communication Falsed.\r\n");
taknokolat 1:290e621741fd 654 memset(SFbuf, 0, sizeof(SFbuf));
taknokolat 1:290e621741fd 655 bufcounter = 0;
taknokolat 1:290e621741fd 656 NVIC_ClearPendingIRQ(USART2_IRQn);
taknokolat 1:290e621741fd 657 }
taknokolat 1:290e621741fd 658 }
taknokolat 1:290e621741fd 659
taknokolat 1:290e621741fd 660
taknokolat 1:290e621741fd 661 }
taknokolat 1:290e621741fd 662
taknokolat 1:290e621741fd 663
taknokolat 12:083662bca47d 664 void getSF_Serial_pi(){
taknokolat 2:f30666d7838b 665
taknokolat 7:8989a4b84695 666 //NVIC_DisableIRQ(USART2_IRQn);
taknokolat 1:290e621741fd 667
taknokolat 1:290e621741fd 668 static char SFbuf[16]={'Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q'};
taknokolat 1:290e621741fd 669
taknokolat 1:290e621741fd 670 static int bufcounter=0;
taknokolat 1:290e621741fd 671
taknokolat 1:290e621741fd 672
taknokolat 1:290e621741fd 673
taknokolat 1:290e621741fd 674 if(pc2.readable()) { // 受信確認
taknokolat 1:290e621741fd 675
taknokolat 1:290e621741fd 676 SFbuf[bufcounter] = pc2.getc(); // 1文字取り出し
taknokolat 1:290e621741fd 677 if(SFbuf[0]!='S'){
taknokolat 1:290e621741fd 678 //pc.printf("x");
taknokolat 1:290e621741fd 679 return;
taknokolat 1:290e621741fd 680 }
taknokolat 1:290e621741fd 681
taknokolat 1:290e621741fd 682
taknokolat 1:290e621741fd 683
taknokolat 30:90252dc48c1a 684 pc.printf("%c",SFbuf[bufcounter]);
taknokolat 1:290e621741fd 685
taknokolat 1:290e621741fd 686 if(SFbuf[0]=='S'&&bufcounter<5)bufcounter++;
taknokolat 1:290e621741fd 687
taknokolat 1:290e621741fd 688 if(bufcounter==5 && SFbuf[4]=='F'){
taknokolat 1:290e621741fd 689
taknokolat 1:290e621741fd 690 g_landingcommand = SFbuf[1];
taknokolat 2:f30666d7838b 691 wait_ms(31);//信号が速すぎることによる割り込み防止
taknokolat 1:290e621741fd 692 //pc.printf("%c",g_landingcommand);
taknokolat 1:290e621741fd 693 //wait_ms(20);
taknokolat 1:290e621741fd 694 //if(g_landingcommand=='Y')g_SerialTargetYAW = ConvertByteintoFloat(SFbuf[2], SFbuf[3]);
taknokolat 1:290e621741fd 695 bufcounter = 0;
taknokolat 1:290e621741fd 696 memset(SFbuf, 0, sizeof(SFbuf));
taknokolat 1:290e621741fd 697 NVIC_ClearPendingIRQ(USART2_IRQn);
taknokolat 1:290e621741fd 698 //pc.printf("command = %c, commandYAW = %f\r\n", g_landingcommand, g_SerialTargetYAW);
taknokolat 1:290e621741fd 699 }
taknokolat 1:290e621741fd 700
taknokolat 1:290e621741fd 701 else if(bufcounter>=5){
taknokolat 1:290e621741fd 702 //pc.printf("Communication Falsed.\r\n");
taknokolat 1:290e621741fd 703 memset(SFbuf, 0, sizeof(SFbuf));
taknokolat 1:290e621741fd 704 bufcounter = 0;
taknokolat 1:290e621741fd 705 NVIC_ClearPendingIRQ(USART2_IRQn);
taknokolat 1:290e621741fd 706 }
taknokolat 1:290e621741fd 707 }
taknokolat 2:f30666d7838b 708
taknokolat 7:8989a4b84695 709 //NVIC_EnableIRQ(USART2_IRQn);
taknokolat 1:290e621741fd 710
taknokolat 12:083662bca47d 711 }
taknokolat 1:290e621741fd 712
Skykon 3:c18342e4fddd 713
Skykon 3:c18342e4fddd 714 void setup(){
HARUKIDELTA 23:29b2722bd753 715
HARUKIDELTA 23:29b2722bd753 716 led1 = 1;
HARUKIDELTA 23:29b2722bd753 717 led2 = 1;
taknokolat 37:8e273677500d 718 //led3 = 1;
HARUKIDELTA 23:29b2722bd753 719 led4 = 1;
HARUKIDELTA 26:ea86e69563b5 720
HARUKIDELTA 26:ea86e69563b5 721 servoR.pulsewidth_us(Servo_NEUTRAL_R); //servo initialize
HARUKIDELTA 26:ea86e69563b5 722 servoL.pulsewidth_us(Servo_NEUTRAL_L);
HARUKIDELTA 26:ea86e69563b5 723 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL);
taknokolat 29:5d239812ace6 724 servoCameradeg.pulsewidth_us(Camera_deg_B);
HARUKIDELTA 26:ea86e69563b5 725 servoCameraPinto.pulsewidth_us(focus_NEUTRAL);
Skykon 3:c18342e4fddd 726
taknokolat 13:b088f0db7158 727 SetOptions(&Servo_NEUTRAL_R, &Servo_NEUTRAL_L,
taknokolat 12:083662bca47d 728 &Servo_high_FORWARD_R, &Servo_high_FORWARD_L,
taknokolat 12:083662bca47d 729 &Servo_slow_FORWARD_R,&Servo_slow_FORWARD_L,
taknokolat 12:083662bca47d 730 &Turntable_NEUTRAL,&Matchspeed,&Focus_NEUTRAL,
taknokolat 16:26cee2aaf61d 731 &Camera_deg_A, &Camera_deg_B,
HARUKIDELTA 17:83db05cab3d1 732 &Pint_speed,&Pint_wait,
taknokolat 19:949bab1e9451 733 &Turntable_speed,
taknokolat 24:0ad1725c7849 734 &Time360, &Match_wid,
taknokolat 20:011977a37394 735 &Camera_board_wait
taknokolat 13:b088f0db7158 736 );
taknokolat 12:083662bca47d 737
Skykon 3:c18342e4fddd 738 Init_sensors();
Skykon 3:c18342e4fddd 739 //switch2.rise(ResetTrim);
Skykon 3:c18342e4fddd 740
taknokolat 30:90252dc48c1a 741 //NVIC_SetPriority(USART6_IRQn,0);
taknokolat 7:8989a4b84695 742 //NVIC_SetPriority(EXTI0_IRQn,1);
taknokolat 7:8989a4b84695 743 //NVIC_SetPriority(TIM5_IRQn,2);
taknokolat 7:8989a4b84695 744 //NVIC_SetPriority(EXTI9_5_IRQn,3);
taknokolat 7:8989a4b84695 745 //NVIC_SetPriority(USART2_IRQn,4);
taknokolat 7:8989a4b84695 746
taknokolat 30:90252dc48c1a 747 NVIC_SetPriority(USART6_IRQn,0);//割り込み優先度
taknokolat 7:8989a4b84695 748 NVIC_SetPriority(USART2_IRQn,1);
taknokolat 7:8989a4b84695 749
Skykon 3:c18342e4fddd 750 DisplayClock();
Skykon 3:c18342e4fddd 751 t.start();
Skykon 3:c18342e4fddd 752
Skykon 3:c18342e4fddd 753 pc.printf("MPU calibration start\r\n");
taknokolat 24:0ad1725c7849 754 //pc.printf("HMC calibration start\r\n");
Skykon 3:c18342e4fddd 755
Skykon 3:c18342e4fddd 756 float offsetstart = t.read();
Skykon 3:c18342e4fddd 757 while(t.read() - offsetstart < 26){
Skykon 3:c18342e4fddd 758 SensingMPU();
taknokolat 24:0ad1725c7849 759 //SensingHMC();
Skykon 3:c18342e4fddd 760 for(uint8_t i=0; i<3; i++) pc.printf("%3.2f\t",nowAngle[i]);
taknokolat 24:0ad1725c7849 761 //pc.printf("\t%3.2f\t",nowAngle_HMC);
Skykon 3:c18342e4fddd 762 pc.printf("\r\n");
HARUKIDELTA 23:29b2722bd753 763 led1 = !led1;
HARUKIDELTA 23:29b2722bd753 764 led2 = !led2;
taknokolat 37:8e273677500d 765 //led3 = !led3;
HARUKIDELTA 23:29b2722bd753 766 led4 = !led4;
Skykon 3:c18342e4fddd 767 }
Skykon 3:c18342e4fddd 768
Skykon 3:c18342e4fddd 769 FirstROLL = nowAngle[ROLL];
Skykon 3:c18342e4fddd 770 FirstPITCH = nowAngle[PITCH];
Skykon 3:c18342e4fddd 771 nowAngle[ROLL] -=FirstROLL;
Skykon 3:c18342e4fddd 772 nowAngle[PITCH] -=FirstPITCH;
taknokolat 6:166746820555 773 FirstYAW = nowAngle[YAW];
taknokolat 6:166746820555 774 nowAngle[YAW] -= FirstYAW;
taknokolat 6:166746820555 775
taknokolat 24:0ad1725c7849 776 //g_FirstYAW_HMC = nowAngle_HMC;
taknokolat 24:0ad1725c7849 777 //nowAngle_HMC -=g_FirstYAW_HMC;
taknokolat 24:0ad1725c7849 778 //if(nowAngle_HMC<0)nowAngle_HMC+=360;
Skykon 3:c18342e4fddd 779
HARUKIDELTA 23:29b2722bd753 780 led1 = 0;
HARUKIDELTA 23:29b2722bd753 781 led2 = 0;
taknokolat 37:8e273677500d 782 //led3 = 0;
HARUKIDELTA 23:29b2722bd753 783 led4 = 0;
HARUKIDELTA 23:29b2722bd753 784
Skykon 3:c18342e4fddd 785 wait(0.2);
Skykon 3:c18342e4fddd 786
HARUKIDELTA 26:ea86e69563b5 787
HARUKIDELTA 26:ea86e69563b5 788 g_fp = fopen( "/sd/Datalog01.txt" ,"a" );
HARUKIDELTA 26:ea86e69563b5 789 if( g_fp == NULL ) {
taknokolat 37:8e273677500d 790 pc.printf( "File open error!!!\r\n" );
HARUKIDELTA 26:ea86e69563b5 791 }
HARUKIDELTA 27:f67efcee6509 792 fprintf(g_fp,"\r\n-------------------------\r\n");
HARUKIDELTA 26:ea86e69563b5 793 fprintf(g_fp,"All initialized.\r\n");
HARUKIDELTA 26:ea86e69563b5 794 fclose( g_fp );
HARUKIDELTA 26:ea86e69563b5 795
HARUKIDELTA 26:ea86e69563b5 796
Skykon 3:c18342e4fddd 797 pc.printf("All initialized\r\n");
taknokolat 4:67f705d42f1e 798 setupFlag=true;
taknokolat 1:290e621741fd 799 }
taknokolat 1:290e621741fd 800
Skykon 3:c18342e4fddd 801
Skykon 3:c18342e4fddd 802 void SensingMPU(){
Skykon 3:c18342e4fddd 803 //static int16_t deltaT = 0, t_start = 0;
Skykon 3:c18342e4fddd 804 //t_start = t.read_us();
Skykon 3:c18342e4fddd 805
taknokolat 7:8989a4b84695 806 float rpy[3] = {0};
Skykon 3:c18342e4fddd 807 static uint16_t count_changeRPY = 0;
Skykon 3:c18342e4fddd 808 static bool flg_checkoutlier = false;
taknokolat 30:90252dc48c1a 809 NVIC_DisableIRQ(USART6_IRQn);
Skykon 3:c18342e4fddd 810 NVIC_DisableIRQ(USART2_IRQn);
Skykon 3:c18342e4fddd 811 NVIC_DisableIRQ(TIM5_IRQn);
Skykon 3:c18342e4fddd 812 NVIC_DisableIRQ(EXTI0_IRQn);
Skykon 3:c18342e4fddd 813 NVIC_DisableIRQ(EXTI9_5_IRQn);
Skykon 3:c18342e4fddd 814
Skykon 3:c18342e4fddd 815 mpu6050.getRollPitchYaw_Skipper(rpy);
Skykon 3:c18342e4fddd 816
taknokolat 30:90252dc48c1a 817 NVIC_EnableIRQ(USART6_IRQn);
Skykon 3:c18342e4fddd 818 NVIC_EnableIRQ(USART2_IRQn);
Skykon 3:c18342e4fddd 819 NVIC_EnableIRQ(TIM5_IRQn);
Skykon 3:c18342e4fddd 820 NVIC_EnableIRQ(EXTI0_IRQn);
Skykon 3:c18342e4fddd 821 NVIC_EnableIRQ(EXTI9_5_IRQn);
Skykon 3:c18342e4fddd 822
Skykon 3:c18342e4fddd 823
Skykon 3:c18342e4fddd 824 //外れ値対策
taknokolat 37:8e273677500d 825 for(uint8_t i=0; i<3; i++) rpy[i] *= 180.0f/(float)PI;
Skykon 3:c18342e4fddd 826 rpy[ROLL] -= FirstROLL;
Skykon 3:c18342e4fddd 827 rpy[PITCH] -= FirstPITCH;
taknokolat 4:67f705d42f1e 828 if(!setupFlag){
taknokolat 4:67f705d42f1e 829 rpy[YAW] -= FirstYAW;
taknokolat 4:67f705d42f1e 830 }else{
taknokolat 4:67f705d42f1e 831 if(rpy[YAW] >= FirstYAW){
taknokolat 4:67f705d42f1e 832 rpy[YAW] -= FirstYAW;
taknokolat 4:67f705d42f1e 833 }else{
taknokolat 4:67f705d42f1e 834 rpy[YAW] += 360.0f;
taknokolat 4:67f705d42f1e 835 rpy[YAW] -= FirstYAW;
taknokolat 4:67f705d42f1e 836 }
taknokolat 4:67f705d42f1e 837 }
Skykon 3:c18342e4fddd 838
Skykon 3:c18342e4fddd 839 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 840 if(!flg_checkoutlier || count_changeRPY >= 2){
Skykon 3:c18342e4fddd 841 for(uint8_t i=0; i<3; i++){
taknokolat 34:0c2b67b31b12 842 if(rpy[i] > nowAngle[i]-180 && rpy[i] < nowAngle[i]+180){
taknokolat 34:0c2b67b31b12 843 nowAngle[i] = (rpy[i] + nowAngle[i])/2.0f; //2つの移動平均
taknokolat 34:0c2b67b31b12 844 }else{
taknokolat 34:0c2b67b31b12 845 nowAngle[i] = rpy[i];
taknokolat 34:0c2b67b31b12 846 }
Skykon 3:c18342e4fddd 847 }
Skykon 3:c18342e4fddd 848 count_changeRPY = 0;
Skykon 3:c18342e4fddd 849 }else count_changeRPY++;
Skykon 3:c18342e4fddd 850 flg_checkoutlier = false;
Skykon 3:c18342e4fddd 851
Skykon 3:c18342e4fddd 852 }
Skykon 3:c18342e4fddd 853
Skykon 3:c18342e4fddd 854
Skykon 3:c18342e4fddd 855 void Init_sensors(){
Skykon 3:c18342e4fddd 856 if(mpu6050.setup() == -1){
Skykon 3:c18342e4fddd 857 pc.printf("failed initialize\r\n");
Skykon 3:c18342e4fddd 858 }
Skykon 3:c18342e4fddd 859 }
Skykon 3:c18342e4fddd 860
Skykon 3:c18342e4fddd 861
Skykon 3:c18342e4fddd 862 void DisplayClock(){
Skykon 3:c18342e4fddd 863 pc.printf("System Clock = %d[MHz]\r\n", HAL_RCC_GetSysClockFreq()/1000000);
Skykon 3:c18342e4fddd 864 pc.printf("HCLK Clock = %d[MHz]\r\n", HAL_RCC_GetHCLKFreq()/1000000);
Skykon 3:c18342e4fddd 865 pc.printf("PCLK1 Clock = %d[MHz]\r\n", HAL_RCC_GetPCLK1Freq()/1000000);
Skykon 3:c18342e4fddd 866 pc.printf("PCLK2 Clock = %d[MHz]\r\n", HAL_RCC_GetPCLK2Freq()/1000000);
Skykon 3:c18342e4fddd 867 pc.printf("\r\n");
taknokolat 4:67f705d42f1e 868 }
taknokolat 6:166746820555 869
taknokolat 24:0ad1725c7849 870 /*void SensingHMC(){
taknokolat 6:166746820555 871 //static int16_t deltaT = 0, t_start = 0;
taknokolat 6:166746820555 872 //t_start = t.read_us();
taknokolat 6:166746820555 873
taknokolat 7:8989a4b84695 874 float rpy=0;
taknokolat 6:166746820555 875 static uint16_t count_changeRPY = 0;
taknokolat 6:166746820555 876 static bool flg_checkoutlier = false;
taknokolat 30:90252dc48c1a 877 NVIC_DisableIRQ(USART6_IRQn);
taknokolat 6:166746820555 878 NVIC_DisableIRQ(USART2_IRQn);
taknokolat 19:949bab1e9451 879 //NVIC_DisableIRQ(TIM5_IRQn);
taknokolat 19:949bab1e9451 880 //NVIC_DisableIRQ(EXTI0_IRQn);
taknokolat 19:949bab1e9451 881 //NVIC_DisableIRQ(EXTI9_5_IRQn);
taknokolat 4:67f705d42f1e 882
taknokolat 24:0ad1725c7849 883 rpy= compass.getHeadingXYDeg(Time360,Match_wid);
taknokolat 6:166746820555 884
taknokolat 30:90252dc48c1a 885 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 6:166746820555 886 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 19:949bab1e9451 887 //NVIC_EnableIRQ(TIM5_IRQn);
taknokolat 19:949bab1e9451 888 //NVIC_EnableIRQ(EXTI0_IRQn);
taknokolat 19:949bab1e9451 889 //NVIC_EnableIRQ(EXTI9_5_IRQn);
taknokolat 6:166746820555 890
taknokolat 6:166746820555 891
taknokolat 6:166746820555 892 //外れ値対策
taknokolat 6:166746820555 893 //rpy*= 180.0f/PI;
taknokolat 6:166746820555 894 if(!setupFlag){
taknokolat 6:166746820555 895 rpy -= g_FirstYAW_HMC;
taknokolat 6:166746820555 896 }else{
taknokolat 6:166746820555 897 if(rpy >= g_FirstYAW_HMC){
taknokolat 6:166746820555 898 rpy -= g_FirstYAW_HMC;
taknokolat 6:166746820555 899 }else{
taknokolat 6:166746820555 900 rpy += 360.0f;
taknokolat 6:166746820555 901 rpy -= g_FirstYAW_HMC;
taknokolat 6:166746820555 902 }
taknokolat 6:166746820555 903 }
taknokolat 6:166746820555 904
taknokolat 6:166746820555 905 if(rpy < nowAngle_HMC-10 || rpy > nowAngle_HMC+10) {flg_checkoutlier = true;}
taknokolat 6:166746820555 906 if(!flg_checkoutlier || count_changeRPY >= 2){
taknokolat 6:166746820555 907
taknokolat 6:166746820555 908 nowAngle_HMC = (rpy + nowAngle_HMC)/2.0f; //2つの移動平均
taknokolat 6:166746820555 909
taknokolat 6:166746820555 910 count_changeRPY = 0;
taknokolat 6:166746820555 911 }else count_changeRPY++;
taknokolat 6:166746820555 912 flg_checkoutlier = false;
taknokolat 6:166746820555 913
taknokolat 24:0ad1725c7849 914 }*/
taknokolat 12:083662bca47d 915
taknokolat 12:083662bca47d 916 int SetOptions(int *Servo_NEUTRAL_R, int *Servo_NEUTRAL_L,
taknokolat 12:083662bca47d 917 int *Servo_high_FORWARD_R, int *Servo_high_FORWARD_L,
taknokolat 12:083662bca47d 918 int *Servo_slow_FORWARD_R,int *Servo_slow_FORWARD_L,
taknokolat 12:083662bca47d 919 int *Turntable_NEUTRAL,int *Matchspeed,int *Focus_NEUTRAL,
taknokolat 16:26cee2aaf61d 920 int *Camera_deg_A, int *Camera_deg_B,
HARUKIDELTA 17:83db05cab3d1 921 int *Pint_speed, float *Pint_wait,
taknokolat 19:949bab1e9451 922 int *Turntable_speed,
taknokolat 24:0ad1725c7849 923 int *Time360, int *Match_wid,
taknokolat 20:011977a37394 924 int *Camera_board_wait
taknokolat 12:083662bca47d 925 ){
taknokolat 12:083662bca47d 926
taknokolat 12:083662bca47d 927 pc.printf("SDsetup start.\r\n");
taknokolat 12:083662bca47d 928
taknokolat 12:083662bca47d 929 FILE *fp;
taknokolat 12:083662bca47d 930 char parameter[20]; //文字列渡す用の配列
taknokolat 12:083662bca47d 931 int SDerrorcount = 0; //取得できなかった数を返す
taknokolat 12:083662bca47d 932 const char *paramNames[] = {
taknokolat 12:083662bca47d 933 "SERVO_NEUTRAL_R",
taknokolat 12:083662bca47d 934 "SERVO_NEUTRAL_L",
taknokolat 12:083662bca47d 935 "SERVO_HIGH_FORWARD_R",
taknokolat 12:083662bca47d 936 "SERVO_HIGH_FORWARD_L",
taknokolat 12:083662bca47d 937 "SERVO_SLOW_FORWARD_R",
taknokolat 12:083662bca47d 938 "SERVO_SLOW_FORWARD_L",
taknokolat 12:083662bca47d 939 "TURNTABLE_NEUTRAL",
taknokolat 12:083662bca47d 940 "MATCH_SPEED",
taknokolat 12:083662bca47d 941 "FOCUS_NEUTRAL",
taknokolat 12:083662bca47d 942 "CAMERA_DEG_A",
taknokolat 16:26cee2aaf61d 943 "CAMERA_DEG_B",
taknokolat 16:26cee2aaf61d 944 "PINT_SPEED",
HARUKIDELTA 17:83db05cab3d1 945 "PINT_WAIT",
taknokolat 19:949bab1e9451 946 "TURNTABLE_SPEED",
taknokolat 24:0ad1725c7849 947 "TIME360",
taknokolat 24:0ad1725c7849 948 "MATCH_WID",
taknokolat 20:011977a37394 949 "CAMERA_BOARD_WAIT"
taknokolat 12:083662bca47d 950 };
taknokolat 12:083662bca47d 951
taknokolat 12:083662bca47d 952 fp = fopen("/sd/option.txt","r");
taknokolat 12:083662bca47d 953
taknokolat 12:083662bca47d 954 if(fp != NULL){ //開けたら
taknokolat 12:083662bca47d 955 pc.printf("File was openned.\r\n");
taknokolat 12:083662bca47d 956 if(GetParameter(fp,paramNames[0],parameter)) *Servo_NEUTRAL_R = atof(parameter);
taknokolat 12:083662bca47d 957 else{ *Servo_NEUTRAL_R = servo_NEUTRAL_R;
taknokolat 12:083662bca47d 958 SDerrorcount++;
taknokolat 12:083662bca47d 959 }
taknokolat 12:083662bca47d 960 if(GetParameter(fp,paramNames[1],parameter)) *Servo_NEUTRAL_L = atof(parameter);
taknokolat 12:083662bca47d 961 else{ *Servo_NEUTRAL_L = servo_NEUTRAL_L;
taknokolat 12:083662bca47d 962 SDerrorcount++;
taknokolat 12:083662bca47d 963 }
taknokolat 12:083662bca47d 964 if(GetParameter(fp,paramNames[2],parameter)) *Servo_high_FORWARD_R = atof(parameter);
taknokolat 12:083662bca47d 965 else{ *Servo_high_FORWARD_R = servo_high_FORWARD_R;
taknokolat 12:083662bca47d 966 SDerrorcount++;
taknokolat 12:083662bca47d 967 }
taknokolat 12:083662bca47d 968 if(GetParameter(fp,paramNames[3],parameter)) *Servo_high_FORWARD_L = atof(parameter);
taknokolat 12:083662bca47d 969 else{ *Servo_high_FORWARD_L = servo_high_FORWARD_L;
taknokolat 12:083662bca47d 970 SDerrorcount++;
taknokolat 12:083662bca47d 971 }
taknokolat 12:083662bca47d 972 if(GetParameter(fp,paramNames[4],parameter)) *Servo_slow_FORWARD_R = atof(parameter);
taknokolat 12:083662bca47d 973 else{ *Servo_slow_FORWARD_R = servo_slow_FORWARD_R;
taknokolat 12:083662bca47d 974 SDerrorcount++;
taknokolat 12:083662bca47d 975 }
taknokolat 12:083662bca47d 976 if(GetParameter(fp,paramNames[5],parameter)) *Servo_slow_FORWARD_L = atof(parameter);
taknokolat 12:083662bca47d 977 else{ *Servo_slow_FORWARD_L = servo_slow_FORWARD_L;
taknokolat 12:083662bca47d 978 SDerrorcount++;
taknokolat 12:083662bca47d 979 }
taknokolat 12:083662bca47d 980
taknokolat 12:083662bca47d 981 if(GetParameter(fp,paramNames[6],parameter)) *Turntable_NEUTRAL = atof(parameter);
taknokolat 12:083662bca47d 982 else{ *Turntable_NEUTRAL = turntable_NEUTRAL;
taknokolat 12:083662bca47d 983 SDerrorcount++;
taknokolat 12:083662bca47d 984 }
taknokolat 12:083662bca47d 985 if(GetParameter(fp,paramNames[7],parameter)) *Matchspeed = atof(parameter);
taknokolat 12:083662bca47d 986 else{ *Matchspeed = matchspeed;
taknokolat 12:083662bca47d 987 SDerrorcount++;
taknokolat 12:083662bca47d 988 }
taknokolat 12:083662bca47d 989 if(GetParameter(fp,paramNames[8],parameter)) *Focus_NEUTRAL = atof(parameter);
taknokolat 12:083662bca47d 990 else{ *Focus_NEUTRAL = focus_NEUTRAL;
taknokolat 12:083662bca47d 991 SDerrorcount++;
taknokolat 12:083662bca47d 992 }
taknokolat 19:949bab1e9451 993 if(GetParameter(fp,paramNames[9],parameter)) *Camera_deg_A = atof(parameter);
taknokolat 12:083662bca47d 994 else{ *Camera_deg_A = camera_deg_A;
taknokolat 12:083662bca47d 995 SDerrorcount++;
taknokolat 12:083662bca47d 996 }
taknokolat 19:949bab1e9451 997 if(GetParameter(fp,paramNames[10],parameter)) *Camera_deg_B = atof(parameter);
taknokolat 12:083662bca47d 998 else{ *Camera_deg_B = camera_deg_B;
taknokolat 12:083662bca47d 999 SDerrorcount++;
taknokolat 12:083662bca47d 1000 }
taknokolat 19:949bab1e9451 1001 if(GetParameter(fp,paramNames[11],parameter)) *Pint_speed = atof(parameter);
taknokolat 16:26cee2aaf61d 1002 else{ *Pint_speed = pint_speed;
taknokolat 16:26cee2aaf61d 1003 SDerrorcount++;
taknokolat 16:26cee2aaf61d 1004 }
taknokolat 20:011977a37394 1005 if(GetParameter(fp,paramNames[12],parameter)) *Pint_wait = atof(parameter);
taknokolat 20:011977a37394 1006 else{ *Pint_wait = pint_wait;
taknokolat 16:26cee2aaf61d 1007 SDerrorcount++;
taknokolat 16:26cee2aaf61d 1008 }
taknokolat 19:949bab1e9451 1009 if(GetParameter(fp,paramNames[13],parameter)) *Turntable_speed = atof(parameter);
HARUKIDELTA 17:83db05cab3d1 1010 else{ *Turntable_speed = turntable_speed;
HARUKIDELTA 17:83db05cab3d1 1011 SDerrorcount++;
HARUKIDELTA 17:83db05cab3d1 1012 }
taknokolat 24:0ad1725c7849 1013 if(GetParameter(fp,paramNames[14],parameter)) *Time360 = atof(parameter);
taknokolat 24:0ad1725c7849 1014 else{ *Time360 = time360;
taknokolat 19:949bab1e9451 1015 SDerrorcount++;
taknokolat 19:949bab1e9451 1016 }
taknokolat 24:0ad1725c7849 1017 if(GetParameter(fp,paramNames[15],parameter)) *Match_wid = atof(parameter);
taknokolat 24:0ad1725c7849 1018 else{ *Match_wid = match_wid;
taknokolat 19:949bab1e9451 1019 SDerrorcount++;
taknokolat 19:949bab1e9451 1020 }
taknokolat 20:011977a37394 1021 if(GetParameter(fp,paramNames[16],parameter)) *Camera_board_wait = atof(parameter);
taknokolat 20:011977a37394 1022 else{ *Camera_board_wait = camera_board_wait;
taknokolat 20:011977a37394 1023 SDerrorcount++;
taknokolat 20:011977a37394 1024 }
taknokolat 12:083662bca47d 1025 fclose(fp);
taknokolat 12:083662bca47d 1026
taknokolat 12:083662bca47d 1027 }else{ //ファイルがなかったら
taknokolat 12:083662bca47d 1028 pc.printf("fp was null.\r\n");
taknokolat 12:083662bca47d 1029
taknokolat 12:083662bca47d 1030 *Servo_NEUTRAL_R = servo_NEUTRAL_R;
taknokolat 12:083662bca47d 1031 *Servo_NEUTRAL_L = servo_NEUTRAL_L;
taknokolat 12:083662bca47d 1032 *Servo_high_FORWARD_R = servo_high_FORWARD_R;
taknokolat 12:083662bca47d 1033 *Servo_high_FORWARD_L = servo_high_FORWARD_L;
taknokolat 12:083662bca47d 1034 *Servo_slow_FORWARD_R = servo_slow_FORWARD_R;
taknokolat 12:083662bca47d 1035 *Servo_slow_FORWARD_L = servo_slow_FORWARD_L;
taknokolat 12:083662bca47d 1036 *Turntable_NEUTRAL = turntable_NEUTRAL;
taknokolat 12:083662bca47d 1037 *Matchspeed = matchspeed;
taknokolat 12:083662bca47d 1038 *Focus_NEUTRAL = focus_NEUTRAL;
taknokolat 12:083662bca47d 1039 *Camera_deg_A = camera_deg_A;
taknokolat 12:083662bca47d 1040 *Camera_deg_B = camera_deg_B;
taknokolat 16:26cee2aaf61d 1041 *Pint_speed = pint_speed;
taknokolat 16:26cee2aaf61d 1042 *Pint_wait = pint_wait;
HARUKIDELTA 17:83db05cab3d1 1043 *Turntable_speed = turntable_speed;
taknokolat 24:0ad1725c7849 1044 *Time360 = time360;
taknokolat 24:0ad1725c7849 1045 *Match_wid = match_wid;
taknokolat 22:a19be3b505b7 1046 *Camera_board_wait = camera_board_wait;
taknokolat 12:083662bca47d 1047 SDerrorcount = -1;
taknokolat 12:083662bca47d 1048 }
taknokolat 12:083662bca47d 1049 pc.printf("SDsetup finished.\r\n");
taknokolat 12:083662bca47d 1050 if(SDerrorcount == 0) pc.printf("setting option is success\r\n");
taknokolat 12:083662bca47d 1051 else if(SDerrorcount == -1) pc.printf("ERROR 1. cannot open option\r\n");
taknokolat 12:083662bca47d 1052 else if(SDerrorcount > 0) pc.printf("ERROR 2. reading parameter is failed[%d]\r\n",SDerrorcount);
taknokolat 12:083662bca47d 1053
taknokolat 12:083662bca47d 1054 pc.printf("Servo_NEUTRAL_R = %d, Servo_NEUTRAL_L = %d\r\n", *Servo_NEUTRAL_R, *Servo_NEUTRAL_L);
taknokolat 13:b088f0db7158 1055 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 1056 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 1057 pc.printf("Turntable_NEUTRAL = %d, Matchspeed = %d\r\n", *Turntable_NEUTRAL, *Matchspeed);
taknokolat 13:b088f0db7158 1058 pc.printf("Focus_NEUTRAL = %d\r\n", *Focus_NEUTRAL);
taknokolat 13:b088f0db7158 1059 pc.printf("Camera_deg_A = %d, Camera_deg_B = %d\r\n", *Camera_deg_A, *Camera_deg_B);
taknokolat 16:26cee2aaf61d 1060 pc.printf("Pint_speed = %d, Pint_wait = %f\r\n", *Pint_speed, *Pint_wait);
HARUKIDELTA 17:83db05cab3d1 1061 pc.printf("Turntable_speed = %d\r\n",*Turntable_speed);
taknokolat 24:0ad1725c7849 1062 pc.printf("Time360 = %d, Match_wid = %d\r\n", *Time360, *Match_wid);
taknokolat 20:011977a37394 1063 pc.printf("Camera_board_wait = %d\r\n", *Camera_board_wait);
taknokolat 12:083662bca47d 1064
taknokolat 12:083662bca47d 1065 return SDerrorcount;
taknokolat 12:083662bca47d 1066 }
taknokolat 12:083662bca47d 1067 int GetParameter(FILE *fp, const char *paramName,char parameter[]){
taknokolat 12:083662bca47d 1068 int i=0, j=0;
taknokolat 12:083662bca47d 1069 int strmax = 200;
taknokolat 12:083662bca47d 1070 char str[strmax];
taknokolat 12:083662bca47d 1071
taknokolat 12:083662bca47d 1072 rewind(fp); //ファイル位置を先頭に
taknokolat 12:083662bca47d 1073 while(1){
taknokolat 12:083662bca47d 1074 if (fgets(str, strmax, fp) == NULL) {
taknokolat 12:083662bca47d 1075 return 0;
taknokolat 12:083662bca47d 1076 }
taknokolat 12:083662bca47d 1077 if (!strncmp(str, paramName, strlen(paramName))) {
taknokolat 12:083662bca47d 1078 while (str[i++] != '=') {}
taknokolat 12:083662bca47d 1079 while (str[i] != '\n') {
taknokolat 12:083662bca47d 1080 parameter[j++] = str[i++];
taknokolat 12:083662bca47d 1081 }
taknokolat 12:083662bca47d 1082 parameter[j] = '\0';
taknokolat 12:083662bca47d 1083 return 1;
taknokolat 12:083662bca47d 1084 }
taknokolat 12:083662bca47d 1085 }
taknokolat 12:083662bca47d 1086 }
taknokolat 12:083662bca47d 1087
taknokolat 12:083662bca47d 1088
taknokolat 6:166746820555 1089
taknokolat 4:67f705d42f1e 1090 void DebugPrint(){
taknokolat 4:67f705d42f1e 1091 //for(uint8_t i=0; i<3; i++) pc.printf("%3.2f\t",nowAngle[i]); //skipper地磁気センサ_デバック用
taknokolat 7:8989a4b84695 1092 //pc.printf("%3.2f\t",nowAngle[2]);
taknokolat 7:8989a4b84695 1093 //pc.printf("%3.2f\t",nowAngle_HMC); //HMC
taknokolat 7:8989a4b84695 1094 //pc.printf("\r\n");
taknokolat 6:166746820555 1095 }