SDの設定が反映されるように修正

Dependencies:   mbed MPU6050_2 HMC5883L_2 SDFileSystem3

Committer:
taknokolat
Date:
Tue Feb 12 13:16:29 2019 +0000
Revision:
13:b088f0db7158
Parent:
12:083662bca47d
Child:
14:90e9b44eb819
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
taknokolat 11:d44d137831b9 11 #define servo_NEUTRAL_R 1614
taknokolat 11:d44d137831b9 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_low_FORWARD_R 1560 //RasPi速さ調節用
taknokolat 12:083662bca47d 16 #define servo_high_FORWARD_R 1860
taknokolat 12:083662bca47d 17 #define servo_low_FORWARD_L 1560
taknokolat 12:083662bca47d 18 #define servo_high_FORWARD_L 1860
taknokolat 12:083662bca47d 19 #define servo_low_back_R 1360
taknokolat 12:083662bca47d 20 #define servo_high_back_R 1160
taknokolat 12:083662bca47d 21 #define servo_low_back_L 1360
taknokolat 12:083662bca47d 22 #define servo_high_back_L 1160
taknokolat 12:083662bca47d 23 #define turntable_NEUTRAL 1180 //カメラ台座のサーボ
taknokolat 12:083662bca47d 24 #define matchspeed 1500 + 100 //カメラと方向を合わせるときの車輪の速度
taknokolat 12:083662bca47d 25 #define focus_NEUTRAL 1455 //焦点合わせ用サーボ
taknokolat 12:083662bca47d 26 #define camera_deg_A 1400 //カメラ角度調整
taknokolat 12:083662bca47d 27 #define camera_deg_B 1800
HARUKIDELTA 0:84ddd6d354e1 28
HARUKIDELTA 0:84ddd6d354e1 29 #define MOVE_NEUTRAL 0
HARUKIDELTA 0:84ddd6d354e1 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 12:083662bca47d 63 int *Camera_deg_A, int *Camera_deg_B
taknokolat 12:083662bca47d 64 );
taknokolat 12:083662bca47d 65
taknokolat 6:166746820555 66 static float nowAngle[3] = {0,0,0},nowAngle_HMC=0;
taknokolat 6:166746820555 67 float FirstROLL = 0.0, FirstPITCH = 0.0 ,FirstYAW = 0.0,g_FirstYAW_HMC;
Skykon 3:c18342e4fddd 68
taknokolat 7:8989a4b84695 69 bool setupFlag = false;
taknokolat 7:8989a4b84695 70 bool CameraDegFlag = false;
taknokolat 7:8989a4b84695 71 bool jevoisFlag = true;
taknokolat 4:67f705d42f1e 72
Skykon 3:c18342e4fddd 73 enum Angle{ROLL, PITCH, YAW}; //yaw:北を0とした絶対角度
Skykon 3:c18342e4fddd 74
Skykon 3:c18342e4fddd 75 Timer t;
Skykon 3:c18342e4fddd 76
taknokolat 11:d44d137831b9 77 RawSerial pc(PA_2,PA_3,115200); //uart2
taknokolat 11:d44d137831b9 78 //pa2:UART2_TX,pa3:UART2_RX
taknokolat 12:083662bca47d 79 RawSerial pc2(PA_11,PA_12,115200); //uart1
taknokolat 11:d44d137831b9 80 //pb6:UART1_TX,pb7:UART1_RX
taknokolat 11:d44d137831b9 81
HARUKIDELTA 5:8bfe95431ec0 82 //PWM pin宣言
taknokolat 6:166746820555 83 PwmOut servoR(PC_6); //TIM3_CH1 車輪右
taknokolat 6:166746820555 84 PwmOut servoL(PC_7); //TIM3_CH2 車輪左
HARUKIDELTA 5:8bfe95431ec0 85 PwmOut servoTurnTable(PB_0); //TIM3_CH3 カメラ台回転Servo
HARUKIDELTA 5:8bfe95431ec0 86 PwmOut servoCameradeg(PB_1); //TIM3_CH4 カメラ角度調節Servo
HARUKIDELTA 5:8bfe95431ec0 87 PwmOut servoCameraPinto(PB_6); //TIM4_CH1 カメラピント合わせ
HARUKIDELTA 5:8bfe95431ec0 88 PwmOut servoCameramount(PA_6); //skipperウラ カメラマウント起動
HARUKIDELTA 5:8bfe95431ec0 89 PwmOut servoGetUP(PC_8); //skipperウラ 起き上がり動作
Skykon 3:c18342e4fddd 90
HARUKIDELTA 5:8bfe95431ec0 91 /*通信用のpinは
HARUKIDELTA 5:8bfe95431ec0 92 PA_3(UART2_Rx) skipperウラ
HARUKIDELTA 5:8bfe95431ec0 93 PA_12(UART6_Rx) skipperオモテ USB端子より
HARUKIDELTA 5:8bfe95431ec0 94 PB_7 (UART1_Rx) skipperオモテ 6番目 TIM4_CH2
HARUKIDELTA 5:8bfe95431ec0 95 */
HARUKIDELTA 5:8bfe95431ec0 96
HARUKIDELTA 5:8bfe95431ec0 97 /*超音波はRaspberryPiに積む*/
HARUKIDELTA 5:8bfe95431ec0 98
HARUKIDELTA 5:8bfe95431ec0 99 //外付けコンパス
taknokolat 6:166746820555 100 HMC5883L compass(PB_9, PB_8); //コンパスセンサー TIM4_CH3とCH4
HARUKIDELTA 0:84ddd6d354e1 101
taknokolat 2:f30666d7838b 102 char g_landingcommand='N';
taknokolat 1:290e621741fd 103
Skykon 3:c18342e4fddd 104 //MPU_check用
Skykon 3:c18342e4fddd 105 MPU6050DMP6 mpu6050(PC_0,&pc);
Skykon 3:c18342e4fddd 106
Skykon 3:c18342e4fddd 107
HARUKIDELTA 0:84ddd6d354e1 108 int main() {
taknokolat 1:290e621741fd 109
Skykon 3:c18342e4fddd 110 //MPU_check
Skykon 3:c18342e4fddd 111 setup();
Skykon 3:c18342e4fddd 112
taknokolat 11:d44d137831b9 113 servoCameradeg.pulsewidth_us(1400);
taknokolat 11:d44d137831b9 114
taknokolat 1:290e621741fd 115 // シリアル通信受信の割り込みイベント登録
taknokolat 1:290e621741fd 116 pc.attach(getSF_Serial_jevois, Serial::RxIrq);
taknokolat 12:083662bca47d 117 pc2.attach(getSF_Serial_pi, Serial::RxIrq);
taknokolat 1:290e621741fd 118
HARUKIDELTA 0:84ddd6d354e1 119 while(1) {
taknokolat 7:8989a4b84695 120 if(jevoisFlag==true) NVIC_DisableIRQ(USART1_IRQn);
taknokolat 7:8989a4b84695 121 else NVIC_DisableIRQ(USART2_IRQn);
taknokolat 8:d11a59d2a2f1 122
taknokolat 10:63fe920595a7 123 MoveCameraBoard();
taknokolat 10:63fe920595a7 124
taknokolat 7:8989a4b84695 125 if(g_landingcommand!='N') MatchPosition();
taknokolat 8:d11a59d2a2f1 126
taknokolat 8:d11a59d2a2f1 127 if(jevoisFlag==true) NVIC_DisableIRQ(USART1_IRQn);
taknokolat 8:d11a59d2a2f1 128 else NVIC_DisableIRQ(USART2_IRQn);
taknokolat 8:d11a59d2a2f1 129
taknokolat 7:8989a4b84695 130 MoveCansat(g_landingcommand);
Skykon 3:c18342e4fddd 131 wait_ms(23);
taknokolat 8:d11a59d2a2f1 132
taknokolat 7:8989a4b84695 133 if(jevoisFlag==true) NVIC_EnableIRQ(USART1_IRQn);
taknokolat 7:8989a4b84695 134 else NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 0:84ddd6d354e1 135 }
HARUKIDELTA 0:84ddd6d354e1 136 }
HARUKIDELTA 0:84ddd6d354e1 137
Skykon 3:c18342e4fddd 138
taknokolat 1:290e621741fd 139 void MoveCansat(char g_landingcommand)
HARUKIDELTA 0:84ddd6d354e1 140 {
taknokolat 2:f30666d7838b 141 //NVIC_DisableIRQ(USART1_IRQn);
taknokolat 7:8989a4b84695 142 //NVIC_DisableIRQ(USART2_IRQn);
taknokolat 1:290e621741fd 143 switch(g_landingcommand){
taknokolat 2:f30666d7838b 144 case 'N': //MOVE_NEUTRAL
HARUKIDELTA 0:84ddd6d354e1 145 servoR.pulsewidth_us(servo_NEUTRAL_R);
HARUKIDELTA 0:84ddd6d354e1 146 servoL.pulsewidth_us(servo_NEUTRAL_L);
taknokolat 2:f30666d7838b 147 //NVIC_EnableIRQ(USART1_IRQn);
taknokolat 7:8989a4b84695 148 //NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 0:84ddd6d354e1 149 break;
taknokolat 1:290e621741fd 150
taknokolat 2:f30666d7838b 151 case 'Y': //MOVE_FORWARD
taknokolat 12:083662bca47d 152 servoR.pulsewidth_us(servo_high_FORWARD_R);
taknokolat 12:083662bca47d 153 servoL.pulsewidth_us(servo_high_FORWARD_L);
taknokolat 2:f30666d7838b 154 //NVIC_EnableIRQ(USART1_IRQn);
taknokolat 7:8989a4b84695 155 //NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 0:84ddd6d354e1 156 break;
taknokolat 1:290e621741fd 157
taknokolat 12:083662bca47d 158 case 'l': //MOVE_LEFT Low Speed
taknokolat 12:083662bca47d 159 servoR.pulsewidth_us(servo_low_FORWARD_R);
taknokolat 12:083662bca47d 160 //NVIC_EnableIRQ(USART1_IRQn);
taknokolat 12:083662bca47d 161 //NVIC_EnableIRQ(USART2_IRQn);
taknokolat 12:083662bca47d 162
taknokolat 12:083662bca47d 163 case 'L': //MOVE_LEFT High Speed
taknokolat 12:083662bca47d 164 servoR.pulsewidth_us(servo_high_FORWARD_R);
taknokolat 2:f30666d7838b 165 //NVIC_EnableIRQ(USART1_IRQn);
taknokolat 7:8989a4b84695 166 //NVIC_EnableIRQ(USART2_IRQn);
taknokolat 1:290e621741fd 167
taknokolat 12:083662bca47d 168 case 'r': //MOVE_RIGHT Low Speed
taknokolat 12:083662bca47d 169 servoL.pulsewidth_us(servo_low_FORWARD_L);
taknokolat 2:f30666d7838b 170 //NVIC_EnableIRQ(USART1_IRQn);
taknokolat 7:8989a4b84695 171 //NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 0:84ddd6d354e1 172 break;
taknokolat 12:083662bca47d 173
taknokolat 12:083662bca47d 174 case 'R': //MOVE_RIGHT High Speed
taknokolat 12:083662bca47d 175 servoL.pulsewidth_us(servo_high_FORWARD_L);
taknokolat 2:f30666d7838b 176 //NVIC_EnableIRQ(USART1_IRQn);
taknokolat 7:8989a4b84695 177 //NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 0:84ddd6d354e1 178 break;
taknokolat 1:290e621741fd 179
taknokolat 1:290e621741fd 180 case 'G': //GOAL_FORWARD
HARUKIDELTA 0:84ddd6d354e1 181 servoR.pulsewidth_us(servo_slow_FORWARD_R);
HARUKIDELTA 0:84ddd6d354e1 182 servoL.pulsewidth_us(servo_slow_FORWARD_L);
taknokolat 2:f30666d7838b 183 //NVIC_EnableIRQ(USART1_IRQn);
taknokolat 7:8989a4b84695 184 //NVIC_EnableIRQ(USART2_IRQn);
taknokolat 7:8989a4b84695 185 break;
taknokolat 12:083662bca47d 186
taknokolat 12:083662bca47d 187 case '1': //MOVE_FORWARD Speed Level 1
taknokolat 12:083662bca47d 188 servoR.pulsewidth_us(servo_high_FORWARD_R);
taknokolat 12:083662bca47d 189 servoL.pulsewidth_us(servo_high_FORWARD_L);
taknokolat 12:083662bca47d 190 //NVIC_EnableIRQ(USART1_IRQn);
taknokolat 12:083662bca47d 191 wait(1);
taknokolat 12:083662bca47d 192 do{
taknokolat 12:083662bca47d 193 }while((nowAngle[PITCH]<20&&nowAngle[PITCH]>-20)&&(nowAngle[ROLL]<20&&nowAngle[ROLL]>-20));
taknokolat 12:083662bca47d 194 //NVIC_EnableIRQ(USART2_IRQn);
taknokolat 12:083662bca47d 195 break;
taknokolat 12:083662bca47d 196
taknokolat 12:083662bca47d 197 case '2': //MOVE_FORWARD Speed Level 2
taknokolat 12:083662bca47d 198 servoR.pulsewidth_us(servo_high_FORWARD_R);
taknokolat 12:083662bca47d 199 servoL.pulsewidth_us(servo_high_FORWARD_L);
taknokolat 12:083662bca47d 200 //NVIC_EnableIRQ(USART1_IRQn);
taknokolat 12:083662bca47d 201 wait(2);
taknokolat 12:083662bca47d 202 do{
taknokolat 12:083662bca47d 203 }while((nowAngle[PITCH]<20&&nowAngle[PITCH]>-20)&&(nowAngle[ROLL]<20&&nowAngle[ROLL]>-20));
taknokolat 12:083662bca47d 204 //NVIC_EnableIRQ(USART2_IRQn);
taknokolat 12:083662bca47d 205 break;
taknokolat 12:083662bca47d 206
taknokolat 12:083662bca47d 207 case '3': //MOVE_FORWARD Speed Level 3
taknokolat 12:083662bca47d 208 servoR.pulsewidth_us(servo_high_FORWARD_R);
taknokolat 12:083662bca47d 209 servoL.pulsewidth_us(servo_high_FORWARD_L);
taknokolat 12:083662bca47d 210 //NVIC_EnableIRQ(USART1_IRQn);
taknokolat 12:083662bca47d 211 wait(3);
taknokolat 12:083662bca47d 212 do{
taknokolat 12:083662bca47d 213 }while((nowAngle[PITCH]<20&&nowAngle[PITCH]>-20)&&(nowAngle[ROLL]<20&&nowAngle[ROLL]>-20));
taknokolat 12:083662bca47d 214 //NVIC_EnableIRQ(USART2_IRQn);
taknokolat 12:083662bca47d 215 break;
taknokolat 12:083662bca47d 216
taknokolat 12:083662bca47d 217 case '4': //MOVE_FORWARD Speed Level 4
taknokolat 12:083662bca47d 218 servoR.pulsewidth_us(servo_high_FORWARD_R);
taknokolat 12:083662bca47d 219 servoL.pulsewidth_us(servo_high_FORWARD_L);
taknokolat 12:083662bca47d 220 //NVIC_EnableIRQ(USART1_IRQn);
taknokolat 12:083662bca47d 221 wait(4);
taknokolat 12:083662bca47d 222 do{
taknokolat 12:083662bca47d 223 }while((nowAngle[PITCH]<20&&nowAngle[PITCH]>-20)&&(nowAngle[ROLL]<20&&nowAngle[ROLL]>-20));
taknokolat 12:083662bca47d 224 //NVIC_EnableIRQ(USART2_IRQn);
taknokolat 12:083662bca47d 225 break;
taknokolat 7:8989a4b84695 226
taknokolat 12:083662bca47d 227 case '5': //MOVE_FORWARD Speed Level 5
taknokolat 12:083662bca47d 228 servoR.pulsewidth_us(servo_high_FORWARD_R);
taknokolat 12:083662bca47d 229 servoL.pulsewidth_us(servo_high_FORWARD_L);
taknokolat 7:8989a4b84695 230 //NVIC_EnableIRQ(USART1_IRQn);
taknokolat 7:8989a4b84695 231 wait(5);
taknokolat 10:63fe920595a7 232 do{
taknokolat 10:63fe920595a7 233 }while((nowAngle[PITCH]<20&&nowAngle[PITCH]>-20)&&(nowAngle[ROLL]<20&&nowAngle[ROLL]>-20));
taknokolat 7:8989a4b84695 234 //NVIC_EnableIRQ(USART2_IRQn);
taknokolat 7:8989a4b84695 235 break;
taknokolat 7:8989a4b84695 236
taknokolat 7:8989a4b84695 237 case 'M': //MatchPosition
taknokolat 12:083662bca47d 238 servoR.pulsewidth_us(matchspeed);
taknokolat 7:8989a4b84695 239 //NVIC_EnableIRQ(USART1_IRQn);
taknokolat 7:8989a4b84695 240 //NVIC_EnableIRQ(USART2_IRQn);
taknokolat 7:8989a4b84695 241 break;
taknokolat 7:8989a4b84695 242
taknokolat 12:083662bca47d 243 case 'P': //jevoisからraspberry piへの切り替え
taknokolat 7:8989a4b84695 244 jevoisFlag = false;
taknokolat 7:8989a4b84695 245 //NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 0:84ddd6d354e1 246 break;
taknokolat 12:083662bca47d 247
taknokolat 12:083662bca47d 248 case 'S':
taknokolat 12:083662bca47d 249 /*RasPiからの超音波判定(プログラムスタート部)*/
taknokolat 12:083662bca47d 250 break;
taknokolat 1:290e621741fd 251
taknokolat 1:290e621741fd 252 default :
taknokolat 2:f30666d7838b 253 //NVIC_EnableIRQ(USART1_IRQn);
taknokolat 7:8989a4b84695 254 //NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 0:84ddd6d354e1 255 break;
taknokolat 1:290e621741fd 256
HARUKIDELTA 0:84ddd6d354e1 257 }
taknokolat 7:8989a4b84695 258
HARUKIDELTA 0:84ddd6d354e1 259 return;
taknokolat 1:290e621741fd 260 }
taknokolat 1:290e621741fd 261
taknokolat 7:8989a4b84695 262 void MoveCameraBoard(){
taknokolat 7:8989a4b84695 263 MoveCansat('N');
taknokolat 10:63fe920595a7 264 g_landingcommand='N';
taknokolat 11:d44d137831b9 265 servoTurnTable.pulsewidth_us(1800);
taknokolat 11:d44d137831b9 266 wait_ms(600);
taknokolat 12:083662bca47d 267 servoTurnTable.pulsewidth_us(turntable_NEUTRAL);
taknokolat 7:8989a4b84695 268 if(jevoisFlag == true) FocusAdjust();
taknokolat 7:8989a4b84695 269 else wait(1);
taknokolat 7:8989a4b84695 270
taknokolat 7:8989a4b84695 271 if(g_landingcommand!='N') return;
taknokolat 7:8989a4b84695 272 if(!CameraDegFlag){
taknokolat 7:8989a4b84695 273 servoCameradeg.pulsewidth_us(1800);
taknokolat 7:8989a4b84695 274 CameraDegFlag=!CameraDegFlag;
taknokolat 7:8989a4b84695 275 }else{
taknokolat 11:d44d137831b9 276 servoCameradeg.pulsewidth_us(1400);
taknokolat 7:8989a4b84695 277 CameraDegFlag = !CameraDegFlag;
taknokolat 7:8989a4b84695 278 }
taknokolat 7:8989a4b84695 279
taknokolat 7:8989a4b84695 280 if(jevoisFlag == true) FocusAdjust();
taknokolat 7:8989a4b84695 281 else wait(1);
taknokolat 7:8989a4b84695 282
taknokolat 7:8989a4b84695 283 return;
taknokolat 7:8989a4b84695 284 }
taknokolat 7:8989a4b84695 285
taknokolat 7:8989a4b84695 286 void MatchPosition(){
taknokolat 7:8989a4b84695 287 SensingMPU();
taknokolat 7:8989a4b84695 288 SensingHMC();
taknokolat 7:8989a4b84695 289 DebugPrint();
taknokolat 7:8989a4b84695 290
taknokolat 9:21cd5d18ad9e 291 while(nowAngle[YAW] <= nowAngle_HMC+5 && nowAngle[YAW] >= nowAngle_HMC-5){
taknokolat 7:8989a4b84695 292 MoveCansat('M');
taknokolat 9:21cd5d18ad9e 293 SensingMPU();
taknokolat 7:8989a4b84695 294 }
taknokolat 7:8989a4b84695 295 return;
taknokolat 7:8989a4b84695 296 }
taknokolat 7:8989a4b84695 297
taknokolat 7:8989a4b84695 298 void FocusAdjust(){
taknokolat 11:d44d137831b9 299 servoCameraPinto.pulsewidth_us(Focus_NEUTRAL-200);
taknokolat 11:d44d137831b9 300 pc.printf("set\r\n");
taknokolat 11:d44d137831b9 301 wait(1);
taknokolat 7:8989a4b84695 302
taknokolat 11:d44d137831b9 303 servoCameraPinto.pulsewidth_us(Focus_NEUTRAL+30);
taknokolat 11:d44d137831b9 304 pc.printf("check\r\n");
taknokolat 11:d44d137831b9 305 wait(3);
taknokolat 11:d44d137831b9 306 servoCameraPinto.pulsewidth_us(Focus_NEUTRAL);
taknokolat 11:d44d137831b9 307
taknokolat 7:8989a4b84695 308 return;
taknokolat 7:8989a4b84695 309 }
taknokolat 7:8989a4b84695 310
taknokolat 1:290e621741fd 311 void getSF_Serial_jevois(){
taknokolat 1:290e621741fd 312
taknokolat 1:290e621741fd 313
taknokolat 1:290e621741fd 314 static char SFbuf[16]={'Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q'};
taknokolat 1:290e621741fd 315
taknokolat 1:290e621741fd 316 static int bufcounter=0;
taknokolat 1:290e621741fd 317
taknokolat 1:290e621741fd 318
taknokolat 1:290e621741fd 319
taknokolat 1:290e621741fd 320 if(pc.readable()) { // 受信確認
taknokolat 1:290e621741fd 321
taknokolat 1:290e621741fd 322 SFbuf[bufcounter] = pc.getc(); // 1文字取り出し
taknokolat 1:290e621741fd 323 if(SFbuf[0]!='S'){
taknokolat 1:290e621741fd 324 //pc.printf("x");
taknokolat 1:290e621741fd 325 return;
taknokolat 1:290e621741fd 326 }
taknokolat 1:290e621741fd 327
taknokolat 1:290e621741fd 328
taknokolat 1:290e621741fd 329
taknokolat 1:290e621741fd 330 //pc.printf("%c",SFbuf[bufcounter]);
taknokolat 1:290e621741fd 331
Skykon 3:c18342e4fddd 332 if(SFbuf[0]=='S' && bufcounter<5)bufcounter++;
taknokolat 1:290e621741fd 333
taknokolat 1:290e621741fd 334 if(bufcounter==5 && SFbuf[4]=='F'){
taknokolat 1:290e621741fd 335
taknokolat 1:290e621741fd 336 g_landingcommand = SFbuf[1];
taknokolat 2:f30666d7838b 337 wait_ms(31);//信号が速すぎることによる割り込み防止
taknokolat 1:290e621741fd 338 //pc.printf("%c",g_landingcommand);
taknokolat 1:290e621741fd 339 //wait_ms(20);
taknokolat 1:290e621741fd 340 //if(g_landingcommand=='Y')g_SerialTargetYAW = ConvertByteintoFloat(SFbuf[2], SFbuf[3]);
taknokolat 1:290e621741fd 341 bufcounter = 0;
taknokolat 1:290e621741fd 342 memset(SFbuf, 0, sizeof(SFbuf));
taknokolat 1:290e621741fd 343 NVIC_ClearPendingIRQ(USART2_IRQn);
taknokolat 1:290e621741fd 344 //pc.printf("command = %c, commandYAW = %f\r\n", g_landingcommand, g_SerialTargetYAW);
taknokolat 1:290e621741fd 345 }
taknokolat 1:290e621741fd 346
taknokolat 1:290e621741fd 347 else if(bufcounter>=5){
taknokolat 1:290e621741fd 348 //pc.printf("Communication Falsed.\r\n");
taknokolat 1:290e621741fd 349 memset(SFbuf, 0, sizeof(SFbuf));
taknokolat 1:290e621741fd 350 bufcounter = 0;
taknokolat 1:290e621741fd 351 NVIC_ClearPendingIRQ(USART2_IRQn);
taknokolat 1:290e621741fd 352 }
taknokolat 1:290e621741fd 353 }
taknokolat 1:290e621741fd 354
taknokolat 1:290e621741fd 355
taknokolat 1:290e621741fd 356 }
taknokolat 1:290e621741fd 357
taknokolat 1:290e621741fd 358
taknokolat 12:083662bca47d 359 void getSF_Serial_pi(){
taknokolat 2:f30666d7838b 360
taknokolat 7:8989a4b84695 361 //NVIC_DisableIRQ(USART2_IRQn);
taknokolat 1:290e621741fd 362
taknokolat 1:290e621741fd 363 static char SFbuf[16]={'Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q'};
taknokolat 1:290e621741fd 364
taknokolat 1:290e621741fd 365 static int bufcounter=0;
taknokolat 1:290e621741fd 366
taknokolat 1:290e621741fd 367
taknokolat 1:290e621741fd 368
taknokolat 1:290e621741fd 369 if(pc2.readable()) { // 受信確認
taknokolat 1:290e621741fd 370
taknokolat 1:290e621741fd 371 SFbuf[bufcounter] = pc2.getc(); // 1文字取り出し
taknokolat 1:290e621741fd 372 if(SFbuf[0]!='S'){
taknokolat 1:290e621741fd 373 //pc.printf("x");
taknokolat 1:290e621741fd 374 return;
taknokolat 1:290e621741fd 375 }
taknokolat 1:290e621741fd 376
taknokolat 1:290e621741fd 377
taknokolat 1:290e621741fd 378
taknokolat 1:290e621741fd 379 //pc.printf("%c",SFbuf[bufcounter]);
taknokolat 1:290e621741fd 380
taknokolat 1:290e621741fd 381 if(SFbuf[0]=='S'&&bufcounter<5)bufcounter++;
taknokolat 1:290e621741fd 382
taknokolat 1:290e621741fd 383 if(bufcounter==5 && SFbuf[4]=='F'){
taknokolat 1:290e621741fd 384
taknokolat 1:290e621741fd 385 g_landingcommand = SFbuf[1];
taknokolat 2:f30666d7838b 386 wait_ms(31);//信号が速すぎることによる割り込み防止
taknokolat 1:290e621741fd 387 //pc.printf("%c",g_landingcommand);
taknokolat 1:290e621741fd 388 //wait_ms(20);
taknokolat 1:290e621741fd 389 //if(g_landingcommand=='Y')g_SerialTargetYAW = ConvertByteintoFloat(SFbuf[2], SFbuf[3]);
taknokolat 1:290e621741fd 390 bufcounter = 0;
taknokolat 1:290e621741fd 391 memset(SFbuf, 0, sizeof(SFbuf));
taknokolat 1:290e621741fd 392 NVIC_ClearPendingIRQ(USART2_IRQn);
taknokolat 1:290e621741fd 393 //pc.printf("command = %c, commandYAW = %f\r\n", g_landingcommand, g_SerialTargetYAW);
taknokolat 1:290e621741fd 394 }
taknokolat 1:290e621741fd 395
taknokolat 1:290e621741fd 396 else if(bufcounter>=5){
taknokolat 1:290e621741fd 397 //pc.printf("Communication Falsed.\r\n");
taknokolat 1:290e621741fd 398 memset(SFbuf, 0, sizeof(SFbuf));
taknokolat 1:290e621741fd 399 bufcounter = 0;
taknokolat 1:290e621741fd 400 NVIC_ClearPendingIRQ(USART2_IRQn);
taknokolat 1:290e621741fd 401 }
taknokolat 1:290e621741fd 402 }
taknokolat 2:f30666d7838b 403
taknokolat 7:8989a4b84695 404 //NVIC_EnableIRQ(USART2_IRQn);
taknokolat 1:290e621741fd 405
taknokolat 12:083662bca47d 406 }
taknokolat 1:290e621741fd 407
Skykon 3:c18342e4fddd 408
Skykon 3:c18342e4fddd 409 void setup(){
Skykon 3:c18342e4fddd 410
taknokolat 13:b088f0db7158 411 SetOptions(&Servo_NEUTRAL_R, &Servo_NEUTRAL_L,
taknokolat 12:083662bca47d 412 &Servo_high_FORWARD_R, &Servo_high_FORWARD_L,
taknokolat 12:083662bca47d 413 &Servo_slow_FORWARD_R,&Servo_slow_FORWARD_L,
taknokolat 12:083662bca47d 414 &Turntable_NEUTRAL,&Matchspeed,&Focus_NEUTRAL,
taknokolat 12:083662bca47d 415 &Camera_deg_A, &Camera_deg_B
taknokolat 13:b088f0db7158 416 );
taknokolat 12:083662bca47d 417
Skykon 3:c18342e4fddd 418 Init_sensors();
Skykon 3:c18342e4fddd 419 //switch2.rise(ResetTrim);
Skykon 3:c18342e4fddd 420
taknokolat 7:8989a4b84695 421 //NVIC_SetPriority(USART1_IRQn,0);
taknokolat 7:8989a4b84695 422 //NVIC_SetPriority(EXTI0_IRQn,1);
taknokolat 7:8989a4b84695 423 //NVIC_SetPriority(TIM5_IRQn,2);
taknokolat 7:8989a4b84695 424 //NVIC_SetPriority(EXTI9_5_IRQn,3);
taknokolat 7:8989a4b84695 425 //NVIC_SetPriority(USART2_IRQn,4);
taknokolat 7:8989a4b84695 426
taknokolat 7:8989a4b84695 427 NVIC_SetPriority(USART1_IRQn,0);//割り込み優先度
taknokolat 7:8989a4b84695 428 NVIC_SetPriority(USART2_IRQn,1);
taknokolat 7:8989a4b84695 429
Skykon 3:c18342e4fddd 430 DisplayClock();
Skykon 3:c18342e4fddd 431 t.start();
Skykon 3:c18342e4fddd 432
Skykon 3:c18342e4fddd 433 pc.printf("MPU calibration start\r\n");
taknokolat 6:166746820555 434 pc.printf("HMC calibration start\r\n");
Skykon 3:c18342e4fddd 435
Skykon 3:c18342e4fddd 436 float offsetstart = t.read();
Skykon 3:c18342e4fddd 437 while(t.read() - offsetstart < 26){
Skykon 3:c18342e4fddd 438 SensingMPU();
taknokolat 6:166746820555 439 SensingHMC();
Skykon 3:c18342e4fddd 440 for(uint8_t i=0; i<3; i++) pc.printf("%3.2f\t",nowAngle[i]);
taknokolat 6:166746820555 441 pc.printf("%3.2f\t",nowAngle_HMC);
Skykon 3:c18342e4fddd 442 pc.printf("\r\n");
Skykon 3:c18342e4fddd 443 }
Skykon 3:c18342e4fddd 444
Skykon 3:c18342e4fddd 445 FirstROLL = nowAngle[ROLL];
Skykon 3:c18342e4fddd 446 FirstPITCH = nowAngle[PITCH];
Skykon 3:c18342e4fddd 447 nowAngle[ROLL] -=FirstROLL;
Skykon 3:c18342e4fddd 448 nowAngle[PITCH] -=FirstPITCH;
taknokolat 6:166746820555 449 FirstYAW = nowAngle[YAW];
taknokolat 6:166746820555 450 nowAngle[YAW] -= FirstYAW;
taknokolat 6:166746820555 451
taknokolat 6:166746820555 452 g_FirstYAW_HMC = nowAngle_HMC;
taknokolat 6:166746820555 453 nowAngle_HMC -=g_FirstYAW_HMC;
taknokolat 6:166746820555 454 if(nowAngle_HMC<0)nowAngle_HMC+=360;
Skykon 3:c18342e4fddd 455
Skykon 3:c18342e4fddd 456 wait(0.2);
Skykon 3:c18342e4fddd 457
Skykon 3:c18342e4fddd 458 pc.printf("All initialized\r\n");
taknokolat 4:67f705d42f1e 459 setupFlag=true;
taknokolat 1:290e621741fd 460 }
taknokolat 1:290e621741fd 461
Skykon 3:c18342e4fddd 462
Skykon 3:c18342e4fddd 463 void SensingMPU(){
Skykon 3:c18342e4fddd 464 //static int16_t deltaT = 0, t_start = 0;
Skykon 3:c18342e4fddd 465 //t_start = t.read_us();
Skykon 3:c18342e4fddd 466
taknokolat 7:8989a4b84695 467 float rpy[3] = {0};
Skykon 3:c18342e4fddd 468 static uint16_t count_changeRPY = 0;
Skykon 3:c18342e4fddd 469 static bool flg_checkoutlier = false;
Skykon 3:c18342e4fddd 470 NVIC_DisableIRQ(USART1_IRQn);
Skykon 3:c18342e4fddd 471 NVIC_DisableIRQ(USART2_IRQn);
Skykon 3:c18342e4fddd 472 NVIC_DisableIRQ(TIM5_IRQn);
Skykon 3:c18342e4fddd 473 NVIC_DisableIRQ(EXTI0_IRQn);
Skykon 3:c18342e4fddd 474 NVIC_DisableIRQ(EXTI9_5_IRQn);
Skykon 3:c18342e4fddd 475
Skykon 3:c18342e4fddd 476 mpu6050.getRollPitchYaw_Skipper(rpy);
Skykon 3:c18342e4fddd 477
Skykon 3:c18342e4fddd 478 NVIC_EnableIRQ(USART1_IRQn);
Skykon 3:c18342e4fddd 479 NVIC_EnableIRQ(USART2_IRQn);
Skykon 3:c18342e4fddd 480 NVIC_EnableIRQ(TIM5_IRQn);
Skykon 3:c18342e4fddd 481 NVIC_EnableIRQ(EXTI0_IRQn);
Skykon 3:c18342e4fddd 482 NVIC_EnableIRQ(EXTI9_5_IRQn);
Skykon 3:c18342e4fddd 483
Skykon 3:c18342e4fddd 484
Skykon 3:c18342e4fddd 485 //外れ値対策
Skykon 3:c18342e4fddd 486 for(uint8_t i=0; i<3; i++) rpy[i] *= 180.0f/PI;
Skykon 3:c18342e4fddd 487 rpy[ROLL] -= FirstROLL;
Skykon 3:c18342e4fddd 488 rpy[PITCH] -= FirstPITCH;
taknokolat 4:67f705d42f1e 489 if(!setupFlag){
taknokolat 4:67f705d42f1e 490 rpy[YAW] -= FirstYAW;
taknokolat 4:67f705d42f1e 491 }else{
taknokolat 4:67f705d42f1e 492 if(rpy[YAW] >= FirstYAW){
taknokolat 4:67f705d42f1e 493 rpy[YAW] -= FirstYAW;
taknokolat 4:67f705d42f1e 494 }else{
taknokolat 4:67f705d42f1e 495 rpy[YAW] += 360.0f;
taknokolat 4:67f705d42f1e 496 rpy[YAW] -= FirstYAW;
taknokolat 4:67f705d42f1e 497 }
taknokolat 4:67f705d42f1e 498 }
Skykon 3:c18342e4fddd 499
Skykon 3:c18342e4fddd 500 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 501 if(!flg_checkoutlier || count_changeRPY >= 2){
Skykon 3:c18342e4fddd 502 for(uint8_t i=0; i<3; i++){
Skykon 3:c18342e4fddd 503 nowAngle[i] = (rpy[i] + nowAngle[i])/2.0f; //2つの移動平均
Skykon 3:c18342e4fddd 504 }
Skykon 3:c18342e4fddd 505 count_changeRPY = 0;
Skykon 3:c18342e4fddd 506 }else count_changeRPY++;
Skykon 3:c18342e4fddd 507 flg_checkoutlier = false;
Skykon 3:c18342e4fddd 508
Skykon 3:c18342e4fddd 509 }
Skykon 3:c18342e4fddd 510
Skykon 3:c18342e4fddd 511
Skykon 3:c18342e4fddd 512 void Init_sensors(){
Skykon 3:c18342e4fddd 513 if(mpu6050.setup() == -1){
Skykon 3:c18342e4fddd 514 pc.printf("failed initialize\r\n");
Skykon 3:c18342e4fddd 515 }
Skykon 3:c18342e4fddd 516 }
Skykon 3:c18342e4fddd 517
Skykon 3:c18342e4fddd 518
Skykon 3:c18342e4fddd 519 void DisplayClock(){
Skykon 3:c18342e4fddd 520 pc.printf("System Clock = %d[MHz]\r\n", HAL_RCC_GetSysClockFreq()/1000000);
Skykon 3:c18342e4fddd 521 pc.printf("HCLK Clock = %d[MHz]\r\n", HAL_RCC_GetHCLKFreq()/1000000);
Skykon 3:c18342e4fddd 522 pc.printf("PCLK1 Clock = %d[MHz]\r\n", HAL_RCC_GetPCLK1Freq()/1000000);
Skykon 3:c18342e4fddd 523 pc.printf("PCLK2 Clock = %d[MHz]\r\n", HAL_RCC_GetPCLK2Freq()/1000000);
Skykon 3:c18342e4fddd 524 pc.printf("\r\n");
taknokolat 4:67f705d42f1e 525 }
taknokolat 6:166746820555 526
taknokolat 6:166746820555 527 void SensingHMC(){
taknokolat 6:166746820555 528 //static int16_t deltaT = 0, t_start = 0;
taknokolat 6:166746820555 529 //t_start = t.read_us();
taknokolat 6:166746820555 530
taknokolat 7:8989a4b84695 531 float rpy=0;
taknokolat 6:166746820555 532 static uint16_t count_changeRPY = 0;
taknokolat 6:166746820555 533 static bool flg_checkoutlier = false;
taknokolat 6:166746820555 534 NVIC_DisableIRQ(USART1_IRQn);
taknokolat 6:166746820555 535 NVIC_DisableIRQ(USART2_IRQn);
taknokolat 6:166746820555 536 NVIC_DisableIRQ(TIM5_IRQn);
taknokolat 6:166746820555 537 NVIC_DisableIRQ(EXTI0_IRQn);
taknokolat 6:166746820555 538 NVIC_DisableIRQ(EXTI9_5_IRQn);
taknokolat 4:67f705d42f1e 539
taknokolat 6:166746820555 540 rpy= compass.getHeadingXYDeg(20,50);
taknokolat 6:166746820555 541
taknokolat 6:166746820555 542 NVIC_EnableIRQ(USART1_IRQn);
taknokolat 6:166746820555 543 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 6:166746820555 544 NVIC_EnableIRQ(TIM5_IRQn);
taknokolat 6:166746820555 545 NVIC_EnableIRQ(EXTI0_IRQn);
taknokolat 6:166746820555 546 NVIC_EnableIRQ(EXTI9_5_IRQn);
taknokolat 6:166746820555 547
taknokolat 6:166746820555 548
taknokolat 6:166746820555 549 //外れ値対策
taknokolat 6:166746820555 550 //rpy*= 180.0f/PI;
taknokolat 6:166746820555 551 if(!setupFlag){
taknokolat 6:166746820555 552 rpy -= g_FirstYAW_HMC;
taknokolat 6:166746820555 553 }else{
taknokolat 6:166746820555 554 if(rpy >= g_FirstYAW_HMC){
taknokolat 6:166746820555 555 rpy -= g_FirstYAW_HMC;
taknokolat 6:166746820555 556 }else{
taknokolat 6:166746820555 557 rpy += 360.0f;
taknokolat 6:166746820555 558 rpy -= g_FirstYAW_HMC;
taknokolat 6:166746820555 559 }
taknokolat 6:166746820555 560 }
taknokolat 6:166746820555 561
taknokolat 6:166746820555 562 if(rpy < nowAngle_HMC-10 || rpy > nowAngle_HMC+10) {flg_checkoutlier = true;}
taknokolat 6:166746820555 563 if(!flg_checkoutlier || count_changeRPY >= 2){
taknokolat 6:166746820555 564
taknokolat 6:166746820555 565 nowAngle_HMC = (rpy + nowAngle_HMC)/2.0f; //2つの移動平均
taknokolat 6:166746820555 566
taknokolat 6:166746820555 567 count_changeRPY = 0;
taknokolat 6:166746820555 568 }else count_changeRPY++;
taknokolat 6:166746820555 569 flg_checkoutlier = false;
taknokolat 6:166746820555 570
taknokolat 6:166746820555 571 }
taknokolat 12:083662bca47d 572
taknokolat 12:083662bca47d 573 int SetOptions(int *Servo_NEUTRAL_R, int *Servo_NEUTRAL_L,
taknokolat 12:083662bca47d 574 int *Servo_high_FORWARD_R, int *Servo_high_FORWARD_L,
taknokolat 12:083662bca47d 575 int *Servo_slow_FORWARD_R,int *Servo_slow_FORWARD_L,
taknokolat 12:083662bca47d 576 int *Turntable_NEUTRAL,int *Matchspeed,int *Focus_NEUTRAL,
taknokolat 12:083662bca47d 577 int *Camera_deg_A, int *Camera_deg_B
taknokolat 12:083662bca47d 578 ){
taknokolat 12:083662bca47d 579
taknokolat 12:083662bca47d 580 pc.printf("SDsetup start.\r\n");
taknokolat 12:083662bca47d 581
taknokolat 12:083662bca47d 582 FILE *fp;
taknokolat 12:083662bca47d 583 char parameter[20]; //文字列渡す用の配列
taknokolat 12:083662bca47d 584 int SDerrorcount = 0; //取得できなかった数を返す
taknokolat 12:083662bca47d 585 const char *paramNames[] = {
taknokolat 12:083662bca47d 586 "SERVO_NEUTRAL_R",
taknokolat 12:083662bca47d 587 "SERVO_NEUTRAL_L",
taknokolat 12:083662bca47d 588 "SERVO_HIGH_FORWARD_R",
taknokolat 12:083662bca47d 589 "SERVO_HIGH_FORWARD_L",
taknokolat 12:083662bca47d 590 "SERVO_SLOW_FORWARD_R",
taknokolat 12:083662bca47d 591 "SERVO_SLOW_FORWARD_L",
taknokolat 12:083662bca47d 592 "TURNTABLE_NEUTRAL",
taknokolat 12:083662bca47d 593 "MATCH_SPEED",
taknokolat 12:083662bca47d 594 "FOCUS_NEUTRAL",
taknokolat 12:083662bca47d 595 "CAMERA_DEG_A",
taknokolat 12:083662bca47d 596 "CAMERA_DEG_B"
taknokolat 12:083662bca47d 597 };
taknokolat 12:083662bca47d 598
taknokolat 12:083662bca47d 599 fp = fopen("/sd/option.txt","r");
taknokolat 12:083662bca47d 600
taknokolat 12:083662bca47d 601 if(fp != NULL){ //開けたら
taknokolat 12:083662bca47d 602 pc.printf("File was openned.\r\n");
taknokolat 12:083662bca47d 603 if(GetParameter(fp,paramNames[0],parameter)) *Servo_NEUTRAL_R = atof(parameter);
taknokolat 12:083662bca47d 604 else{ *Servo_NEUTRAL_R = servo_NEUTRAL_R;
taknokolat 12:083662bca47d 605 SDerrorcount++;
taknokolat 12:083662bca47d 606 }
taknokolat 12:083662bca47d 607 if(GetParameter(fp,paramNames[1],parameter)) *Servo_NEUTRAL_L = atof(parameter);
taknokolat 12:083662bca47d 608 else{ *Servo_NEUTRAL_L = servo_NEUTRAL_L;
taknokolat 12:083662bca47d 609 SDerrorcount++;
taknokolat 12:083662bca47d 610 }
taknokolat 12:083662bca47d 611 if(GetParameter(fp,paramNames[2],parameter)) *Servo_high_FORWARD_R = atof(parameter);
taknokolat 12:083662bca47d 612 else{ *Servo_high_FORWARD_R = servo_high_FORWARD_R;
taknokolat 12:083662bca47d 613 SDerrorcount++;
taknokolat 12:083662bca47d 614 }
taknokolat 12:083662bca47d 615 if(GetParameter(fp,paramNames[3],parameter)) *Servo_high_FORWARD_L = atof(parameter);
taknokolat 12:083662bca47d 616 else{ *Servo_high_FORWARD_L = servo_high_FORWARD_L;
taknokolat 12:083662bca47d 617 SDerrorcount++;
taknokolat 12:083662bca47d 618 }
taknokolat 12:083662bca47d 619 if(GetParameter(fp,paramNames[4],parameter)) *Servo_slow_FORWARD_R = atof(parameter);
taknokolat 12:083662bca47d 620 else{ *Servo_slow_FORWARD_R = servo_slow_FORWARD_R;
taknokolat 12:083662bca47d 621 SDerrorcount++;
taknokolat 12:083662bca47d 622 }
taknokolat 12:083662bca47d 623 if(GetParameter(fp,paramNames[5],parameter)) *Servo_slow_FORWARD_L = atof(parameter);
taknokolat 12:083662bca47d 624 else{ *Servo_slow_FORWARD_L = servo_slow_FORWARD_L;
taknokolat 12:083662bca47d 625 SDerrorcount++;
taknokolat 12:083662bca47d 626 }
taknokolat 12:083662bca47d 627
taknokolat 12:083662bca47d 628 if(GetParameter(fp,paramNames[6],parameter)) *Turntable_NEUTRAL = atof(parameter);
taknokolat 12:083662bca47d 629 else{ *Turntable_NEUTRAL = turntable_NEUTRAL;
taknokolat 12:083662bca47d 630 SDerrorcount++;
taknokolat 12:083662bca47d 631 }
taknokolat 12:083662bca47d 632 if(GetParameter(fp,paramNames[7],parameter)) *Matchspeed = atof(parameter);
taknokolat 12:083662bca47d 633 else{ *Matchspeed = matchspeed;
taknokolat 12:083662bca47d 634 SDerrorcount++;
taknokolat 12:083662bca47d 635 }
taknokolat 12:083662bca47d 636 if(GetParameter(fp,paramNames[8],parameter)) *Focus_NEUTRAL = atof(parameter);
taknokolat 12:083662bca47d 637 else{ *Focus_NEUTRAL = focus_NEUTRAL;
taknokolat 12:083662bca47d 638 SDerrorcount++;
taknokolat 12:083662bca47d 639 }
taknokolat 12:083662bca47d 640 if(GetParameter(fp,paramNames[9],parameter)) *Camera_deg_A = atof(parameter);
taknokolat 12:083662bca47d 641 else{ *Camera_deg_A = camera_deg_A;
taknokolat 12:083662bca47d 642 SDerrorcount++;
taknokolat 12:083662bca47d 643 }
taknokolat 12:083662bca47d 644 if(GetParameter(fp,paramNames[10],parameter)) *Camera_deg_B = atof(parameter);
taknokolat 12:083662bca47d 645 else{ *Camera_deg_B = camera_deg_B;
taknokolat 12:083662bca47d 646 SDerrorcount++;
taknokolat 12:083662bca47d 647 }
taknokolat 12:083662bca47d 648
taknokolat 12:083662bca47d 649 fclose(fp);
taknokolat 12:083662bca47d 650
taknokolat 12:083662bca47d 651 }else{ //ファイルがなかったら
taknokolat 12:083662bca47d 652 pc.printf("fp was null.\r\n");
taknokolat 12:083662bca47d 653
taknokolat 12:083662bca47d 654 *Servo_NEUTRAL_R = servo_NEUTRAL_R;
taknokolat 12:083662bca47d 655 *Servo_NEUTRAL_L = servo_NEUTRAL_L;
taknokolat 12:083662bca47d 656 *Servo_high_FORWARD_R = servo_high_FORWARD_R;
taknokolat 12:083662bca47d 657 *Servo_high_FORWARD_L = servo_high_FORWARD_L;
taknokolat 12:083662bca47d 658 *Servo_slow_FORWARD_R = servo_slow_FORWARD_R;
taknokolat 12:083662bca47d 659 *Servo_slow_FORWARD_L = servo_slow_FORWARD_L;
taknokolat 12:083662bca47d 660 *Turntable_NEUTRAL = turntable_NEUTRAL;
taknokolat 12:083662bca47d 661 *Matchspeed = matchspeed;
taknokolat 12:083662bca47d 662 *Focus_NEUTRAL = focus_NEUTRAL;
taknokolat 12:083662bca47d 663 *Camera_deg_A = camera_deg_A;
taknokolat 12:083662bca47d 664 *Camera_deg_B = camera_deg_B;
taknokolat 12:083662bca47d 665 SDerrorcount = -1;
taknokolat 12:083662bca47d 666 }
taknokolat 12:083662bca47d 667 pc.printf("SDsetup finished.\r\n");
taknokolat 12:083662bca47d 668 if(SDerrorcount == 0) pc.printf("setting option is success\r\n");
taknokolat 12:083662bca47d 669 else if(SDerrorcount == -1) pc.printf("ERROR 1. cannot open option\r\n");
taknokolat 12:083662bca47d 670 else if(SDerrorcount > 0) pc.printf("ERROR 2. reading parameter is failed[%d]\r\n",SDerrorcount);
taknokolat 12:083662bca47d 671
taknokolat 12:083662bca47d 672 pc.printf("Servo_NEUTRAL_R = %d, Servo_NEUTRAL_L = %d\r\n", *Servo_NEUTRAL_R, *Servo_NEUTRAL_L);
taknokolat 13:b088f0db7158 673 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 674 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 675 pc.printf("Turntable_NEUTRAL = %d, Matchspeed = %d\r\n", *Turntable_NEUTRAL, *Matchspeed);
taknokolat 13:b088f0db7158 676 pc.printf("Focus_NEUTRAL = %d\r\n", *Focus_NEUTRAL);
taknokolat 13:b088f0db7158 677 pc.printf("Camera_deg_A = %d, Camera_deg_B = %d\r\n", *Camera_deg_A, *Camera_deg_B);
taknokolat 12:083662bca47d 678
taknokolat 12:083662bca47d 679 return SDerrorcount;
taknokolat 12:083662bca47d 680 }
taknokolat 12:083662bca47d 681
taknokolat 12:083662bca47d 682 int GetParameter(FILE *fp, const char *paramName,char parameter[]){
taknokolat 12:083662bca47d 683 int i=0, j=0;
taknokolat 12:083662bca47d 684 int strmax = 200;
taknokolat 12:083662bca47d 685 char str[strmax];
taknokolat 12:083662bca47d 686
taknokolat 12:083662bca47d 687 rewind(fp); //ファイル位置を先頭に
taknokolat 12:083662bca47d 688 while(1){
taknokolat 12:083662bca47d 689 if (fgets(str, strmax, fp) == NULL) {
taknokolat 12:083662bca47d 690 return 0;
taknokolat 12:083662bca47d 691 }
taknokolat 12:083662bca47d 692 if (!strncmp(str, paramName, strlen(paramName))) {
taknokolat 12:083662bca47d 693 while (str[i++] != '=') {}
taknokolat 12:083662bca47d 694 while (str[i] != '\n') {
taknokolat 12:083662bca47d 695 parameter[j++] = str[i++];
taknokolat 12:083662bca47d 696 }
taknokolat 12:083662bca47d 697 parameter[j] = '\0';
taknokolat 12:083662bca47d 698 return 1;
taknokolat 12:083662bca47d 699 }
taknokolat 12:083662bca47d 700 }
taknokolat 12:083662bca47d 701 }
taknokolat 12:083662bca47d 702
taknokolat 12:083662bca47d 703
taknokolat 6:166746820555 704
taknokolat 4:67f705d42f1e 705 void DebugPrint(){
taknokolat 4:67f705d42f1e 706 //for(uint8_t i=0; i<3; i++) pc.printf("%3.2f\t",nowAngle[i]); //skipper地磁気センサ_デバック用
taknokolat 7:8989a4b84695 707 //pc.printf("%3.2f\t",nowAngle[2]);
taknokolat 7:8989a4b84695 708 //pc.printf("%3.2f\t",nowAngle_HMC); //HMC
taknokolat 7:8989a4b84695 709 //pc.printf("\r\n");
taknokolat 6:166746820555 710 }