skipper_raspi_uart_test

Dependencies:   mbed MPU6050_2 HMC5883L_4 SDFileSystem3

Committer:
taknokolat
Date:
Mon Mar 04 17:28:47 2019 +0000
Revision:
39:3faddfc87351
Parent:
38:7c323abc62fb
Child:
40:917b50b9e863
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 39:3faddfc87351 77 bool jevoisFlag = false;
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 1:290e621741fd 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 37:8e273677500d 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 22:a19be3b505b7 477 //pc.printf("Move Board Finish\r\n");
taknokolat 7:8989a4b84695 478 return;
taknokolat 7:8989a4b84695 479 }
taknokolat 7:8989a4b84695 480
taknokolat 7:8989a4b84695 481 void MatchPosition(){
taknokolat 32:ab030832d180 482 NVIC_DisableIRQ(USART6_IRQn);
taknokolat 32:ab030832d180 483 NVIC_DisableIRQ(USART2_IRQn);
taknokolat 24:0ad1725c7849 484
taknokolat 32:ab030832d180 485 int TurnTime ;
taknokolat 32:ab030832d180 486
taknokolat 32:ab030832d180 487 TurnTime = g_CameraDegCounter - ReturnCount;
taknokolat 32:ab030832d180 488
taknokolat 32:ab030832d180 489 if(TurnTime >=0){
taknokolat 32:ab030832d180 490 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL + Turntable_speed);
taknokolat 38:7c323abc62fb 491 //wait_ms(Camera_board_wait*TurnTime);
taknokolat 38:7c323abc62fb 492 pc.printf("MatchPosition\r\n");
taknokolat 38:7c323abc62fb 493 while(BoardCheck == 0){
taknokolat 38:7c323abc62fb 494 }
taknokolat 32:ab030832d180 495 }else{
taknokolat 32:ab030832d180 496 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL - Turntable_speed);
taknokolat 38:7c323abc62fb 497 //wait_ms(-Camera_board_wait*TurnTime);
taknokolat 38:7c323abc62fb 498 pc.printf("MatchPosition\r\n");
taknokolat 38:7c323abc62fb 499 while(BoardCheck == 0){
taknokolat 38:7c323abc62fb 500 }
taknokolat 32:ab030832d180 501 }
taknokolat 24:0ad1725c7849 502 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL);
taknokolat 24:0ad1725c7849 503
taknokolat 38:7c323abc62fb 504 if(jevoisFlag == false ){
taknokolat 37:8e273677500d 505 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL + Turntable_speed);
taknokolat 37:8e273677500d 506 wait_ms((float)Time360/(float)2);
taknokolat 37:8e273677500d 507 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL);
taknokolat 38:7c323abc62fb 508 }
taknokolat 37:8e273677500d 509
taknokolat 22:a19be3b505b7 510 int SetLoop=0;
taknokolat 22:a19be3b505b7 511
taknokolat 22:a19be3b505b7 512 while(SetLoop<30){
taknokolat 7:8989a4b84695 513 SensingMPU();
taknokolat 37:8e273677500d 514 wait_ms(10);
taknokolat 24:0ad1725c7849 515 //SensingHMC();
taknokolat 24:0ad1725c7849 516 //wait_ms(20);
taknokolat 22:a19be3b505b7 517 //DebugPrint();
taknokolat 22:a19be3b505b7 518 SetLoop++;
taknokolat 22:a19be3b505b7 519 //pc.printf("nowAngle_HMC=%f\tMPU=%f\r\n",nowAngle_HMC,nowAngle[YAW]);
taknokolat 22:a19be3b505b7 520
taknokolat 22:a19be3b505b7 521 }
taknokolat 7:8989a4b84695 522
taknokolat 24:0ad1725c7849 523 static float TargetDeg = 0;
taknokolat 24:0ad1725c7849 524
taknokolat 32:ab030832d180 525 TargetDeg = 360*(float)Camera_board_wait*((float)g_CameraDegCounter - ReturnCount)/(float)Time360;
taknokolat 24:0ad1725c7849 526
taknokolat 37:8e273677500d 527 if(TargetDeg > 360)TargetDeg = TargetDeg - 360;
taknokolat 37:8e273677500d 528 if(TargetDeg < 0)TargetDeg = TargetDeg + 360;
taknokolat 33:5f77118eacd5 529
taknokolat 37:8e273677500d 530 float HighTargetYaw = nowAngle[YAW] + TargetDeg + Match_wid;
taknokolat 37:8e273677500d 531 float LowTargetYaw = nowAngle[YAW] + TargetDeg - Match_wid;
taknokolat 21:ca8f35e24e66 532
taknokolat 22:a19be3b505b7 533
taknokolat 37:8e273677500d 534 if(HighTargetYaw >= 360.0f) HighTargetYaw = HighTargetYaw - 360.0f;
taknokolat 37:8e273677500d 535 if(LowTargetYaw >= 360.0f) LowTargetYaw = LowTargetYaw - 360.0f;
taknokolat 37:8e273677500d 536 if(LowTargetYaw < 0.0f) LowTargetYaw = LowTargetYaw + 360.0f;
taknokolat 21:ca8f35e24e66 537
taknokolat 22:a19be3b505b7 538 pc.printf("\r\nnow=%f\t,high=%f\t,low=%f\r\n",nowAngle[YAW],HighTargetYaw,LowTargetYaw);
taknokolat 22:a19be3b505b7 539
taknokolat 24:0ad1725c7849 540 MoveCansat('r');
taknokolat 22:a19be3b505b7 541
taknokolat 22:a19be3b505b7 542 if(HighTargetYaw-LowTargetYaw<0){
taknokolat 22:a19be3b505b7 543 while(nowAngle[YAW] > HighTargetYaw && nowAngle[YAW] < LowTargetYaw){
taknokolat 22:a19be3b505b7 544 //MoveCansat('r');
taknokolat 22:a19be3b505b7 545 SensingMPU();
taknokolat 35:0f89eff001a7 546 wait_ms(10);
taknokolat 22:a19be3b505b7 547 pc.printf("nowAngle_MPU=%f\r\n",nowAngle[YAW]);
taknokolat 22:a19be3b505b7 548 }
taknokolat 22:a19be3b505b7 549 }else{
taknokolat 22:a19be3b505b7 550 while(nowAngle[YAW] > HighTargetYaw || nowAngle[YAW] < LowTargetYaw){
taknokolat 22:a19be3b505b7 551 //MoveCansat('r');
taknokolat 22:a19be3b505b7 552 SensingMPU();
taknokolat 35:0f89eff001a7 553 wait_ms(10);
taknokolat 22:a19be3b505b7 554 pc.printf("nowAngle_MPU=%f\r\n",nowAngle[YAW]);
taknokolat 22:a19be3b505b7 555 }
taknokolat 7:8989a4b84695 556 }
taknokolat 24:0ad1725c7849 557 g_CameraDegCounter = 0;
taknokolat 32:ab030832d180 558
taknokolat 39:3faddfc87351 559 g_fp = fopen( "/sd/Datalog01.txt","a" );
taknokolat 39:3faddfc87351 560 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 561 fclose(g_fp);
taknokolat 39:3faddfc87351 562
taknokolat 32:ab030832d180 563 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 32:ab030832d180 564 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 7:8989a4b84695 565 return;
taknokolat 7:8989a4b84695 566 }
taknokolat 7:8989a4b84695 567
taknokolat 7:8989a4b84695 568 void FocusAdjust(){
taknokolat 35:0f89eff001a7 569 if(jevoisFlag==true) NVIC_DisableIRQ(USART6_IRQn);
taknokolat 35:0f89eff001a7 570 else NVIC_DisableIRQ(USART2_IRQn);
taknokolat 35:0f89eff001a7 571
taknokolat 31:210cc32d3175 572 if(FocusFlag == false){
taknokolat 33:5f77118eacd5 573 servoCameraPinto.pulsewidth_us(Focus_NEUTRAL + Pint_speed);
taknokolat 33:5f77118eacd5 574 servoR.pulsewidth_us(Servo_NEUTRAL_R); //servo initialize
taknokolat 33:5f77118eacd5 575 servoL.pulsewidth_us(Servo_NEUTRAL_L);
taknokolat 36:e13fca1666a4 576 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL);
taknokolat 33:5f77118eacd5 577 wait(Pint_wait);
taknokolat 31:210cc32d3175 578 FocusFlag = !FocusFlag;
taknokolat 31:210cc32d3175 579 }else{
taknokolat 33:5f77118eacd5 580 servoCameraPinto.pulsewidth_us(Focus_NEUTRAL - Pint_speed);
taknokolat 33:5f77118eacd5 581 servoR.pulsewidth_us(Servo_NEUTRAL_R); //servo initialize
taknokolat 33:5f77118eacd5 582 servoL.pulsewidth_us(Servo_NEUTRAL_L);
taknokolat 36:e13fca1666a4 583 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL);
taknokolat 33:5f77118eacd5 584 wait(Pint_wait);
taknokolat 31:210cc32d3175 585 FocusFlag = !FocusFlag;
taknokolat 31:210cc32d3175 586 }
HARUKIDELTA 17:83db05cab3d1 587 servoCameraPinto.pulsewidth_us(Focus_NEUTRAL);
taknokolat 11:d44d137831b9 588
taknokolat 7:8989a4b84695 589 return;
taknokolat 15:1519fccfcae3 590 }
taknokolat 7:8989a4b84695 591
taknokolat 1:290e621741fd 592 void getSF_Serial_jevois(){
taknokolat 22:a19be3b505b7 593
taknokolat 22:a19be3b505b7 594 //pc.printf("jevois\r\n");
taknokolat 1:290e621741fd 595
taknokolat 1:290e621741fd 596
taknokolat 1:290e621741fd 597 static char SFbuf[16]={'Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q'};
taknokolat 1:290e621741fd 598
taknokolat 1:290e621741fd 599 static int bufcounter=0;
taknokolat 1:290e621741fd 600
taknokolat 1:290e621741fd 601
taknokolat 1:290e621741fd 602
taknokolat 1:290e621741fd 603 if(pc.readable()) { // 受信確認
taknokolat 1:290e621741fd 604
taknokolat 1:290e621741fd 605 SFbuf[bufcounter] = pc.getc(); // 1文字取り出し
taknokolat 1:290e621741fd 606 if(SFbuf[0]!='S'){
taknokolat 1:290e621741fd 607 //pc.printf("x");
taknokolat 1:290e621741fd 608 return;
taknokolat 1:290e621741fd 609 }
taknokolat 1:290e621741fd 610
taknokolat 1:290e621741fd 611
taknokolat 1:290e621741fd 612
taknokolat 22:a19be3b505b7 613 pc.printf("%c",SFbuf[bufcounter]);
taknokolat 1:290e621741fd 614
Skykon 3:c18342e4fddd 615 if(SFbuf[0]=='S' && bufcounter<5)bufcounter++;
taknokolat 1:290e621741fd 616
taknokolat 1:290e621741fd 617 if(bufcounter==5 && SFbuf[4]=='F'){
taknokolat 1:290e621741fd 618
taknokolat 1:290e621741fd 619 g_landingcommand = SFbuf[1];
taknokolat 2:f30666d7838b 620 wait_ms(31);//信号が速すぎることによる割り込み防止
taknokolat 1:290e621741fd 621 //pc.printf("%c",g_landingcommand);
taknokolat 1:290e621741fd 622 //wait_ms(20);
taknokolat 1:290e621741fd 623 //if(g_landingcommand=='Y')g_SerialTargetYAW = ConvertByteintoFloat(SFbuf[2], SFbuf[3]);
taknokolat 1:290e621741fd 624 bufcounter = 0;
taknokolat 1:290e621741fd 625 memset(SFbuf, 0, sizeof(SFbuf));
taknokolat 1:290e621741fd 626 NVIC_ClearPendingIRQ(USART2_IRQn);
taknokolat 1:290e621741fd 627 //pc.printf("command = %c, commandYAW = %f\r\n", g_landingcommand, g_SerialTargetYAW);
taknokolat 1:290e621741fd 628 }
taknokolat 1:290e621741fd 629
taknokolat 1:290e621741fd 630 else if(bufcounter>=5){
taknokolat 1:290e621741fd 631 //pc.printf("Communication Falsed.\r\n");
taknokolat 1:290e621741fd 632 memset(SFbuf, 0, sizeof(SFbuf));
taknokolat 1:290e621741fd 633 bufcounter = 0;
taknokolat 1:290e621741fd 634 NVIC_ClearPendingIRQ(USART2_IRQn);
taknokolat 1:290e621741fd 635 }
taknokolat 1:290e621741fd 636 }
taknokolat 1:290e621741fd 637
taknokolat 1:290e621741fd 638
taknokolat 1:290e621741fd 639 }
taknokolat 1:290e621741fd 640
taknokolat 1:290e621741fd 641
taknokolat 12:083662bca47d 642 void getSF_Serial_pi(){
taknokolat 2:f30666d7838b 643
taknokolat 7:8989a4b84695 644 //NVIC_DisableIRQ(USART2_IRQn);
taknokolat 1:290e621741fd 645
taknokolat 1:290e621741fd 646 static char SFbuf[16]={'Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q'};
taknokolat 1:290e621741fd 647
taknokolat 1:290e621741fd 648 static int bufcounter=0;
taknokolat 1:290e621741fd 649
taknokolat 1:290e621741fd 650
taknokolat 1:290e621741fd 651
taknokolat 1:290e621741fd 652 if(pc2.readable()) { // 受信確認
taknokolat 1:290e621741fd 653
taknokolat 1:290e621741fd 654 SFbuf[bufcounter] = pc2.getc(); // 1文字取り出し
taknokolat 1:290e621741fd 655 if(SFbuf[0]!='S'){
taknokolat 1:290e621741fd 656 //pc.printf("x");
taknokolat 1:290e621741fd 657 return;
taknokolat 1:290e621741fd 658 }
taknokolat 1:290e621741fd 659
taknokolat 1:290e621741fd 660
taknokolat 1:290e621741fd 661
taknokolat 30:90252dc48c1a 662 pc.printf("%c",SFbuf[bufcounter]);
taknokolat 1:290e621741fd 663
taknokolat 1:290e621741fd 664 if(SFbuf[0]=='S'&&bufcounter<5)bufcounter++;
taknokolat 1:290e621741fd 665
taknokolat 1:290e621741fd 666 if(bufcounter==5 && SFbuf[4]=='F'){
taknokolat 1:290e621741fd 667
taknokolat 1:290e621741fd 668 g_landingcommand = SFbuf[1];
taknokolat 2:f30666d7838b 669 wait_ms(31);//信号が速すぎることによる割り込み防止
taknokolat 1:290e621741fd 670 //pc.printf("%c",g_landingcommand);
taknokolat 1:290e621741fd 671 //wait_ms(20);
taknokolat 1:290e621741fd 672 //if(g_landingcommand=='Y')g_SerialTargetYAW = ConvertByteintoFloat(SFbuf[2], SFbuf[3]);
taknokolat 1:290e621741fd 673 bufcounter = 0;
taknokolat 1:290e621741fd 674 memset(SFbuf, 0, sizeof(SFbuf));
taknokolat 1:290e621741fd 675 NVIC_ClearPendingIRQ(USART2_IRQn);
taknokolat 1:290e621741fd 676 //pc.printf("command = %c, commandYAW = %f\r\n", g_landingcommand, g_SerialTargetYAW);
taknokolat 1:290e621741fd 677 }
taknokolat 1:290e621741fd 678
taknokolat 1:290e621741fd 679 else if(bufcounter>=5){
taknokolat 1:290e621741fd 680 //pc.printf("Communication Falsed.\r\n");
taknokolat 1:290e621741fd 681 memset(SFbuf, 0, sizeof(SFbuf));
taknokolat 1:290e621741fd 682 bufcounter = 0;
taknokolat 1:290e621741fd 683 NVIC_ClearPendingIRQ(USART2_IRQn);
taknokolat 1:290e621741fd 684 }
taknokolat 1:290e621741fd 685 }
taknokolat 2:f30666d7838b 686
taknokolat 7:8989a4b84695 687 //NVIC_EnableIRQ(USART2_IRQn);
taknokolat 1:290e621741fd 688
taknokolat 12:083662bca47d 689 }
taknokolat 1:290e621741fd 690
Skykon 3:c18342e4fddd 691
Skykon 3:c18342e4fddd 692 void setup(){
HARUKIDELTA 23:29b2722bd753 693
HARUKIDELTA 23:29b2722bd753 694 led1 = 1;
HARUKIDELTA 23:29b2722bd753 695 led2 = 1;
taknokolat 37:8e273677500d 696 //led3 = 1;
HARUKIDELTA 23:29b2722bd753 697 led4 = 1;
HARUKIDELTA 26:ea86e69563b5 698
HARUKIDELTA 26:ea86e69563b5 699 servoR.pulsewidth_us(Servo_NEUTRAL_R); //servo initialize
HARUKIDELTA 26:ea86e69563b5 700 servoL.pulsewidth_us(Servo_NEUTRAL_L);
HARUKIDELTA 26:ea86e69563b5 701 servoTurnTable.pulsewidth_us(Turntable_NEUTRAL);
taknokolat 29:5d239812ace6 702 servoCameradeg.pulsewidth_us(Camera_deg_B);
HARUKIDELTA 26:ea86e69563b5 703 servoCameraPinto.pulsewidth_us(focus_NEUTRAL);
Skykon 3:c18342e4fddd 704
taknokolat 13:b088f0db7158 705 SetOptions(&Servo_NEUTRAL_R, &Servo_NEUTRAL_L,
taknokolat 12:083662bca47d 706 &Servo_high_FORWARD_R, &Servo_high_FORWARD_L,
taknokolat 12:083662bca47d 707 &Servo_slow_FORWARD_R,&Servo_slow_FORWARD_L,
taknokolat 12:083662bca47d 708 &Turntable_NEUTRAL,&Matchspeed,&Focus_NEUTRAL,
taknokolat 16:26cee2aaf61d 709 &Camera_deg_A, &Camera_deg_B,
HARUKIDELTA 17:83db05cab3d1 710 &Pint_speed,&Pint_wait,
taknokolat 19:949bab1e9451 711 &Turntable_speed,
taknokolat 24:0ad1725c7849 712 &Time360, &Match_wid,
taknokolat 20:011977a37394 713 &Camera_board_wait
taknokolat 13:b088f0db7158 714 );
taknokolat 12:083662bca47d 715
Skykon 3:c18342e4fddd 716 Init_sensors();
Skykon 3:c18342e4fddd 717 //switch2.rise(ResetTrim);
Skykon 3:c18342e4fddd 718
taknokolat 30:90252dc48c1a 719 //NVIC_SetPriority(USART6_IRQn,0);
taknokolat 7:8989a4b84695 720 //NVIC_SetPriority(EXTI0_IRQn,1);
taknokolat 7:8989a4b84695 721 //NVIC_SetPriority(TIM5_IRQn,2);
taknokolat 7:8989a4b84695 722 //NVIC_SetPriority(EXTI9_5_IRQn,3);
taknokolat 7:8989a4b84695 723 //NVIC_SetPriority(USART2_IRQn,4);
taknokolat 7:8989a4b84695 724
taknokolat 30:90252dc48c1a 725 NVIC_SetPriority(USART6_IRQn,0);//割り込み優先度
taknokolat 7:8989a4b84695 726 NVIC_SetPriority(USART2_IRQn,1);
taknokolat 7:8989a4b84695 727
Skykon 3:c18342e4fddd 728 DisplayClock();
Skykon 3:c18342e4fddd 729 t.start();
Skykon 3:c18342e4fddd 730
Skykon 3:c18342e4fddd 731 pc.printf("MPU calibration start\r\n");
taknokolat 24:0ad1725c7849 732 //pc.printf("HMC calibration start\r\n");
Skykon 3:c18342e4fddd 733
Skykon 3:c18342e4fddd 734 float offsetstart = t.read();
Skykon 3:c18342e4fddd 735 while(t.read() - offsetstart < 26){
Skykon 3:c18342e4fddd 736 SensingMPU();
taknokolat 24:0ad1725c7849 737 //SensingHMC();
Skykon 3:c18342e4fddd 738 for(uint8_t i=0; i<3; i++) pc.printf("%3.2f\t",nowAngle[i]);
taknokolat 24:0ad1725c7849 739 //pc.printf("\t%3.2f\t",nowAngle_HMC);
Skykon 3:c18342e4fddd 740 pc.printf("\r\n");
HARUKIDELTA 23:29b2722bd753 741 led1 = !led1;
HARUKIDELTA 23:29b2722bd753 742 led2 = !led2;
taknokolat 37:8e273677500d 743 //led3 = !led3;
HARUKIDELTA 23:29b2722bd753 744 led4 = !led4;
Skykon 3:c18342e4fddd 745 }
Skykon 3:c18342e4fddd 746
Skykon 3:c18342e4fddd 747 FirstROLL = nowAngle[ROLL];
Skykon 3:c18342e4fddd 748 FirstPITCH = nowAngle[PITCH];
Skykon 3:c18342e4fddd 749 nowAngle[ROLL] -=FirstROLL;
Skykon 3:c18342e4fddd 750 nowAngle[PITCH] -=FirstPITCH;
taknokolat 6:166746820555 751 FirstYAW = nowAngle[YAW];
taknokolat 6:166746820555 752 nowAngle[YAW] -= FirstYAW;
taknokolat 6:166746820555 753
taknokolat 24:0ad1725c7849 754 //g_FirstYAW_HMC = nowAngle_HMC;
taknokolat 24:0ad1725c7849 755 //nowAngle_HMC -=g_FirstYAW_HMC;
taknokolat 24:0ad1725c7849 756 //if(nowAngle_HMC<0)nowAngle_HMC+=360;
Skykon 3:c18342e4fddd 757
HARUKIDELTA 23:29b2722bd753 758 led1 = 0;
HARUKIDELTA 23:29b2722bd753 759 led2 = 0;
taknokolat 37:8e273677500d 760 //led3 = 0;
HARUKIDELTA 23:29b2722bd753 761 led4 = 0;
HARUKIDELTA 23:29b2722bd753 762
Skykon 3:c18342e4fddd 763 wait(0.2);
Skykon 3:c18342e4fddd 764
HARUKIDELTA 26:ea86e69563b5 765
HARUKIDELTA 26:ea86e69563b5 766 g_fp = fopen( "/sd/Datalog01.txt" ,"a" );
HARUKIDELTA 26:ea86e69563b5 767 if( g_fp == NULL ) {
taknokolat 37:8e273677500d 768 pc.printf( "File open error!!!\r\n" );
HARUKIDELTA 26:ea86e69563b5 769 }
HARUKIDELTA 27:f67efcee6509 770 fprintf(g_fp,"\r\n-------------------------\r\n");
HARUKIDELTA 26:ea86e69563b5 771 fprintf(g_fp,"All initialized.\r\n");
HARUKIDELTA 26:ea86e69563b5 772 fclose( g_fp );
HARUKIDELTA 26:ea86e69563b5 773
HARUKIDELTA 26:ea86e69563b5 774
Skykon 3:c18342e4fddd 775 pc.printf("All initialized\r\n");
taknokolat 4:67f705d42f1e 776 setupFlag=true;
taknokolat 1:290e621741fd 777 }
taknokolat 1:290e621741fd 778
Skykon 3:c18342e4fddd 779
Skykon 3:c18342e4fddd 780 void SensingMPU(){
Skykon 3:c18342e4fddd 781 //static int16_t deltaT = 0, t_start = 0;
Skykon 3:c18342e4fddd 782 //t_start = t.read_us();
Skykon 3:c18342e4fddd 783
taknokolat 7:8989a4b84695 784 float rpy[3] = {0};
Skykon 3:c18342e4fddd 785 static uint16_t count_changeRPY = 0;
Skykon 3:c18342e4fddd 786 static bool flg_checkoutlier = false;
taknokolat 30:90252dc48c1a 787 NVIC_DisableIRQ(USART6_IRQn);
Skykon 3:c18342e4fddd 788 NVIC_DisableIRQ(USART2_IRQn);
Skykon 3:c18342e4fddd 789 NVIC_DisableIRQ(TIM5_IRQn);
Skykon 3:c18342e4fddd 790 NVIC_DisableIRQ(EXTI0_IRQn);
Skykon 3:c18342e4fddd 791 NVIC_DisableIRQ(EXTI9_5_IRQn);
Skykon 3:c18342e4fddd 792
Skykon 3:c18342e4fddd 793 mpu6050.getRollPitchYaw_Skipper(rpy);
Skykon 3:c18342e4fddd 794
taknokolat 30:90252dc48c1a 795 NVIC_EnableIRQ(USART6_IRQn);
Skykon 3:c18342e4fddd 796 NVIC_EnableIRQ(USART2_IRQn);
Skykon 3:c18342e4fddd 797 NVIC_EnableIRQ(TIM5_IRQn);
Skykon 3:c18342e4fddd 798 NVIC_EnableIRQ(EXTI0_IRQn);
Skykon 3:c18342e4fddd 799 NVIC_EnableIRQ(EXTI9_5_IRQn);
Skykon 3:c18342e4fddd 800
Skykon 3:c18342e4fddd 801
Skykon 3:c18342e4fddd 802 //外れ値対策
taknokolat 37:8e273677500d 803 for(uint8_t i=0; i<3; i++) rpy[i] *= 180.0f/(float)PI;
Skykon 3:c18342e4fddd 804 rpy[ROLL] -= FirstROLL;
Skykon 3:c18342e4fddd 805 rpy[PITCH] -= FirstPITCH;
taknokolat 4:67f705d42f1e 806 if(!setupFlag){
taknokolat 4:67f705d42f1e 807 rpy[YAW] -= FirstYAW;
taknokolat 4:67f705d42f1e 808 }else{
taknokolat 4:67f705d42f1e 809 if(rpy[YAW] >= FirstYAW){
taknokolat 4:67f705d42f1e 810 rpy[YAW] -= FirstYAW;
taknokolat 4:67f705d42f1e 811 }else{
taknokolat 4:67f705d42f1e 812 rpy[YAW] += 360.0f;
taknokolat 4:67f705d42f1e 813 rpy[YAW] -= FirstYAW;
taknokolat 4:67f705d42f1e 814 }
taknokolat 4:67f705d42f1e 815 }
Skykon 3:c18342e4fddd 816
Skykon 3:c18342e4fddd 817 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 818 if(!flg_checkoutlier || count_changeRPY >= 2){
Skykon 3:c18342e4fddd 819 for(uint8_t i=0; i<3; i++){
taknokolat 34:0c2b67b31b12 820 if(rpy[i] > nowAngle[i]-180 && rpy[i] < nowAngle[i]+180){
taknokolat 34:0c2b67b31b12 821 nowAngle[i] = (rpy[i] + nowAngle[i])/2.0f; //2つの移動平均
taknokolat 34:0c2b67b31b12 822 }else{
taknokolat 34:0c2b67b31b12 823 nowAngle[i] = rpy[i];
taknokolat 34:0c2b67b31b12 824 }
Skykon 3:c18342e4fddd 825 }
Skykon 3:c18342e4fddd 826 count_changeRPY = 0;
Skykon 3:c18342e4fddd 827 }else count_changeRPY++;
Skykon 3:c18342e4fddd 828 flg_checkoutlier = false;
Skykon 3:c18342e4fddd 829
Skykon 3:c18342e4fddd 830 }
Skykon 3:c18342e4fddd 831
Skykon 3:c18342e4fddd 832
Skykon 3:c18342e4fddd 833 void Init_sensors(){
Skykon 3:c18342e4fddd 834 if(mpu6050.setup() == -1){
Skykon 3:c18342e4fddd 835 pc.printf("failed initialize\r\n");
Skykon 3:c18342e4fddd 836 }
Skykon 3:c18342e4fddd 837 }
Skykon 3:c18342e4fddd 838
Skykon 3:c18342e4fddd 839
Skykon 3:c18342e4fddd 840 void DisplayClock(){
Skykon 3:c18342e4fddd 841 pc.printf("System Clock = %d[MHz]\r\n", HAL_RCC_GetSysClockFreq()/1000000);
Skykon 3:c18342e4fddd 842 pc.printf("HCLK Clock = %d[MHz]\r\n", HAL_RCC_GetHCLKFreq()/1000000);
Skykon 3:c18342e4fddd 843 pc.printf("PCLK1 Clock = %d[MHz]\r\n", HAL_RCC_GetPCLK1Freq()/1000000);
Skykon 3:c18342e4fddd 844 pc.printf("PCLK2 Clock = %d[MHz]\r\n", HAL_RCC_GetPCLK2Freq()/1000000);
Skykon 3:c18342e4fddd 845 pc.printf("\r\n");
taknokolat 4:67f705d42f1e 846 }
taknokolat 6:166746820555 847
taknokolat 24:0ad1725c7849 848 /*void SensingHMC(){
taknokolat 6:166746820555 849 //static int16_t deltaT = 0, t_start = 0;
taknokolat 6:166746820555 850 //t_start = t.read_us();
taknokolat 6:166746820555 851
taknokolat 7:8989a4b84695 852 float rpy=0;
taknokolat 6:166746820555 853 static uint16_t count_changeRPY = 0;
taknokolat 6:166746820555 854 static bool flg_checkoutlier = false;
taknokolat 30:90252dc48c1a 855 NVIC_DisableIRQ(USART6_IRQn);
taknokolat 6:166746820555 856 NVIC_DisableIRQ(USART2_IRQn);
taknokolat 19:949bab1e9451 857 //NVIC_DisableIRQ(TIM5_IRQn);
taknokolat 19:949bab1e9451 858 //NVIC_DisableIRQ(EXTI0_IRQn);
taknokolat 19:949bab1e9451 859 //NVIC_DisableIRQ(EXTI9_5_IRQn);
taknokolat 4:67f705d42f1e 860
taknokolat 24:0ad1725c7849 861 rpy= compass.getHeadingXYDeg(Time360,Match_wid);
taknokolat 6:166746820555 862
taknokolat 30:90252dc48c1a 863 NVIC_EnableIRQ(USART6_IRQn);
taknokolat 6:166746820555 864 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 19:949bab1e9451 865 //NVIC_EnableIRQ(TIM5_IRQn);
taknokolat 19:949bab1e9451 866 //NVIC_EnableIRQ(EXTI0_IRQn);
taknokolat 19:949bab1e9451 867 //NVIC_EnableIRQ(EXTI9_5_IRQn);
taknokolat 6:166746820555 868
taknokolat 6:166746820555 869
taknokolat 6:166746820555 870 //外れ値対策
taknokolat 6:166746820555 871 //rpy*= 180.0f/PI;
taknokolat 6:166746820555 872 if(!setupFlag){
taknokolat 6:166746820555 873 rpy -= g_FirstYAW_HMC;
taknokolat 6:166746820555 874 }else{
taknokolat 6:166746820555 875 if(rpy >= g_FirstYAW_HMC){
taknokolat 6:166746820555 876 rpy -= g_FirstYAW_HMC;
taknokolat 6:166746820555 877 }else{
taknokolat 6:166746820555 878 rpy += 360.0f;
taknokolat 6:166746820555 879 rpy -= g_FirstYAW_HMC;
taknokolat 6:166746820555 880 }
taknokolat 6:166746820555 881 }
taknokolat 6:166746820555 882
taknokolat 6:166746820555 883 if(rpy < nowAngle_HMC-10 || rpy > nowAngle_HMC+10) {flg_checkoutlier = true;}
taknokolat 6:166746820555 884 if(!flg_checkoutlier || count_changeRPY >= 2){
taknokolat 6:166746820555 885
taknokolat 6:166746820555 886 nowAngle_HMC = (rpy + nowAngle_HMC)/2.0f; //2つの移動平均
taknokolat 6:166746820555 887
taknokolat 6:166746820555 888 count_changeRPY = 0;
taknokolat 6:166746820555 889 }else count_changeRPY++;
taknokolat 6:166746820555 890 flg_checkoutlier = false;
taknokolat 6:166746820555 891
taknokolat 24:0ad1725c7849 892 }*/
taknokolat 12:083662bca47d 893
taknokolat 12:083662bca47d 894 int SetOptions(int *Servo_NEUTRAL_R, int *Servo_NEUTRAL_L,
taknokolat 12:083662bca47d 895 int *Servo_high_FORWARD_R, int *Servo_high_FORWARD_L,
taknokolat 12:083662bca47d 896 int *Servo_slow_FORWARD_R,int *Servo_slow_FORWARD_L,
taknokolat 12:083662bca47d 897 int *Turntable_NEUTRAL,int *Matchspeed,int *Focus_NEUTRAL,
taknokolat 16:26cee2aaf61d 898 int *Camera_deg_A, int *Camera_deg_B,
HARUKIDELTA 17:83db05cab3d1 899 int *Pint_speed, float *Pint_wait,
taknokolat 19:949bab1e9451 900 int *Turntable_speed,
taknokolat 24:0ad1725c7849 901 int *Time360, int *Match_wid,
taknokolat 20:011977a37394 902 int *Camera_board_wait
taknokolat 12:083662bca47d 903 ){
taknokolat 12:083662bca47d 904
taknokolat 12:083662bca47d 905 pc.printf("SDsetup start.\r\n");
taknokolat 12:083662bca47d 906
taknokolat 12:083662bca47d 907 FILE *fp;
taknokolat 12:083662bca47d 908 char parameter[20]; //文字列渡す用の配列
taknokolat 12:083662bca47d 909 int SDerrorcount = 0; //取得できなかった数を返す
taknokolat 12:083662bca47d 910 const char *paramNames[] = {
taknokolat 12:083662bca47d 911 "SERVO_NEUTRAL_R",
taknokolat 12:083662bca47d 912 "SERVO_NEUTRAL_L",
taknokolat 12:083662bca47d 913 "SERVO_HIGH_FORWARD_R",
taknokolat 12:083662bca47d 914 "SERVO_HIGH_FORWARD_L",
taknokolat 12:083662bca47d 915 "SERVO_SLOW_FORWARD_R",
taknokolat 12:083662bca47d 916 "SERVO_SLOW_FORWARD_L",
taknokolat 12:083662bca47d 917 "TURNTABLE_NEUTRAL",
taknokolat 12:083662bca47d 918 "MATCH_SPEED",
taknokolat 12:083662bca47d 919 "FOCUS_NEUTRAL",
taknokolat 12:083662bca47d 920 "CAMERA_DEG_A",
taknokolat 16:26cee2aaf61d 921 "CAMERA_DEG_B",
taknokolat 16:26cee2aaf61d 922 "PINT_SPEED",
HARUKIDELTA 17:83db05cab3d1 923 "PINT_WAIT",
taknokolat 19:949bab1e9451 924 "TURNTABLE_SPEED",
taknokolat 24:0ad1725c7849 925 "TIME360",
taknokolat 24:0ad1725c7849 926 "MATCH_WID",
taknokolat 20:011977a37394 927 "CAMERA_BOARD_WAIT"
taknokolat 12:083662bca47d 928 };
taknokolat 12:083662bca47d 929
taknokolat 12:083662bca47d 930 fp = fopen("/sd/option.txt","r");
taknokolat 12:083662bca47d 931
taknokolat 12:083662bca47d 932 if(fp != NULL){ //開けたら
taknokolat 12:083662bca47d 933 pc.printf("File was openned.\r\n");
taknokolat 12:083662bca47d 934 if(GetParameter(fp,paramNames[0],parameter)) *Servo_NEUTRAL_R = atof(parameter);
taknokolat 12:083662bca47d 935 else{ *Servo_NEUTRAL_R = servo_NEUTRAL_R;
taknokolat 12:083662bca47d 936 SDerrorcount++;
taknokolat 12:083662bca47d 937 }
taknokolat 12:083662bca47d 938 if(GetParameter(fp,paramNames[1],parameter)) *Servo_NEUTRAL_L = atof(parameter);
taknokolat 12:083662bca47d 939 else{ *Servo_NEUTRAL_L = servo_NEUTRAL_L;
taknokolat 12:083662bca47d 940 SDerrorcount++;
taknokolat 12:083662bca47d 941 }
taknokolat 12:083662bca47d 942 if(GetParameter(fp,paramNames[2],parameter)) *Servo_high_FORWARD_R = atof(parameter);
taknokolat 12:083662bca47d 943 else{ *Servo_high_FORWARD_R = servo_high_FORWARD_R;
taknokolat 12:083662bca47d 944 SDerrorcount++;
taknokolat 12:083662bca47d 945 }
taknokolat 12:083662bca47d 946 if(GetParameter(fp,paramNames[3],parameter)) *Servo_high_FORWARD_L = atof(parameter);
taknokolat 12:083662bca47d 947 else{ *Servo_high_FORWARD_L = servo_high_FORWARD_L;
taknokolat 12:083662bca47d 948 SDerrorcount++;
taknokolat 12:083662bca47d 949 }
taknokolat 12:083662bca47d 950 if(GetParameter(fp,paramNames[4],parameter)) *Servo_slow_FORWARD_R = atof(parameter);
taknokolat 12:083662bca47d 951 else{ *Servo_slow_FORWARD_R = servo_slow_FORWARD_R;
taknokolat 12:083662bca47d 952 SDerrorcount++;
taknokolat 12:083662bca47d 953 }
taknokolat 12:083662bca47d 954 if(GetParameter(fp,paramNames[5],parameter)) *Servo_slow_FORWARD_L = atof(parameter);
taknokolat 12:083662bca47d 955 else{ *Servo_slow_FORWARD_L = servo_slow_FORWARD_L;
taknokolat 12:083662bca47d 956 SDerrorcount++;
taknokolat 12:083662bca47d 957 }
taknokolat 12:083662bca47d 958
taknokolat 12:083662bca47d 959 if(GetParameter(fp,paramNames[6],parameter)) *Turntable_NEUTRAL = atof(parameter);
taknokolat 12:083662bca47d 960 else{ *Turntable_NEUTRAL = turntable_NEUTRAL;
taknokolat 12:083662bca47d 961 SDerrorcount++;
taknokolat 12:083662bca47d 962 }
taknokolat 12:083662bca47d 963 if(GetParameter(fp,paramNames[7],parameter)) *Matchspeed = atof(parameter);
taknokolat 12:083662bca47d 964 else{ *Matchspeed = matchspeed;
taknokolat 12:083662bca47d 965 SDerrorcount++;
taknokolat 12:083662bca47d 966 }
taknokolat 12:083662bca47d 967 if(GetParameter(fp,paramNames[8],parameter)) *Focus_NEUTRAL = atof(parameter);
taknokolat 12:083662bca47d 968 else{ *Focus_NEUTRAL = focus_NEUTRAL;
taknokolat 12:083662bca47d 969 SDerrorcount++;
taknokolat 12:083662bca47d 970 }
taknokolat 19:949bab1e9451 971 if(GetParameter(fp,paramNames[9],parameter)) *Camera_deg_A = atof(parameter);
taknokolat 12:083662bca47d 972 else{ *Camera_deg_A = camera_deg_A;
taknokolat 12:083662bca47d 973 SDerrorcount++;
taknokolat 12:083662bca47d 974 }
taknokolat 19:949bab1e9451 975 if(GetParameter(fp,paramNames[10],parameter)) *Camera_deg_B = atof(parameter);
taknokolat 12:083662bca47d 976 else{ *Camera_deg_B = camera_deg_B;
taknokolat 12:083662bca47d 977 SDerrorcount++;
taknokolat 12:083662bca47d 978 }
taknokolat 19:949bab1e9451 979 if(GetParameter(fp,paramNames[11],parameter)) *Pint_speed = atof(parameter);
taknokolat 16:26cee2aaf61d 980 else{ *Pint_speed = pint_speed;
taknokolat 16:26cee2aaf61d 981 SDerrorcount++;
taknokolat 16:26cee2aaf61d 982 }
taknokolat 20:011977a37394 983 if(GetParameter(fp,paramNames[12],parameter)) *Pint_wait = atof(parameter);
taknokolat 20:011977a37394 984 else{ *Pint_wait = pint_wait;
taknokolat 16:26cee2aaf61d 985 SDerrorcount++;
taknokolat 16:26cee2aaf61d 986 }
taknokolat 19:949bab1e9451 987 if(GetParameter(fp,paramNames[13],parameter)) *Turntable_speed = atof(parameter);
HARUKIDELTA 17:83db05cab3d1 988 else{ *Turntable_speed = turntable_speed;
HARUKIDELTA 17:83db05cab3d1 989 SDerrorcount++;
HARUKIDELTA 17:83db05cab3d1 990 }
taknokolat 24:0ad1725c7849 991 if(GetParameter(fp,paramNames[14],parameter)) *Time360 = atof(parameter);
taknokolat 24:0ad1725c7849 992 else{ *Time360 = time360;
taknokolat 19:949bab1e9451 993 SDerrorcount++;
taknokolat 19:949bab1e9451 994 }
taknokolat 24:0ad1725c7849 995 if(GetParameter(fp,paramNames[15],parameter)) *Match_wid = atof(parameter);
taknokolat 24:0ad1725c7849 996 else{ *Match_wid = match_wid;
taknokolat 19:949bab1e9451 997 SDerrorcount++;
taknokolat 19:949bab1e9451 998 }
taknokolat 20:011977a37394 999 if(GetParameter(fp,paramNames[16],parameter)) *Camera_board_wait = atof(parameter);
taknokolat 20:011977a37394 1000 else{ *Camera_board_wait = camera_board_wait;
taknokolat 20:011977a37394 1001 SDerrorcount++;
taknokolat 20:011977a37394 1002 }
taknokolat 12:083662bca47d 1003 fclose(fp);
taknokolat 12:083662bca47d 1004
taknokolat 12:083662bca47d 1005 }else{ //ファイルがなかったら
taknokolat 12:083662bca47d 1006 pc.printf("fp was null.\r\n");
taknokolat 12:083662bca47d 1007
taknokolat 12:083662bca47d 1008 *Servo_NEUTRAL_R = servo_NEUTRAL_R;
taknokolat 12:083662bca47d 1009 *Servo_NEUTRAL_L = servo_NEUTRAL_L;
taknokolat 12:083662bca47d 1010 *Servo_high_FORWARD_R = servo_high_FORWARD_R;
taknokolat 12:083662bca47d 1011 *Servo_high_FORWARD_L = servo_high_FORWARD_L;
taknokolat 12:083662bca47d 1012 *Servo_slow_FORWARD_R = servo_slow_FORWARD_R;
taknokolat 12:083662bca47d 1013 *Servo_slow_FORWARD_L = servo_slow_FORWARD_L;
taknokolat 12:083662bca47d 1014 *Turntable_NEUTRAL = turntable_NEUTRAL;
taknokolat 12:083662bca47d 1015 *Matchspeed = matchspeed;
taknokolat 12:083662bca47d 1016 *Focus_NEUTRAL = focus_NEUTRAL;
taknokolat 12:083662bca47d 1017 *Camera_deg_A = camera_deg_A;
taknokolat 12:083662bca47d 1018 *Camera_deg_B = camera_deg_B;
taknokolat 16:26cee2aaf61d 1019 *Pint_speed = pint_speed;
taknokolat 16:26cee2aaf61d 1020 *Pint_wait = pint_wait;
HARUKIDELTA 17:83db05cab3d1 1021 *Turntable_speed = turntable_speed;
taknokolat 24:0ad1725c7849 1022 *Time360 = time360;
taknokolat 24:0ad1725c7849 1023 *Match_wid = match_wid;
taknokolat 22:a19be3b505b7 1024 *Camera_board_wait = camera_board_wait;
taknokolat 12:083662bca47d 1025 SDerrorcount = -1;
taknokolat 12:083662bca47d 1026 }
taknokolat 12:083662bca47d 1027 pc.printf("SDsetup finished.\r\n");
taknokolat 12:083662bca47d 1028 if(SDerrorcount == 0) pc.printf("setting option is success\r\n");
taknokolat 12:083662bca47d 1029 else if(SDerrorcount == -1) pc.printf("ERROR 1. cannot open option\r\n");
taknokolat 12:083662bca47d 1030 else if(SDerrorcount > 0) pc.printf("ERROR 2. reading parameter is failed[%d]\r\n",SDerrorcount);
taknokolat 12:083662bca47d 1031
taknokolat 12:083662bca47d 1032 pc.printf("Servo_NEUTRAL_R = %d, Servo_NEUTRAL_L = %d\r\n", *Servo_NEUTRAL_R, *Servo_NEUTRAL_L);
taknokolat 13:b088f0db7158 1033 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 1034 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 1035 pc.printf("Turntable_NEUTRAL = %d, Matchspeed = %d\r\n", *Turntable_NEUTRAL, *Matchspeed);
taknokolat 13:b088f0db7158 1036 pc.printf("Focus_NEUTRAL = %d\r\n", *Focus_NEUTRAL);
taknokolat 13:b088f0db7158 1037 pc.printf("Camera_deg_A = %d, Camera_deg_B = %d\r\n", *Camera_deg_A, *Camera_deg_B);
taknokolat 16:26cee2aaf61d 1038 pc.printf("Pint_speed = %d, Pint_wait = %f\r\n", *Pint_speed, *Pint_wait);
HARUKIDELTA 17:83db05cab3d1 1039 pc.printf("Turntable_speed = %d\r\n",*Turntable_speed);
taknokolat 24:0ad1725c7849 1040 pc.printf("Time360 = %d, Match_wid = %d\r\n", *Time360, *Match_wid);
taknokolat 20:011977a37394 1041 pc.printf("Camera_board_wait = %d\r\n", *Camera_board_wait);
taknokolat 12:083662bca47d 1042
taknokolat 12:083662bca47d 1043 return SDerrorcount;
taknokolat 12:083662bca47d 1044 }
taknokolat 12:083662bca47d 1045 int GetParameter(FILE *fp, const char *paramName,char parameter[]){
taknokolat 12:083662bca47d 1046 int i=0, j=0;
taknokolat 12:083662bca47d 1047 int strmax = 200;
taknokolat 12:083662bca47d 1048 char str[strmax];
taknokolat 12:083662bca47d 1049
taknokolat 12:083662bca47d 1050 rewind(fp); //ファイル位置を先頭に
taknokolat 12:083662bca47d 1051 while(1){
taknokolat 12:083662bca47d 1052 if (fgets(str, strmax, fp) == NULL) {
taknokolat 12:083662bca47d 1053 return 0;
taknokolat 12:083662bca47d 1054 }
taknokolat 12:083662bca47d 1055 if (!strncmp(str, paramName, strlen(paramName))) {
taknokolat 12:083662bca47d 1056 while (str[i++] != '=') {}
taknokolat 12:083662bca47d 1057 while (str[i] != '\n') {
taknokolat 12:083662bca47d 1058 parameter[j++] = str[i++];
taknokolat 12:083662bca47d 1059 }
taknokolat 12:083662bca47d 1060 parameter[j] = '\0';
taknokolat 12:083662bca47d 1061 return 1;
taknokolat 12:083662bca47d 1062 }
taknokolat 12:083662bca47d 1063 }
taknokolat 12:083662bca47d 1064 }
taknokolat 12:083662bca47d 1065
taknokolat 12:083662bca47d 1066
taknokolat 6:166746820555 1067
taknokolat 4:67f705d42f1e 1068 void DebugPrint(){
taknokolat 4:67f705d42f1e 1069 //for(uint8_t i=0; i<3; i++) pc.printf("%3.2f\t",nowAngle[i]); //skipper地磁気センサ_デバック用
taknokolat 7:8989a4b84695 1070 //pc.printf("%3.2f\t",nowAngle[2]);
taknokolat 7:8989a4b84695 1071 //pc.printf("%3.2f\t",nowAngle_HMC); //HMC
taknokolat 7:8989a4b84695 1072 //pc.printf("\r\n");
taknokolat 6:166746820555 1073 }