skipper_raspi_uart_test

Dependencies:   mbed MPU6050_2 HMC5883L_4 SDFileSystem3

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