skipper_raspi_uart_test

Dependencies:   mbed MPU6050_2 HMC5883L_4 SDFileSystem3

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