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