skipper_raspi_uart_test

Dependencies:   mbed MPU6050_2 HMC5883L_4 SDFileSystem3

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