skipper_raspi_uart_test
Dependencies: mbed MPU6050_2 HMC5883L_4 SDFileSystem3
main.cpp@26:ea86e69563b5, 2019-02-19 (annotated)
- Committer:
- HARUKIDELTA
- Date:
- Tue Feb 19 10:36:19 2019 +0000
- Revision:
- 26:ea86e69563b5
- Parent:
- 25:1f938342d5f9
- Child:
- 27:f67efcee6509
a
Who changed what in which revision?
User | Revision | Line number | New 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 | 7:8989a4b84695 | 75 | bool jevoisFlag = true; |
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 | }*/ |
taknokolat | 19:949bab1e9451 | 138 | |
Skykon | 3:c18342e4fddd | 139 | |
HARUKIDELTA | 17:83db05cab3d1 | 140 | servoCameradeg.pulsewidth_us(Camera_deg_A); |
taknokolat | 11:d44d137831b9 | 141 | |
taknokolat | 1:290e621741fd | 142 | // シリアル通信受信の割り込みイベント登録 |
taknokolat | 1:290e621741fd | 143 | pc.attach(getSF_Serial_jevois, Serial::RxIrq); |
taknokolat | 12:083662bca47d | 144 | pc2.attach(getSF_Serial_pi, Serial::RxIrq); |
taknokolat | 1:290e621741fd | 145 | |
HARUKIDELTA | 0:84ddd6d354e1 | 146 | while(1) { |
taknokolat | 7:8989a4b84695 | 147 | if(jevoisFlag==true) NVIC_DisableIRQ(USART1_IRQn); |
taknokolat | 7:8989a4b84695 | 148 | else NVIC_DisableIRQ(USART2_IRQn); |
taknokolat | 20:011977a37394 | 149 | pc.printf("Move Camera Board\r\n"); |
taknokolat | 10:63fe920595a7 | 150 | MoveCameraBoard(); |
taknokolat | 10:63fe920595a7 | 151 | |
taknokolat | 20:011977a37394 | 152 | pc.printf("Position\r\n"); |
taknokolat | 22:a19be3b505b7 | 153 | pc.printf("g_landingcommand=%c\r\n",g_landingcommand); |
HARUKIDELTA | 25:1f938342d5f9 | 154 | |
taknokolat | 22:a19be3b505b7 | 155 | NVIC_DisableIRQ(USART1_IRQn); |
taknokolat | 22:a19be3b505b7 | 156 | NVIC_DisableIRQ(USART2_IRQn); |
taknokolat | 7:8989a4b84695 | 157 | if(g_landingcommand!='N') MatchPosition(); |
taknokolat | 22:a19be3b505b7 | 158 | NVIC_EnableIRQ(USART1_IRQn); |
taknokolat | 22:a19be3b505b7 | 159 | NVIC_EnableIRQ(USART2_IRQn); |
taknokolat | 8:d11a59d2a2f1 | 160 | |
taknokolat | 8:d11a59d2a2f1 | 161 | if(jevoisFlag==true) NVIC_DisableIRQ(USART1_IRQn); |
taknokolat | 8:d11a59d2a2f1 | 162 | else NVIC_DisableIRQ(USART2_IRQn); |
taknokolat | 8:d11a59d2a2f1 | 163 | |
taknokolat | 20:011977a37394 | 164 | pc.printf("Move Cansat\r\n"); |
taknokolat | 7:8989a4b84695 | 165 | MoveCansat(g_landingcommand); |
taknokolat | 22:a19be3b505b7 | 166 | if(jevoisFlag==true) NVIC_DisableIRQ(USART1_IRQn); |
taknokolat | 22:a19be3b505b7 | 167 | else NVIC_DisableIRQ(USART2_IRQn); |
Skykon | 3:c18342e4fddd | 168 | wait_ms(23); |
taknokolat | 8:d11a59d2a2f1 | 169 | |
taknokolat | 20:011977a37394 | 170 | pc.printf("finish\r\n"); |
taknokolat | 7:8989a4b84695 | 171 | if(jevoisFlag==true) NVIC_EnableIRQ(USART1_IRQn); |
taknokolat | 7:8989a4b84695 | 172 | else NVIC_EnableIRQ(USART2_IRQn); |
HARUKIDELTA | 0:84ddd6d354e1 | 173 | } |
HARUKIDELTA | 0:84ddd6d354e1 | 174 | } |
HARUKIDELTA | 0:84ddd6d354e1 | 175 | |
Skykon | 3:c18342e4fddd | 176 | |
taknokolat | 22:a19be3b505b7 | 177 | void MoveCansat(char a) |
HARUKIDELTA | 0:84ddd6d354e1 | 178 | { |
taknokolat | 22:a19be3b505b7 | 179 | NVIC_DisableIRQ(USART1_IRQn); |
taknokolat | 22:a19be3b505b7 | 180 | NVIC_DisableIRQ(USART2_IRQn); |
taknokolat | 22:a19be3b505b7 | 181 | switch(a){ |
taknokolat | 2:f30666d7838b | 182 | case 'N': //MOVE_NEUTRAL |
HARUKIDELTA | 17:83db05cab3d1 | 183 | servoR.pulsewidth_us(Servo_NEUTRAL_R); |
HARUKIDELTA | 17:83db05cab3d1 | 184 | servoL.pulsewidth_us(Servo_NEUTRAL_L); |
taknokolat | 22:a19be3b505b7 | 185 | NVIC_EnableIRQ(USART1_IRQn); |
taknokolat | 22:a19be3b505b7 | 186 | NVIC_EnableIRQ(USART2_IRQn); |
HARUKIDELTA | 26:ea86e69563b5 | 187 | g_fp = fopen( "/sd/Datalog01.txt" ,"a" ); |
HARUKIDELTA | 26:ea86e69563b5 | 188 | fprintf(g_fp, "Not found\r\n."); |
HARUKIDELTA | 26:ea86e69563b5 | 189 | fclose(g_fp); |
HARUKIDELTA | 0:84ddd6d354e1 | 190 | break; |
taknokolat | 1:290e621741fd | 191 | |
taknokolat | 2:f30666d7838b | 192 | case 'Y': //MOVE_FORWARD |
HARUKIDELTA | 17:83db05cab3d1 | 193 | servoR.pulsewidth_us(Servo_high_FORWARD_R); |
HARUKIDELTA | 17:83db05cab3d1 | 194 | servoL.pulsewidth_us(Servo_high_FORWARD_L); |
taknokolat | 22:a19be3b505b7 | 195 | NVIC_EnableIRQ(USART1_IRQn); |
taknokolat | 22:a19be3b505b7 | 196 | NVIC_EnableIRQ(USART2_IRQn); |
HARUKIDELTA | 0:84ddd6d354e1 | 197 | break; |
taknokolat | 1:290e621741fd | 198 | |
taknokolat | 12:083662bca47d | 199 | case 'l': //MOVE_LEFT Low Speed |
HARUKIDELTA | 17:83db05cab3d1 | 200 | servoR.pulsewidth_us(Servo_slow_FORWARD_R); |
taknokolat | 22:a19be3b505b7 | 201 | servoL.pulsewidth_us(Servo_NEUTRAL_L); |
taknokolat | 22:a19be3b505b7 | 202 | NVIC_EnableIRQ(USART1_IRQn); |
taknokolat | 22:a19be3b505b7 | 203 | NVIC_EnableIRQ(USART2_IRQn); |
taknokolat | 12:083662bca47d | 204 | |
taknokolat | 12:083662bca47d | 205 | case 'L': //MOVE_LEFT High Speed |
HARUKIDELTA | 17:83db05cab3d1 | 206 | servoR.pulsewidth_us(Servo_high_FORWARD_R); |
taknokolat | 22:a19be3b505b7 | 207 | servoL.pulsewidth_us(Servo_NEUTRAL_L); |
taknokolat | 22:a19be3b505b7 | 208 | NVIC_EnableIRQ(USART1_IRQn); |
taknokolat | 22:a19be3b505b7 | 209 | NVIC_EnableIRQ(USART2_IRQn); |
taknokolat | 1:290e621741fd | 210 | |
taknokolat | 12:083662bca47d | 211 | case 'r': //MOVE_RIGHT Low Speed |
taknokolat | 22:a19be3b505b7 | 212 | servoR.pulsewidth_us(Servo_NEUTRAL_R); |
HARUKIDELTA | 17:83db05cab3d1 | 213 | servoL.pulsewidth_us(Servo_slow_FORWARD_L); |
taknokolat | 22:a19be3b505b7 | 214 | NVIC_EnableIRQ(USART1_IRQn); |
taknokolat | 22:a19be3b505b7 | 215 | NVIC_EnableIRQ(USART2_IRQn); |
HARUKIDELTA | 0:84ddd6d354e1 | 216 | break; |
taknokolat | 12:083662bca47d | 217 | |
taknokolat | 12:083662bca47d | 218 | case 'R': //MOVE_RIGHT High Speed |
taknokolat | 22:a19be3b505b7 | 219 | servoR.pulsewidth_us(Servo_NEUTRAL_R); |
HARUKIDELTA | 17:83db05cab3d1 | 220 | servoL.pulsewidth_us(Servo_high_FORWARD_L); |
taknokolat | 22:a19be3b505b7 | 221 | NVIC_EnableIRQ(USART1_IRQn); |
taknokolat | 22:a19be3b505b7 | 222 | NVIC_EnableIRQ(USART2_IRQn); |
HARUKIDELTA | 0:84ddd6d354e1 | 223 | break; |
taknokolat | 1:290e621741fd | 224 | |
taknokolat | 1:290e621741fd | 225 | case 'G': //GOAL_FORWARD |
HARUKIDELTA | 17:83db05cab3d1 | 226 | servoR.pulsewidth_us(Servo_slow_FORWARD_R); |
HARUKIDELTA | 17:83db05cab3d1 | 227 | servoL.pulsewidth_us(Servo_slow_FORWARD_L); |
taknokolat | 22:a19be3b505b7 | 228 | NVIC_EnableIRQ(USART1_IRQn); |
taknokolat | 22:a19be3b505b7 | 229 | NVIC_EnableIRQ(USART2_IRQn); |
taknokolat | 7:8989a4b84695 | 230 | break; |
taknokolat | 12:083662bca47d | 231 | |
taknokolat | 12:083662bca47d | 232 | case '1': //MOVE_FORWARD Speed Level 1 |
HARUKIDELTA | 17:83db05cab3d1 | 233 | servoR.pulsewidth_us(Servo_high_FORWARD_R); |
HARUKIDELTA | 17:83db05cab3d1 | 234 | servoL.pulsewidth_us(Servo_high_FORWARD_L); |
taknokolat | 12:083662bca47d | 235 | wait(1); |
taknokolat | 12:083662bca47d | 236 | do{ |
taknokolat | 22:a19be3b505b7 | 237 | SensingMPU(); |
taknokolat | 22:a19be3b505b7 | 238 | wait_ms(30); |
taknokolat | 22:a19be3b505b7 | 239 | }while((nowAngle[PITCH]>20||nowAngle[PITCH]<-20)&&(nowAngle[ROLL]>20||nowAngle[ROLL]<-20)); |
taknokolat | 22:a19be3b505b7 | 240 | NVIC_EnableIRQ(USART1_IRQn); |
taknokolat | 22:a19be3b505b7 | 241 | NVIC_EnableIRQ(USART2_IRQn); |
taknokolat | 12:083662bca47d | 242 | break; |
taknokolat | 12:083662bca47d | 243 | |
taknokolat | 12:083662bca47d | 244 | case '2': //MOVE_FORWARD Speed Level 2 |
HARUKIDELTA | 17:83db05cab3d1 | 245 | servoR.pulsewidth_us(Servo_high_FORWARD_R); |
HARUKIDELTA | 17:83db05cab3d1 | 246 | servoL.pulsewidth_us(Servo_high_FORWARD_L); |
taknokolat | 12:083662bca47d | 247 | wait(2); |
taknokolat | 12:083662bca47d | 248 | do{ |
taknokolat | 22:a19be3b505b7 | 249 | SensingMPU(); |
taknokolat | 22:a19be3b505b7 | 250 | wait_ms(30); |
taknokolat | 22:a19be3b505b7 | 251 | }while((nowAngle[PITCH]>20||nowAngle[PITCH]<-20)&&(nowAngle[ROLL]>20||nowAngle[ROLL]<-20)); |
taknokolat | 22:a19be3b505b7 | 252 | NVIC_EnableIRQ(USART1_IRQn); |
taknokolat | 22:a19be3b505b7 | 253 | NVIC_EnableIRQ(USART2_IRQn); |
taknokolat | 12:083662bca47d | 254 | break; |
taknokolat | 12:083662bca47d | 255 | |
taknokolat | 12:083662bca47d | 256 | case '3': //MOVE_FORWARD Speed Level 3 |
HARUKIDELTA | 17:83db05cab3d1 | 257 | servoR.pulsewidth_us(Servo_high_FORWARD_R); |
HARUKIDELTA | 17:83db05cab3d1 | 258 | servoL.pulsewidth_us(Servo_high_FORWARD_L); |
taknokolat | 12:083662bca47d | 259 | wait(3); |
taknokolat | 12:083662bca47d | 260 | do{ |
taknokolat | 22:a19be3b505b7 | 261 | SensingMPU(); |
taknokolat | 22:a19be3b505b7 | 262 | wait_ms(30); |
taknokolat | 22:a19be3b505b7 | 263 | }while((nowAngle[PITCH]>20||nowAngle[PITCH]<-20)&&(nowAngle[ROLL]>20||nowAngle[ROLL]<-20)); |
taknokolat | 22:a19be3b505b7 | 264 | NVIC_EnableIRQ(USART1_IRQn); |
taknokolat | 22:a19be3b505b7 | 265 | NVIC_EnableIRQ(USART2_IRQn); |
taknokolat | 12:083662bca47d | 266 | break; |
taknokolat | 12:083662bca47d | 267 | |
taknokolat | 12:083662bca47d | 268 | case '4': //MOVE_FORWARD Speed Level 4 |
HARUKIDELTA | 17:83db05cab3d1 | 269 | servoR.pulsewidth_us(Servo_high_FORWARD_R); |
HARUKIDELTA | 17:83db05cab3d1 | 270 | servoL.pulsewidth_us(Servo_high_FORWARD_L); |
taknokolat | 12:083662bca47d | 271 | wait(4); |
taknokolat | 12:083662bca47d | 272 | do{ |
taknokolat | 22:a19be3b505b7 | 273 | SensingMPU(); |
taknokolat | 22:a19be3b505b7 | 274 | wait_ms(30); |
taknokolat | 22:a19be3b505b7 | 275 | }while((nowAngle[PITCH]>20||nowAngle[PITCH]<-20)||(nowAngle[ROLL]>20||nowAngle[ROLL]<-20)); |
taknokolat | 22:a19be3b505b7 | 276 | NVIC_EnableIRQ(USART1_IRQn); |
taknokolat | 22:a19be3b505b7 | 277 | NVIC_EnableIRQ(USART2_IRQn); |
taknokolat | 12:083662bca47d | 278 | break; |
taknokolat | 7:8989a4b84695 | 279 | |
taknokolat | 12:083662bca47d | 280 | case '5': //MOVE_FORWARD Speed Level 5 |
HARUKIDELTA | 17:83db05cab3d1 | 281 | servoR.pulsewidth_us(Servo_high_FORWARD_R); |
HARUKIDELTA | 17:83db05cab3d1 | 282 | servoL.pulsewidth_us(Servo_high_FORWARD_L); |
taknokolat | 7:8989a4b84695 | 283 | wait(5); |
taknokolat | 10:63fe920595a7 | 284 | do{ |
taknokolat | 22:a19be3b505b7 | 285 | SensingMPU(); |
taknokolat | 22:a19be3b505b7 | 286 | wait_ms(30); |
taknokolat | 22:a19be3b505b7 | 287 | }while((nowAngle[PITCH]>20||nowAngle[PITCH]<-20)&&(nowAngle[ROLL]>20||nowAngle[ROLL]<-20)); |
taknokolat | 22:a19be3b505b7 | 288 | NVIC_EnableIRQ(USART1_IRQn); |
taknokolat | 22:a19be3b505b7 | 289 | NVIC_EnableIRQ(USART2_IRQn); |
taknokolat | 7:8989a4b84695 | 290 | break; |
taknokolat | 7:8989a4b84695 | 291 | |
taknokolat | 7:8989a4b84695 | 292 | case 'M': //MatchPosition |
HARUKIDELTA | 17:83db05cab3d1 | 293 | servoR.pulsewidth_us(Matchspeed); |
taknokolat | 22:a19be3b505b7 | 294 | NVIC_EnableIRQ(USART1_IRQn); |
taknokolat | 22:a19be3b505b7 | 295 | NVIC_EnableIRQ(USART2_IRQn); |
taknokolat | 7:8989a4b84695 | 296 | break; |
taknokolat | 7:8989a4b84695 | 297 | |
taknokolat | 12:083662bca47d | 298 | case 'P': //jevoisからraspberry piへの切り替え |
taknokolat | 7:8989a4b84695 | 299 | jevoisFlag = false; |
taknokolat | 22:a19be3b505b7 | 300 | NVIC_EnableIRQ(USART1_IRQn); |
taknokolat | 22:a19be3b505b7 | 301 | NVIC_EnableIRQ(USART2_IRQn); |
HARUKIDELTA | 0:84ddd6d354e1 | 302 | break; |
taknokolat | 12:083662bca47d | 303 | |
taknokolat | 12:083662bca47d | 304 | case 'S': |
taknokolat | 12:083662bca47d | 305 | /*RasPiからの超音波判定(プログラムスタート部)*/ |
taknokolat | 22:a19be3b505b7 | 306 | NVIC_EnableIRQ(USART1_IRQn); |
taknokolat | 22:a19be3b505b7 | 307 | NVIC_EnableIRQ(USART2_IRQn); |
taknokolat | 12:083662bca47d | 308 | break; |
taknokolat | 1:290e621741fd | 309 | |
taknokolat | 1:290e621741fd | 310 | default : |
taknokolat | 22:a19be3b505b7 | 311 | NVIC_EnableIRQ(USART1_IRQn); |
taknokolat | 22:a19be3b505b7 | 312 | NVIC_EnableIRQ(USART2_IRQn); |
HARUKIDELTA | 0:84ddd6d354e1 | 313 | break; |
taknokolat | 1:290e621741fd | 314 | |
HARUKIDELTA | 0:84ddd6d354e1 | 315 | } |
taknokolat | 7:8989a4b84695 | 316 | |
HARUKIDELTA | 0:84ddd6d354e1 | 317 | return; |
taknokolat | 1:290e621741fd | 318 | } |
taknokolat | 1:290e621741fd | 319 | |
taknokolat | 7:8989a4b84695 | 320 | void MoveCameraBoard(){ |
taknokolat | 22:a19be3b505b7 | 321 | //pc.printf("start\r\n"); |
taknokolat | 7:8989a4b84695 | 322 | MoveCansat('N'); |
taknokolat | 22:a19be3b505b7 | 323 | //pc.printf("ok\r\n"); |
taknokolat | 10:63fe920595a7 | 324 | g_landingcommand='N'; |
taknokolat | 24:0ad1725c7849 | 325 | servoTurnTable.pulsewidth_us(Turntable_NEUTRAL - Turntable_speed); |
taknokolat | 20:011977a37394 | 326 | wait_ms(Camera_board_wait); |
taknokolat | 24:0ad1725c7849 | 327 | g_CameraDegCounter++; |
HARUKIDELTA | 17:83db05cab3d1 | 328 | servoTurnTable.pulsewidth_us(Turntable_NEUTRAL); |
taknokolat | 22:a19be3b505b7 | 329 | //pc.printf("zoom1\r\n"); |
taknokolat | 7:8989a4b84695 | 330 | if(jevoisFlag == true) FocusAdjust(); |
taknokolat | 7:8989a4b84695 | 331 | else wait(1); |
taknokolat | 7:8989a4b84695 | 332 | if(g_landingcommand!='N') return; |
taknokolat | 7:8989a4b84695 | 333 | if(!CameraDegFlag){ |
taknokolat | 18:4566d1f5fc60 | 334 | for(int i=30; i<Camera_deg_B-Camera_deg_A;i=i+30){ |
taknokolat | 18:4566d1f5fc60 | 335 | servoCameradeg.pulsewidth_us(Camera_deg_A+i); |
taknokolat | 22:a19be3b505b7 | 336 | //pc.printf("%d\r\n",i); |
taknokolat | 15:1519fccfcae3 | 337 | wait_ms(20); |
taknokolat | 15:1519fccfcae3 | 338 | } |
taknokolat | 7:8989a4b84695 | 339 | CameraDegFlag=!CameraDegFlag; |
taknokolat | 7:8989a4b84695 | 340 | }else{ |
taknokolat | 18:4566d1f5fc60 | 341 | for(int i=30; i<Camera_deg_B-Camera_deg_A;i=i+30){ |
taknokolat | 18:4566d1f5fc60 | 342 | servoCameradeg.pulsewidth_us(Camera_deg_B-i); |
taknokolat | 22:a19be3b505b7 | 343 | //pc.printf("%d\r\n",i); |
taknokolat | 18:4566d1f5fc60 | 344 | wait_ms(20); |
taknokolat | 15:1519fccfcae3 | 345 | } |
taknokolat | 7:8989a4b84695 | 346 | CameraDegFlag = !CameraDegFlag; |
taknokolat | 7:8989a4b84695 | 347 | } |
taknokolat | 22:a19be3b505b7 | 348 | if(g_landingcommand!='N') return; |
taknokolat | 22:a19be3b505b7 | 349 | //pc.printf("zoom2\r\n"); |
taknokolat | 7:8989a4b84695 | 350 | if(jevoisFlag == true) FocusAdjust(); |
taknokolat | 7:8989a4b84695 | 351 | else wait(1); |
taknokolat | 7:8989a4b84695 | 352 | |
taknokolat | 20:011977a37394 | 353 | |
taknokolat | 22:a19be3b505b7 | 354 | //pc.printf("Move Board Finish\r\n"); |
taknokolat | 7:8989a4b84695 | 355 | return; |
taknokolat | 7:8989a4b84695 | 356 | } |
taknokolat | 7:8989a4b84695 | 357 | |
taknokolat | 7:8989a4b84695 | 358 | void MatchPosition(){ |
taknokolat | 22:a19be3b505b7 | 359 | pc.printf("MatchPosition\r\n"); |
taknokolat | 24:0ad1725c7849 | 360 | |
taknokolat | 24:0ad1725c7849 | 361 | servoTurnTable.pulsewidth_us(Turntable_NEUTRAL + Turntable_speed); |
taknokolat | 24:0ad1725c7849 | 362 | wait_ms(Camera_board_wait*g_CameraDegCounter); |
taknokolat | 24:0ad1725c7849 | 363 | servoTurnTable.pulsewidth_us(Turntable_NEUTRAL); |
taknokolat | 24:0ad1725c7849 | 364 | |
taknokolat | 22:a19be3b505b7 | 365 | int SetLoop=0; |
taknokolat | 22:a19be3b505b7 | 366 | |
taknokolat | 22:a19be3b505b7 | 367 | while(SetLoop<30){ |
taknokolat | 7:8989a4b84695 | 368 | SensingMPU(); |
taknokolat | 22:a19be3b505b7 | 369 | wait_ms(20); |
taknokolat | 24:0ad1725c7849 | 370 | //SensingHMC(); |
taknokolat | 24:0ad1725c7849 | 371 | //wait_ms(20); |
taknokolat | 22:a19be3b505b7 | 372 | //DebugPrint(); |
taknokolat | 22:a19be3b505b7 | 373 | SetLoop++; |
taknokolat | 22:a19be3b505b7 | 374 | //pc.printf("nowAngle_HMC=%f\tMPU=%f\r\n",nowAngle_HMC,nowAngle[YAW]); |
taknokolat | 22:a19be3b505b7 | 375 | |
taknokolat | 22:a19be3b505b7 | 376 | } |
taknokolat | 7:8989a4b84695 | 377 | |
taknokolat | 24:0ad1725c7849 | 378 | static float TargetDeg = 0; |
taknokolat | 24:0ad1725c7849 | 379 | |
taknokolat | 24:0ad1725c7849 | 380 | TargetDeg = 360*(float)Camera_board_wait*(float)g_CameraDegCounter/(float)Time360; |
taknokolat | 24:0ad1725c7849 | 381 | |
taknokolat | 24:0ad1725c7849 | 382 | float HighTargetYaw = TargetDeg + Match_wid; |
taknokolat | 24:0ad1725c7849 | 383 | float LowTargetYaw = TargetDeg - Match_wid; |
taknokolat | 21:ca8f35e24e66 | 384 | |
taknokolat | 22:a19be3b505b7 | 385 | |
taknokolat | 21:ca8f35e24e66 | 386 | if(HighTargetYaw >= 360.0) HighTargetYaw = HighTargetYaw - 360.0; |
taknokolat | 22:a19be3b505b7 | 387 | |
taknokolat | 21:ca8f35e24e66 | 388 | if(LowTargetYaw < 0) LowTargetYaw = LowTargetYaw + 360.0; |
taknokolat | 21:ca8f35e24e66 | 389 | |
taknokolat | 22:a19be3b505b7 | 390 | pc.printf("\r\nnow=%f\t,high=%f\t,low=%f\r\n",nowAngle[YAW],HighTargetYaw,LowTargetYaw); |
taknokolat | 22:a19be3b505b7 | 391 | |
taknokolat | 24:0ad1725c7849 | 392 | MoveCansat('r'); |
taknokolat | 22:a19be3b505b7 | 393 | |
taknokolat | 22:a19be3b505b7 | 394 | if(HighTargetYaw-LowTargetYaw<0){ |
taknokolat | 22:a19be3b505b7 | 395 | while(nowAngle[YAW] > HighTargetYaw && nowAngle[YAW] < LowTargetYaw){ |
taknokolat | 22:a19be3b505b7 | 396 | //MoveCansat('r'); |
taknokolat | 22:a19be3b505b7 | 397 | SensingMPU(); |
taknokolat | 22:a19be3b505b7 | 398 | wait_ms(30); |
taknokolat | 22:a19be3b505b7 | 399 | pc.printf("nowAngle_MPU=%f\r\n",nowAngle[YAW]); |
taknokolat | 22:a19be3b505b7 | 400 | } |
taknokolat | 22:a19be3b505b7 | 401 | }else{ |
taknokolat | 22:a19be3b505b7 | 402 | while(nowAngle[YAW] > HighTargetYaw || nowAngle[YAW] < LowTargetYaw){ |
taknokolat | 22:a19be3b505b7 | 403 | //MoveCansat('r'); |
taknokolat | 22:a19be3b505b7 | 404 | SensingMPU(); |
taknokolat | 22:a19be3b505b7 | 405 | wait_ms(30); |
taknokolat | 22:a19be3b505b7 | 406 | pc.printf("nowAngle_MPU=%f\r\n",nowAngle[YAW]); |
taknokolat | 22:a19be3b505b7 | 407 | } |
taknokolat | 7:8989a4b84695 | 408 | } |
taknokolat | 24:0ad1725c7849 | 409 | g_CameraDegCounter = 0; |
taknokolat | 7:8989a4b84695 | 410 | return; |
taknokolat | 7:8989a4b84695 | 411 | } |
taknokolat | 7:8989a4b84695 | 412 | |
taknokolat | 7:8989a4b84695 | 413 | void FocusAdjust(){ |
HARUKIDELTA | 17:83db05cab3d1 | 414 | servoCameraPinto.pulsewidth_us(Focus_NEUTRAL-200); |
taknokolat | 20:011977a37394 | 415 | pc.printf("set\r\n"); |
taknokolat | 11:d44d137831b9 | 416 | wait(1); |
taknokolat | 20:011977a37394 | 417 | pc.printf("set2\r\n"); |
HARUKIDELTA | 17:83db05cab3d1 | 418 | servoCameraPinto.pulsewidth_us(Focus_NEUTRAL+Pint_speed); |
taknokolat | 20:011977a37394 | 419 | pc.printf("check\r\n"); |
taknokolat | 20:011977a37394 | 420 | wait(Pint_wait); |
HARUKIDELTA | 17:83db05cab3d1 | 421 | servoCameraPinto.pulsewidth_us(Focus_NEUTRAL); |
taknokolat | 11:d44d137831b9 | 422 | |
taknokolat | 7:8989a4b84695 | 423 | return; |
taknokolat | 15:1519fccfcae3 | 424 | } |
taknokolat | 7:8989a4b84695 | 425 | |
taknokolat | 1:290e621741fd | 426 | void getSF_Serial_jevois(){ |
taknokolat | 22:a19be3b505b7 | 427 | |
taknokolat | 22:a19be3b505b7 | 428 | //pc.printf("jevois\r\n"); |
taknokolat | 1:290e621741fd | 429 | |
taknokolat | 1:290e621741fd | 430 | |
taknokolat | 1:290e621741fd | 431 | static char SFbuf[16]={'Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q'}; |
taknokolat | 1:290e621741fd | 432 | |
taknokolat | 1:290e621741fd | 433 | static int bufcounter=0; |
taknokolat | 1:290e621741fd | 434 | |
taknokolat | 1:290e621741fd | 435 | |
taknokolat | 1:290e621741fd | 436 | |
taknokolat | 1:290e621741fd | 437 | if(pc.readable()) { // 受信確認 |
taknokolat | 1:290e621741fd | 438 | |
taknokolat | 1:290e621741fd | 439 | SFbuf[bufcounter] = pc.getc(); // 1文字取り出し |
taknokolat | 1:290e621741fd | 440 | if(SFbuf[0]!='S'){ |
taknokolat | 1:290e621741fd | 441 | //pc.printf("x"); |
taknokolat | 1:290e621741fd | 442 | return; |
taknokolat | 1:290e621741fd | 443 | } |
taknokolat | 1:290e621741fd | 444 | |
taknokolat | 1:290e621741fd | 445 | |
taknokolat | 1:290e621741fd | 446 | |
taknokolat | 22:a19be3b505b7 | 447 | pc.printf("%c",SFbuf[bufcounter]); |
taknokolat | 1:290e621741fd | 448 | |
Skykon | 3:c18342e4fddd | 449 | if(SFbuf[0]=='S' && bufcounter<5)bufcounter++; |
taknokolat | 1:290e621741fd | 450 | |
taknokolat | 1:290e621741fd | 451 | if(bufcounter==5 && SFbuf[4]=='F'){ |
taknokolat | 1:290e621741fd | 452 | |
taknokolat | 1:290e621741fd | 453 | g_landingcommand = SFbuf[1]; |
taknokolat | 2:f30666d7838b | 454 | wait_ms(31);//信号が速すぎることによる割り込み防止 |
taknokolat | 1:290e621741fd | 455 | //pc.printf("%c",g_landingcommand); |
taknokolat | 1:290e621741fd | 456 | //wait_ms(20); |
taknokolat | 1:290e621741fd | 457 | //if(g_landingcommand=='Y')g_SerialTargetYAW = ConvertByteintoFloat(SFbuf[2], SFbuf[3]); |
taknokolat | 1:290e621741fd | 458 | bufcounter = 0; |
taknokolat | 1:290e621741fd | 459 | memset(SFbuf, 0, sizeof(SFbuf)); |
taknokolat | 1:290e621741fd | 460 | NVIC_ClearPendingIRQ(USART2_IRQn); |
taknokolat | 1:290e621741fd | 461 | //pc.printf("command = %c, commandYAW = %f\r\n", g_landingcommand, g_SerialTargetYAW); |
taknokolat | 1:290e621741fd | 462 | } |
taknokolat | 1:290e621741fd | 463 | |
taknokolat | 1:290e621741fd | 464 | else if(bufcounter>=5){ |
taknokolat | 1:290e621741fd | 465 | //pc.printf("Communication Falsed.\r\n"); |
taknokolat | 1:290e621741fd | 466 | memset(SFbuf, 0, sizeof(SFbuf)); |
taknokolat | 1:290e621741fd | 467 | bufcounter = 0; |
taknokolat | 1:290e621741fd | 468 | NVIC_ClearPendingIRQ(USART2_IRQn); |
taknokolat | 1:290e621741fd | 469 | } |
taknokolat | 1:290e621741fd | 470 | } |
taknokolat | 1:290e621741fd | 471 | |
taknokolat | 1:290e621741fd | 472 | |
taknokolat | 1:290e621741fd | 473 | } |
taknokolat | 1:290e621741fd | 474 | |
taknokolat | 1:290e621741fd | 475 | |
taknokolat | 12:083662bca47d | 476 | void getSF_Serial_pi(){ |
taknokolat | 2:f30666d7838b | 477 | |
taknokolat | 7:8989a4b84695 | 478 | //NVIC_DisableIRQ(USART2_IRQn); |
taknokolat | 1:290e621741fd | 479 | |
taknokolat | 1:290e621741fd | 480 | static char SFbuf[16]={'Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q'}; |
taknokolat | 1:290e621741fd | 481 | |
taknokolat | 1:290e621741fd | 482 | static int bufcounter=0; |
taknokolat | 1:290e621741fd | 483 | |
taknokolat | 1:290e621741fd | 484 | |
taknokolat | 1:290e621741fd | 485 | |
taknokolat | 1:290e621741fd | 486 | if(pc2.readable()) { // 受信確認 |
taknokolat | 1:290e621741fd | 487 | |
taknokolat | 1:290e621741fd | 488 | SFbuf[bufcounter] = pc2.getc(); // 1文字取り出し |
taknokolat | 1:290e621741fd | 489 | if(SFbuf[0]!='S'){ |
taknokolat | 1:290e621741fd | 490 | //pc.printf("x"); |
taknokolat | 1:290e621741fd | 491 | return; |
taknokolat | 1:290e621741fd | 492 | } |
taknokolat | 1:290e621741fd | 493 | |
taknokolat | 1:290e621741fd | 494 | |
taknokolat | 1:290e621741fd | 495 | |
taknokolat | 1:290e621741fd | 496 | //pc.printf("%c",SFbuf[bufcounter]); |
taknokolat | 1:290e621741fd | 497 | |
taknokolat | 1:290e621741fd | 498 | if(SFbuf[0]=='S'&&bufcounter<5)bufcounter++; |
taknokolat | 1:290e621741fd | 499 | |
taknokolat | 1:290e621741fd | 500 | if(bufcounter==5 && SFbuf[4]=='F'){ |
taknokolat | 1:290e621741fd | 501 | |
taknokolat | 1:290e621741fd | 502 | g_landingcommand = SFbuf[1]; |
taknokolat | 2:f30666d7838b | 503 | wait_ms(31);//信号が速すぎることによる割り込み防止 |
taknokolat | 1:290e621741fd | 504 | //pc.printf("%c",g_landingcommand); |
taknokolat | 1:290e621741fd | 505 | //wait_ms(20); |
taknokolat | 1:290e621741fd | 506 | //if(g_landingcommand=='Y')g_SerialTargetYAW = ConvertByteintoFloat(SFbuf[2], SFbuf[3]); |
taknokolat | 1:290e621741fd | 507 | bufcounter = 0; |
taknokolat | 1:290e621741fd | 508 | memset(SFbuf, 0, sizeof(SFbuf)); |
taknokolat | 1:290e621741fd | 509 | NVIC_ClearPendingIRQ(USART2_IRQn); |
taknokolat | 1:290e621741fd | 510 | //pc.printf("command = %c, commandYAW = %f\r\n", g_landingcommand, g_SerialTargetYAW); |
taknokolat | 1:290e621741fd | 511 | } |
taknokolat | 1:290e621741fd | 512 | |
taknokolat | 1:290e621741fd | 513 | else if(bufcounter>=5){ |
taknokolat | 1:290e621741fd | 514 | //pc.printf("Communication Falsed.\r\n"); |
taknokolat | 1:290e621741fd | 515 | memset(SFbuf, 0, sizeof(SFbuf)); |
taknokolat | 1:290e621741fd | 516 | bufcounter = 0; |
taknokolat | 1:290e621741fd | 517 | NVIC_ClearPendingIRQ(USART2_IRQn); |
taknokolat | 1:290e621741fd | 518 | } |
taknokolat | 1:290e621741fd | 519 | } |
taknokolat | 2:f30666d7838b | 520 | |
taknokolat | 7:8989a4b84695 | 521 | //NVIC_EnableIRQ(USART2_IRQn); |
taknokolat | 1:290e621741fd | 522 | |
taknokolat | 12:083662bca47d | 523 | } |
taknokolat | 1:290e621741fd | 524 | |
Skykon | 3:c18342e4fddd | 525 | |
Skykon | 3:c18342e4fddd | 526 | void setup(){ |
HARUKIDELTA | 23:29b2722bd753 | 527 | |
HARUKIDELTA | 23:29b2722bd753 | 528 | led1 = 1; |
HARUKIDELTA | 23:29b2722bd753 | 529 | led2 = 1; |
HARUKIDELTA | 23:29b2722bd753 | 530 | led3 = 1; |
HARUKIDELTA | 23:29b2722bd753 | 531 | led4 = 1; |
HARUKIDELTA | 26:ea86e69563b5 | 532 | |
HARUKIDELTA | 26:ea86e69563b5 | 533 | servoR.pulsewidth_us(Servo_NEUTRAL_R); //servo initialize |
HARUKIDELTA | 26:ea86e69563b5 | 534 | servoL.pulsewidth_us(Servo_NEUTRAL_L); |
HARUKIDELTA | 26:ea86e69563b5 | 535 | servoTurnTable.pulsewidth_us(Turntable_NEUTRAL); |
HARUKIDELTA | 26:ea86e69563b5 | 536 | servoCameradeg.pulsewidth_us(Camera_deg_A); |
HARUKIDELTA | 26:ea86e69563b5 | 537 | servoCameraPinto.pulsewidth_us(focus_NEUTRAL); |
Skykon | 3:c18342e4fddd | 538 | |
taknokolat | 13:b088f0db7158 | 539 | SetOptions(&Servo_NEUTRAL_R, &Servo_NEUTRAL_L, |
taknokolat | 12:083662bca47d | 540 | &Servo_high_FORWARD_R, &Servo_high_FORWARD_L, |
taknokolat | 12:083662bca47d | 541 | &Servo_slow_FORWARD_R,&Servo_slow_FORWARD_L, |
taknokolat | 12:083662bca47d | 542 | &Turntable_NEUTRAL,&Matchspeed,&Focus_NEUTRAL, |
taknokolat | 16:26cee2aaf61d | 543 | &Camera_deg_A, &Camera_deg_B, |
HARUKIDELTA | 17:83db05cab3d1 | 544 | &Pint_speed,&Pint_wait, |
taknokolat | 19:949bab1e9451 | 545 | &Turntable_speed, |
taknokolat | 24:0ad1725c7849 | 546 | &Time360, &Match_wid, |
taknokolat | 20:011977a37394 | 547 | &Camera_board_wait |
taknokolat | 13:b088f0db7158 | 548 | ); |
taknokolat | 12:083662bca47d | 549 | |
Skykon | 3:c18342e4fddd | 550 | Init_sensors(); |
Skykon | 3:c18342e4fddd | 551 | //switch2.rise(ResetTrim); |
Skykon | 3:c18342e4fddd | 552 | |
taknokolat | 7:8989a4b84695 | 553 | //NVIC_SetPriority(USART1_IRQn,0); |
taknokolat | 7:8989a4b84695 | 554 | //NVIC_SetPriority(EXTI0_IRQn,1); |
taknokolat | 7:8989a4b84695 | 555 | //NVIC_SetPriority(TIM5_IRQn,2); |
taknokolat | 7:8989a4b84695 | 556 | //NVIC_SetPriority(EXTI9_5_IRQn,3); |
taknokolat | 7:8989a4b84695 | 557 | //NVIC_SetPriority(USART2_IRQn,4); |
taknokolat | 7:8989a4b84695 | 558 | |
taknokolat | 7:8989a4b84695 | 559 | NVIC_SetPriority(USART1_IRQn,0);//割り込み優先度 |
taknokolat | 7:8989a4b84695 | 560 | NVIC_SetPriority(USART2_IRQn,1); |
taknokolat | 7:8989a4b84695 | 561 | |
Skykon | 3:c18342e4fddd | 562 | DisplayClock(); |
Skykon | 3:c18342e4fddd | 563 | t.start(); |
Skykon | 3:c18342e4fddd | 564 | |
Skykon | 3:c18342e4fddd | 565 | pc.printf("MPU calibration start\r\n"); |
taknokolat | 24:0ad1725c7849 | 566 | //pc.printf("HMC calibration start\r\n"); |
Skykon | 3:c18342e4fddd | 567 | |
Skykon | 3:c18342e4fddd | 568 | float offsetstart = t.read(); |
Skykon | 3:c18342e4fddd | 569 | while(t.read() - offsetstart < 26){ |
Skykon | 3:c18342e4fddd | 570 | SensingMPU(); |
taknokolat | 24:0ad1725c7849 | 571 | //SensingHMC(); |
Skykon | 3:c18342e4fddd | 572 | for(uint8_t i=0; i<3; i++) pc.printf("%3.2f\t",nowAngle[i]); |
taknokolat | 24:0ad1725c7849 | 573 | //pc.printf("\t%3.2f\t",nowAngle_HMC); |
Skykon | 3:c18342e4fddd | 574 | pc.printf("\r\n"); |
HARUKIDELTA | 23:29b2722bd753 | 575 | led1 = !led1; |
HARUKIDELTA | 23:29b2722bd753 | 576 | led2 = !led2; |
HARUKIDELTA | 23:29b2722bd753 | 577 | led3 = !led3; |
HARUKIDELTA | 23:29b2722bd753 | 578 | led4 = !led4; |
Skykon | 3:c18342e4fddd | 579 | } |
Skykon | 3:c18342e4fddd | 580 | |
Skykon | 3:c18342e4fddd | 581 | FirstROLL = nowAngle[ROLL]; |
Skykon | 3:c18342e4fddd | 582 | FirstPITCH = nowAngle[PITCH]; |
Skykon | 3:c18342e4fddd | 583 | nowAngle[ROLL] -=FirstROLL; |
Skykon | 3:c18342e4fddd | 584 | nowAngle[PITCH] -=FirstPITCH; |
taknokolat | 6:166746820555 | 585 | FirstYAW = nowAngle[YAW]; |
taknokolat | 6:166746820555 | 586 | nowAngle[YAW] -= FirstYAW; |
taknokolat | 6:166746820555 | 587 | |
taknokolat | 24:0ad1725c7849 | 588 | //g_FirstYAW_HMC = nowAngle_HMC; |
taknokolat | 24:0ad1725c7849 | 589 | //nowAngle_HMC -=g_FirstYAW_HMC; |
taknokolat | 24:0ad1725c7849 | 590 | //if(nowAngle_HMC<0)nowAngle_HMC+=360; |
Skykon | 3:c18342e4fddd | 591 | |
HARUKIDELTA | 23:29b2722bd753 | 592 | led1 = 0; |
HARUKIDELTA | 23:29b2722bd753 | 593 | led2 = 0; |
HARUKIDELTA | 23:29b2722bd753 | 594 | led3 = 0; |
HARUKIDELTA | 23:29b2722bd753 | 595 | led4 = 0; |
HARUKIDELTA | 23:29b2722bd753 | 596 | |
Skykon | 3:c18342e4fddd | 597 | wait(0.2); |
Skykon | 3:c18342e4fddd | 598 | |
HARUKIDELTA | 26:ea86e69563b5 | 599 | |
HARUKIDELTA | 26:ea86e69563b5 | 600 | g_fp = fopen( "/sd/Datalog01.txt" ,"a" ); |
HARUKIDELTA | 26:ea86e69563b5 | 601 | if( g_fp == NULL ) { |
HARUKIDELTA | 26:ea86e69563b5 | 602 | pc.printf( "ファイルオープンエラー\r\n" ); |
HARUKIDELTA | 26:ea86e69563b5 | 603 | } |
HARUKIDELTA | 26:ea86e69563b5 | 604 | fprintf(g_fp,"-------------------------\r\n"); |
HARUKIDELTA | 26:ea86e69563b5 | 605 | fprintf(g_fp,"All initialized.\r\n"); |
HARUKIDELTA | 26:ea86e69563b5 | 606 | fclose( g_fp ); |
HARUKIDELTA | 26:ea86e69563b5 | 607 | |
HARUKIDELTA | 26:ea86e69563b5 | 608 | |
Skykon | 3:c18342e4fddd | 609 | pc.printf("All initialized\r\n"); |
taknokolat | 4:67f705d42f1e | 610 | setupFlag=true; |
taknokolat | 1:290e621741fd | 611 | } |
taknokolat | 1:290e621741fd | 612 | |
Skykon | 3:c18342e4fddd | 613 | |
Skykon | 3:c18342e4fddd | 614 | void SensingMPU(){ |
Skykon | 3:c18342e4fddd | 615 | //static int16_t deltaT = 0, t_start = 0; |
Skykon | 3:c18342e4fddd | 616 | //t_start = t.read_us(); |
Skykon | 3:c18342e4fddd | 617 | |
taknokolat | 7:8989a4b84695 | 618 | float rpy[3] = {0}; |
Skykon | 3:c18342e4fddd | 619 | static uint16_t count_changeRPY = 0; |
Skykon | 3:c18342e4fddd | 620 | static bool flg_checkoutlier = false; |
Skykon | 3:c18342e4fddd | 621 | NVIC_DisableIRQ(USART1_IRQn); |
Skykon | 3:c18342e4fddd | 622 | NVIC_DisableIRQ(USART2_IRQn); |
Skykon | 3:c18342e4fddd | 623 | NVIC_DisableIRQ(TIM5_IRQn); |
Skykon | 3:c18342e4fddd | 624 | NVIC_DisableIRQ(EXTI0_IRQn); |
Skykon | 3:c18342e4fddd | 625 | NVIC_DisableIRQ(EXTI9_5_IRQn); |
Skykon | 3:c18342e4fddd | 626 | |
Skykon | 3:c18342e4fddd | 627 | mpu6050.getRollPitchYaw_Skipper(rpy); |
Skykon | 3:c18342e4fddd | 628 | |
Skykon | 3:c18342e4fddd | 629 | NVIC_EnableIRQ(USART1_IRQn); |
Skykon | 3:c18342e4fddd | 630 | NVIC_EnableIRQ(USART2_IRQn); |
Skykon | 3:c18342e4fddd | 631 | NVIC_EnableIRQ(TIM5_IRQn); |
Skykon | 3:c18342e4fddd | 632 | NVIC_EnableIRQ(EXTI0_IRQn); |
Skykon | 3:c18342e4fddd | 633 | NVIC_EnableIRQ(EXTI9_5_IRQn); |
Skykon | 3:c18342e4fddd | 634 | |
Skykon | 3:c18342e4fddd | 635 | |
Skykon | 3:c18342e4fddd | 636 | //外れ値対策 |
Skykon | 3:c18342e4fddd | 637 | for(uint8_t i=0; i<3; i++) rpy[i] *= 180.0f/PI; |
Skykon | 3:c18342e4fddd | 638 | rpy[ROLL] -= FirstROLL; |
Skykon | 3:c18342e4fddd | 639 | rpy[PITCH] -= FirstPITCH; |
taknokolat | 4:67f705d42f1e | 640 | if(!setupFlag){ |
taknokolat | 4:67f705d42f1e | 641 | rpy[YAW] -= FirstYAW; |
taknokolat | 4:67f705d42f1e | 642 | }else{ |
taknokolat | 4:67f705d42f1e | 643 | if(rpy[YAW] >= FirstYAW){ |
taknokolat | 4:67f705d42f1e | 644 | rpy[YAW] -= FirstYAW; |
taknokolat | 4:67f705d42f1e | 645 | }else{ |
taknokolat | 4:67f705d42f1e | 646 | rpy[YAW] += 360.0f; |
taknokolat | 4:67f705d42f1e | 647 | rpy[YAW] -= FirstYAW; |
taknokolat | 4:67f705d42f1e | 648 | } |
taknokolat | 4:67f705d42f1e | 649 | } |
Skykon | 3:c18342e4fddd | 650 | |
Skykon | 3:c18342e4fddd | 651 | 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 | 652 | if(!flg_checkoutlier || count_changeRPY >= 2){ |
Skykon | 3:c18342e4fddd | 653 | for(uint8_t i=0; i<3; i++){ |
Skykon | 3:c18342e4fddd | 654 | nowAngle[i] = (rpy[i] + nowAngle[i])/2.0f; //2つの移動平均 |
Skykon | 3:c18342e4fddd | 655 | } |
Skykon | 3:c18342e4fddd | 656 | count_changeRPY = 0; |
Skykon | 3:c18342e4fddd | 657 | }else count_changeRPY++; |
Skykon | 3:c18342e4fddd | 658 | flg_checkoutlier = false; |
Skykon | 3:c18342e4fddd | 659 | |
Skykon | 3:c18342e4fddd | 660 | } |
Skykon | 3:c18342e4fddd | 661 | |
Skykon | 3:c18342e4fddd | 662 | |
Skykon | 3:c18342e4fddd | 663 | void Init_sensors(){ |
Skykon | 3:c18342e4fddd | 664 | if(mpu6050.setup() == -1){ |
Skykon | 3:c18342e4fddd | 665 | pc.printf("failed initialize\r\n"); |
Skykon | 3:c18342e4fddd | 666 | } |
Skykon | 3:c18342e4fddd | 667 | } |
Skykon | 3:c18342e4fddd | 668 | |
Skykon | 3:c18342e4fddd | 669 | |
Skykon | 3:c18342e4fddd | 670 | void DisplayClock(){ |
Skykon | 3:c18342e4fddd | 671 | pc.printf("System Clock = %d[MHz]\r\n", HAL_RCC_GetSysClockFreq()/1000000); |
Skykon | 3:c18342e4fddd | 672 | pc.printf("HCLK Clock = %d[MHz]\r\n", HAL_RCC_GetHCLKFreq()/1000000); |
Skykon | 3:c18342e4fddd | 673 | pc.printf("PCLK1 Clock = %d[MHz]\r\n", HAL_RCC_GetPCLK1Freq()/1000000); |
Skykon | 3:c18342e4fddd | 674 | pc.printf("PCLK2 Clock = %d[MHz]\r\n", HAL_RCC_GetPCLK2Freq()/1000000); |
Skykon | 3:c18342e4fddd | 675 | pc.printf("\r\n"); |
taknokolat | 4:67f705d42f1e | 676 | } |
taknokolat | 6:166746820555 | 677 | |
taknokolat | 24:0ad1725c7849 | 678 | /*void SensingHMC(){ |
taknokolat | 6:166746820555 | 679 | //static int16_t deltaT = 0, t_start = 0; |
taknokolat | 6:166746820555 | 680 | //t_start = t.read_us(); |
taknokolat | 6:166746820555 | 681 | |
taknokolat | 7:8989a4b84695 | 682 | float rpy=0; |
taknokolat | 6:166746820555 | 683 | static uint16_t count_changeRPY = 0; |
taknokolat | 6:166746820555 | 684 | static bool flg_checkoutlier = false; |
taknokolat | 6:166746820555 | 685 | NVIC_DisableIRQ(USART1_IRQn); |
taknokolat | 6:166746820555 | 686 | NVIC_DisableIRQ(USART2_IRQn); |
taknokolat | 19:949bab1e9451 | 687 | //NVIC_DisableIRQ(TIM5_IRQn); |
taknokolat | 19:949bab1e9451 | 688 | //NVIC_DisableIRQ(EXTI0_IRQn); |
taknokolat | 19:949bab1e9451 | 689 | //NVIC_DisableIRQ(EXTI9_5_IRQn); |
taknokolat | 4:67f705d42f1e | 690 | |
taknokolat | 24:0ad1725c7849 | 691 | rpy= compass.getHeadingXYDeg(Time360,Match_wid); |
taknokolat | 6:166746820555 | 692 | |
taknokolat | 6:166746820555 | 693 | NVIC_EnableIRQ(USART1_IRQn); |
taknokolat | 6:166746820555 | 694 | NVIC_EnableIRQ(USART2_IRQn); |
taknokolat | 19:949bab1e9451 | 695 | //NVIC_EnableIRQ(TIM5_IRQn); |
taknokolat | 19:949bab1e9451 | 696 | //NVIC_EnableIRQ(EXTI0_IRQn); |
taknokolat | 19:949bab1e9451 | 697 | //NVIC_EnableIRQ(EXTI9_5_IRQn); |
taknokolat | 6:166746820555 | 698 | |
taknokolat | 6:166746820555 | 699 | |
taknokolat | 6:166746820555 | 700 | //外れ値対策 |
taknokolat | 6:166746820555 | 701 | //rpy*= 180.0f/PI; |
taknokolat | 6:166746820555 | 702 | if(!setupFlag){ |
taknokolat | 6:166746820555 | 703 | rpy -= g_FirstYAW_HMC; |
taknokolat | 6:166746820555 | 704 | }else{ |
taknokolat | 6:166746820555 | 705 | if(rpy >= g_FirstYAW_HMC){ |
taknokolat | 6:166746820555 | 706 | rpy -= g_FirstYAW_HMC; |
taknokolat | 6:166746820555 | 707 | }else{ |
taknokolat | 6:166746820555 | 708 | rpy += 360.0f; |
taknokolat | 6:166746820555 | 709 | rpy -= g_FirstYAW_HMC; |
taknokolat | 6:166746820555 | 710 | } |
taknokolat | 6:166746820555 | 711 | } |
taknokolat | 6:166746820555 | 712 | |
taknokolat | 6:166746820555 | 713 | if(rpy < nowAngle_HMC-10 || rpy > nowAngle_HMC+10) {flg_checkoutlier = true;} |
taknokolat | 6:166746820555 | 714 | if(!flg_checkoutlier || count_changeRPY >= 2){ |
taknokolat | 6:166746820555 | 715 | |
taknokolat | 6:166746820555 | 716 | nowAngle_HMC = (rpy + nowAngle_HMC)/2.0f; //2つの移動平均 |
taknokolat | 6:166746820555 | 717 | |
taknokolat | 6:166746820555 | 718 | count_changeRPY = 0; |
taknokolat | 6:166746820555 | 719 | }else count_changeRPY++; |
taknokolat | 6:166746820555 | 720 | flg_checkoutlier = false; |
taknokolat | 6:166746820555 | 721 | |
taknokolat | 24:0ad1725c7849 | 722 | }*/ |
taknokolat | 12:083662bca47d | 723 | |
taknokolat | 12:083662bca47d | 724 | int SetOptions(int *Servo_NEUTRAL_R, int *Servo_NEUTRAL_L, |
taknokolat | 12:083662bca47d | 725 | int *Servo_high_FORWARD_R, int *Servo_high_FORWARD_L, |
taknokolat | 12:083662bca47d | 726 | int *Servo_slow_FORWARD_R,int *Servo_slow_FORWARD_L, |
taknokolat | 12:083662bca47d | 727 | int *Turntable_NEUTRAL,int *Matchspeed,int *Focus_NEUTRAL, |
taknokolat | 16:26cee2aaf61d | 728 | int *Camera_deg_A, int *Camera_deg_B, |
HARUKIDELTA | 17:83db05cab3d1 | 729 | int *Pint_speed, float *Pint_wait, |
taknokolat | 19:949bab1e9451 | 730 | int *Turntable_speed, |
taknokolat | 24:0ad1725c7849 | 731 | int *Time360, int *Match_wid, |
taknokolat | 20:011977a37394 | 732 | int *Camera_board_wait |
taknokolat | 12:083662bca47d | 733 | ){ |
taknokolat | 12:083662bca47d | 734 | |
taknokolat | 12:083662bca47d | 735 | pc.printf("SDsetup start.\r\n"); |
taknokolat | 12:083662bca47d | 736 | |
taknokolat | 12:083662bca47d | 737 | FILE *fp; |
taknokolat | 12:083662bca47d | 738 | char parameter[20]; //文字列渡す用の配列 |
taknokolat | 12:083662bca47d | 739 | int SDerrorcount = 0; //取得できなかった数を返す |
taknokolat | 12:083662bca47d | 740 | const char *paramNames[] = { |
taknokolat | 12:083662bca47d | 741 | "SERVO_NEUTRAL_R", |
taknokolat | 12:083662bca47d | 742 | "SERVO_NEUTRAL_L", |
taknokolat | 12:083662bca47d | 743 | "SERVO_HIGH_FORWARD_R", |
taknokolat | 12:083662bca47d | 744 | "SERVO_HIGH_FORWARD_L", |
taknokolat | 12:083662bca47d | 745 | "SERVO_SLOW_FORWARD_R", |
taknokolat | 12:083662bca47d | 746 | "SERVO_SLOW_FORWARD_L", |
taknokolat | 12:083662bca47d | 747 | "TURNTABLE_NEUTRAL", |
taknokolat | 12:083662bca47d | 748 | "MATCH_SPEED", |
taknokolat | 12:083662bca47d | 749 | "FOCUS_NEUTRAL", |
taknokolat | 12:083662bca47d | 750 | "CAMERA_DEG_A", |
taknokolat | 16:26cee2aaf61d | 751 | "CAMERA_DEG_B", |
taknokolat | 16:26cee2aaf61d | 752 | "PINT_SPEED", |
HARUKIDELTA | 17:83db05cab3d1 | 753 | "PINT_WAIT", |
taknokolat | 19:949bab1e9451 | 754 | "TURNTABLE_SPEED", |
taknokolat | 24:0ad1725c7849 | 755 | "TIME360", |
taknokolat | 24:0ad1725c7849 | 756 | "MATCH_WID", |
taknokolat | 20:011977a37394 | 757 | "CAMERA_BOARD_WAIT" |
taknokolat | 12:083662bca47d | 758 | }; |
taknokolat | 12:083662bca47d | 759 | |
taknokolat | 12:083662bca47d | 760 | fp = fopen("/sd/option.txt","r"); |
taknokolat | 12:083662bca47d | 761 | |
taknokolat | 12:083662bca47d | 762 | if(fp != NULL){ //開けたら |
taknokolat | 12:083662bca47d | 763 | pc.printf("File was openned.\r\n"); |
taknokolat | 12:083662bca47d | 764 | if(GetParameter(fp,paramNames[0],parameter)) *Servo_NEUTRAL_R = atof(parameter); |
taknokolat | 12:083662bca47d | 765 | else{ *Servo_NEUTRAL_R = servo_NEUTRAL_R; |
taknokolat | 12:083662bca47d | 766 | SDerrorcount++; |
taknokolat | 12:083662bca47d | 767 | } |
taknokolat | 12:083662bca47d | 768 | if(GetParameter(fp,paramNames[1],parameter)) *Servo_NEUTRAL_L = atof(parameter); |
taknokolat | 12:083662bca47d | 769 | else{ *Servo_NEUTRAL_L = servo_NEUTRAL_L; |
taknokolat | 12:083662bca47d | 770 | SDerrorcount++; |
taknokolat | 12:083662bca47d | 771 | } |
taknokolat | 12:083662bca47d | 772 | if(GetParameter(fp,paramNames[2],parameter)) *Servo_high_FORWARD_R = atof(parameter); |
taknokolat | 12:083662bca47d | 773 | else{ *Servo_high_FORWARD_R = servo_high_FORWARD_R; |
taknokolat | 12:083662bca47d | 774 | SDerrorcount++; |
taknokolat | 12:083662bca47d | 775 | } |
taknokolat | 12:083662bca47d | 776 | if(GetParameter(fp,paramNames[3],parameter)) *Servo_high_FORWARD_L = atof(parameter); |
taknokolat | 12:083662bca47d | 777 | else{ *Servo_high_FORWARD_L = servo_high_FORWARD_L; |
taknokolat | 12:083662bca47d | 778 | SDerrorcount++; |
taknokolat | 12:083662bca47d | 779 | } |
taknokolat | 12:083662bca47d | 780 | if(GetParameter(fp,paramNames[4],parameter)) *Servo_slow_FORWARD_R = atof(parameter); |
taknokolat | 12:083662bca47d | 781 | else{ *Servo_slow_FORWARD_R = servo_slow_FORWARD_R; |
taknokolat | 12:083662bca47d | 782 | SDerrorcount++; |
taknokolat | 12:083662bca47d | 783 | } |
taknokolat | 12:083662bca47d | 784 | if(GetParameter(fp,paramNames[5],parameter)) *Servo_slow_FORWARD_L = atof(parameter); |
taknokolat | 12:083662bca47d | 785 | else{ *Servo_slow_FORWARD_L = servo_slow_FORWARD_L; |
taknokolat | 12:083662bca47d | 786 | SDerrorcount++; |
taknokolat | 12:083662bca47d | 787 | } |
taknokolat | 12:083662bca47d | 788 | |
taknokolat | 12:083662bca47d | 789 | if(GetParameter(fp,paramNames[6],parameter)) *Turntable_NEUTRAL = atof(parameter); |
taknokolat | 12:083662bca47d | 790 | else{ *Turntable_NEUTRAL = turntable_NEUTRAL; |
taknokolat | 12:083662bca47d | 791 | SDerrorcount++; |
taknokolat | 12:083662bca47d | 792 | } |
taknokolat | 12:083662bca47d | 793 | if(GetParameter(fp,paramNames[7],parameter)) *Matchspeed = atof(parameter); |
taknokolat | 12:083662bca47d | 794 | else{ *Matchspeed = matchspeed; |
taknokolat | 12:083662bca47d | 795 | SDerrorcount++; |
taknokolat | 12:083662bca47d | 796 | } |
taknokolat | 12:083662bca47d | 797 | if(GetParameter(fp,paramNames[8],parameter)) *Focus_NEUTRAL = atof(parameter); |
taknokolat | 12:083662bca47d | 798 | else{ *Focus_NEUTRAL = focus_NEUTRAL; |
taknokolat | 12:083662bca47d | 799 | SDerrorcount++; |
taknokolat | 12:083662bca47d | 800 | } |
taknokolat | 19:949bab1e9451 | 801 | if(GetParameter(fp,paramNames[9],parameter)) *Camera_deg_A = atof(parameter); |
taknokolat | 12:083662bca47d | 802 | else{ *Camera_deg_A = camera_deg_A; |
taknokolat | 12:083662bca47d | 803 | SDerrorcount++; |
taknokolat | 12:083662bca47d | 804 | } |
taknokolat | 19:949bab1e9451 | 805 | if(GetParameter(fp,paramNames[10],parameter)) *Camera_deg_B = atof(parameter); |
taknokolat | 12:083662bca47d | 806 | else{ *Camera_deg_B = camera_deg_B; |
taknokolat | 12:083662bca47d | 807 | SDerrorcount++; |
taknokolat | 12:083662bca47d | 808 | } |
taknokolat | 19:949bab1e9451 | 809 | if(GetParameter(fp,paramNames[11],parameter)) *Pint_speed = atof(parameter); |
taknokolat | 16:26cee2aaf61d | 810 | else{ *Pint_speed = pint_speed; |
taknokolat | 16:26cee2aaf61d | 811 | SDerrorcount++; |
taknokolat | 16:26cee2aaf61d | 812 | } |
taknokolat | 20:011977a37394 | 813 | if(GetParameter(fp,paramNames[12],parameter)) *Pint_wait = atof(parameter); |
taknokolat | 20:011977a37394 | 814 | else{ *Pint_wait = pint_wait; |
taknokolat | 16:26cee2aaf61d | 815 | SDerrorcount++; |
taknokolat | 16:26cee2aaf61d | 816 | } |
taknokolat | 19:949bab1e9451 | 817 | if(GetParameter(fp,paramNames[13],parameter)) *Turntable_speed = atof(parameter); |
HARUKIDELTA | 17:83db05cab3d1 | 818 | else{ *Turntable_speed = turntable_speed; |
HARUKIDELTA | 17:83db05cab3d1 | 819 | SDerrorcount++; |
HARUKIDELTA | 17:83db05cab3d1 | 820 | } |
taknokolat | 24:0ad1725c7849 | 821 | if(GetParameter(fp,paramNames[14],parameter)) *Time360 = atof(parameter); |
taknokolat | 24:0ad1725c7849 | 822 | else{ *Time360 = time360; |
taknokolat | 19:949bab1e9451 | 823 | SDerrorcount++; |
taknokolat | 19:949bab1e9451 | 824 | } |
taknokolat | 24:0ad1725c7849 | 825 | if(GetParameter(fp,paramNames[15],parameter)) *Match_wid = atof(parameter); |
taknokolat | 24:0ad1725c7849 | 826 | else{ *Match_wid = match_wid; |
taknokolat | 19:949bab1e9451 | 827 | SDerrorcount++; |
taknokolat | 19:949bab1e9451 | 828 | } |
taknokolat | 20:011977a37394 | 829 | if(GetParameter(fp,paramNames[16],parameter)) *Camera_board_wait = atof(parameter); |
taknokolat | 20:011977a37394 | 830 | else{ *Camera_board_wait = camera_board_wait; |
taknokolat | 20:011977a37394 | 831 | SDerrorcount++; |
taknokolat | 20:011977a37394 | 832 | } |
taknokolat | 12:083662bca47d | 833 | fclose(fp); |
taknokolat | 12:083662bca47d | 834 | |
taknokolat | 12:083662bca47d | 835 | }else{ //ファイルがなかったら |
taknokolat | 12:083662bca47d | 836 | pc.printf("fp was null.\r\n"); |
taknokolat | 12:083662bca47d | 837 | |
taknokolat | 12:083662bca47d | 838 | *Servo_NEUTRAL_R = servo_NEUTRAL_R; |
taknokolat | 12:083662bca47d | 839 | *Servo_NEUTRAL_L = servo_NEUTRAL_L; |
taknokolat | 12:083662bca47d | 840 | *Servo_high_FORWARD_R = servo_high_FORWARD_R; |
taknokolat | 12:083662bca47d | 841 | *Servo_high_FORWARD_L = servo_high_FORWARD_L; |
taknokolat | 12:083662bca47d | 842 | *Servo_slow_FORWARD_R = servo_slow_FORWARD_R; |
taknokolat | 12:083662bca47d | 843 | *Servo_slow_FORWARD_L = servo_slow_FORWARD_L; |
taknokolat | 12:083662bca47d | 844 | *Turntable_NEUTRAL = turntable_NEUTRAL; |
taknokolat | 12:083662bca47d | 845 | *Matchspeed = matchspeed; |
taknokolat | 12:083662bca47d | 846 | *Focus_NEUTRAL = focus_NEUTRAL; |
taknokolat | 12:083662bca47d | 847 | *Camera_deg_A = camera_deg_A; |
taknokolat | 12:083662bca47d | 848 | *Camera_deg_B = camera_deg_B; |
taknokolat | 16:26cee2aaf61d | 849 | *Pint_speed = pint_speed; |
taknokolat | 16:26cee2aaf61d | 850 | *Pint_wait = pint_wait; |
HARUKIDELTA | 17:83db05cab3d1 | 851 | *Turntable_speed = turntable_speed; |
taknokolat | 24:0ad1725c7849 | 852 | *Time360 = time360; |
taknokolat | 24:0ad1725c7849 | 853 | *Match_wid = match_wid; |
taknokolat | 22:a19be3b505b7 | 854 | *Camera_board_wait = camera_board_wait; |
taknokolat | 12:083662bca47d | 855 | SDerrorcount = -1; |
taknokolat | 12:083662bca47d | 856 | } |
taknokolat | 12:083662bca47d | 857 | pc.printf("SDsetup finished.\r\n"); |
taknokolat | 12:083662bca47d | 858 | if(SDerrorcount == 0) pc.printf("setting option is success\r\n"); |
taknokolat | 12:083662bca47d | 859 | else if(SDerrorcount == -1) pc.printf("ERROR 1. cannot open option\r\n"); |
taknokolat | 12:083662bca47d | 860 | else if(SDerrorcount > 0) pc.printf("ERROR 2. reading parameter is failed[%d]\r\n",SDerrorcount); |
taknokolat | 12:083662bca47d | 861 | |
taknokolat | 12:083662bca47d | 862 | pc.printf("Servo_NEUTRAL_R = %d, Servo_NEUTRAL_L = %d\r\n", *Servo_NEUTRAL_R, *Servo_NEUTRAL_L); |
taknokolat | 13:b088f0db7158 | 863 | 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 | 864 | 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 | 865 | pc.printf("Turntable_NEUTRAL = %d, Matchspeed = %d\r\n", *Turntable_NEUTRAL, *Matchspeed); |
taknokolat | 13:b088f0db7158 | 866 | pc.printf("Focus_NEUTRAL = %d\r\n", *Focus_NEUTRAL); |
taknokolat | 13:b088f0db7158 | 867 | pc.printf("Camera_deg_A = %d, Camera_deg_B = %d\r\n", *Camera_deg_A, *Camera_deg_B); |
taknokolat | 16:26cee2aaf61d | 868 | pc.printf("Pint_speed = %d, Pint_wait = %f\r\n", *Pint_speed, *Pint_wait); |
HARUKIDELTA | 17:83db05cab3d1 | 869 | pc.printf("Turntable_speed = %d\r\n",*Turntable_speed); |
taknokolat | 24:0ad1725c7849 | 870 | pc.printf("Time360 = %d, Match_wid = %d\r\n", *Time360, *Match_wid); |
taknokolat | 20:011977a37394 | 871 | pc.printf("Camera_board_wait = %d\r\n", *Camera_board_wait); |
taknokolat | 12:083662bca47d | 872 | |
taknokolat | 12:083662bca47d | 873 | return SDerrorcount; |
taknokolat | 12:083662bca47d | 874 | } |
taknokolat | 12:083662bca47d | 875 | int GetParameter(FILE *fp, const char *paramName,char parameter[]){ |
taknokolat | 12:083662bca47d | 876 | int i=0, j=0; |
taknokolat | 12:083662bca47d | 877 | int strmax = 200; |
taknokolat | 12:083662bca47d | 878 | char str[strmax]; |
taknokolat | 12:083662bca47d | 879 | |
taknokolat | 12:083662bca47d | 880 | rewind(fp); //ファイル位置を先頭に |
taknokolat | 12:083662bca47d | 881 | while(1){ |
taknokolat | 12:083662bca47d | 882 | if (fgets(str, strmax, fp) == NULL) { |
taknokolat | 12:083662bca47d | 883 | return 0; |
taknokolat | 12:083662bca47d | 884 | } |
taknokolat | 12:083662bca47d | 885 | if (!strncmp(str, paramName, strlen(paramName))) { |
taknokolat | 12:083662bca47d | 886 | while (str[i++] != '=') {} |
taknokolat | 12:083662bca47d | 887 | while (str[i] != '\n') { |
taknokolat | 12:083662bca47d | 888 | parameter[j++] = str[i++]; |
taknokolat | 12:083662bca47d | 889 | } |
taknokolat | 12:083662bca47d | 890 | parameter[j] = '\0'; |
taknokolat | 12:083662bca47d | 891 | return 1; |
taknokolat | 12:083662bca47d | 892 | } |
taknokolat | 12:083662bca47d | 893 | } |
taknokolat | 12:083662bca47d | 894 | } |
taknokolat | 12:083662bca47d | 895 | |
taknokolat | 12:083662bca47d | 896 | |
taknokolat | 6:166746820555 | 897 | |
taknokolat | 4:67f705d42f1e | 898 | void DebugPrint(){ |
taknokolat | 4:67f705d42f1e | 899 | //for(uint8_t i=0; i<3; i++) pc.printf("%3.2f\t",nowAngle[i]); //skipper地磁気センサ_デバック用 |
taknokolat | 7:8989a4b84695 | 900 | //pc.printf("%3.2f\t",nowAngle[2]); |
taknokolat | 7:8989a4b84695 | 901 | //pc.printf("%3.2f\t",nowAngle_HMC); //HMC |
taknokolat | 7:8989a4b84695 | 902 | //pc.printf("\r\n"); |
taknokolat | 6:166746820555 | 903 | } |