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