SDcard&LED updated

Dependencies:   HCSR04_2 MPU6050_2 mbed SDFileSystem3

Fork of Autoflight2018_49 by 航空研究会

Committer:
HARUKIDELTA
Date:
Tue Sep 25 10:27:21 2018 +0000
Revision:
39:b8d5be233b70
Parent:
38:ef0f39dfc98a
SDcard updated

Who changed what in which revision?

UserRevisionLine numberNew contents of line
HARUKIDELTA 0:17f575135219 1 //mbed
HARUKIDELTA 0:17f575135219 2 #include "mbed.h"
HARUKIDELTA 0:17f575135219 3 #include "FATFileSystem.h"
HARUKIDELTA 0:17f575135219 4 #include "SDFileSystem.h"
HARUKIDELTA 0:17f575135219 5 //C
HARUKIDELTA 0:17f575135219 6 #include "math.h"
HARUKIDELTA 0:17f575135219 7 //sensor
HARUKIDELTA 0:17f575135219 8 #include "MPU6050_DMP6.h"
HARUKIDELTA 0:17f575135219 9 //#include "MPU9250.h"
HARUKIDELTA 0:17f575135219 10 //#include "BMP280.h"
HARUKIDELTA 0:17f575135219 11 #include "hcsr04.h"
HARUKIDELTA 0:17f575135219 12 //device
HARUKIDELTA 0:17f575135219 13 #include "sbus.h"
HARUKIDELTA 0:17f575135219 14 //config
HARUKIDELTA 0:17f575135219 15 #include "SkipperSv2.h"
HARUKIDELTA 0:17f575135219 16 #include "falfalla.h"
HARUKIDELTA 0:17f575135219 17 //other
HARUKIDELTA 0:17f575135219 18 #include "pid.h"
HARUKIDELTA 0:17f575135219 19
HARUKIDELTA 0:17f575135219 20 #define DEBUG_SEMIAUTO 0
HARUKIDELTA 0:17f575135219 21 #define DEBUG_PRINT_INLOOP 1
HARUKIDELTA 0:17f575135219 22
TUATBM 9:f6367b7fd7be 23 #define KP_ELE 15.0 //2.0
HARUKIDELTA 0:17f575135219 24 #define KI_ELE 0.0
TUATBM 9:f6367b7fd7be 25 #define KD_ELE 0.0 //0/0
HARUKIDELTA 0:17f575135219 26 #define KP_RUD 3.0
HARUKIDELTA 0:17f575135219 27 #define KI_RUD 0.0
HARUKIDELTA 0:17f575135219 28 #define KD_RUD 0.0
HARUKIDELTA 2:23daa5fa28b4 29 #define KP_AIL 0.1
HARUKIDELTA 2:23daa5fa28b4 30 #define KI_AIL 0.2
HARUKIDELTA 2:23daa5fa28b4 31 #define KD_AIL 0.2
taknokolat 1:f383708a5a52 32
HARUKIDELTA 2:23daa5fa28b4 33 //#define g_AIL_L_Ratio_rightloop 0.5
HARUKIDELTA 0:17f575135219 34
HARUKIDELTA 0:17f575135219 35 #define GAIN_CONTROLVALUE_TO_PWM 3.0
HARUKIDELTA 0:17f575135219 36
HARUKIDELTA 0:17f575135219 37 #define RIGHT_ROLL -12.0
TUATBM 9:f6367b7fd7be 38 #define RIGHT_PITCH -10.0 //5.0
HARUKIDELTA 0:17f575135219 39 #define LEFT_ROLL 12.0
HARUKIDELTA 0:17f575135219 40 #define LEFT_PITCH -5.0
HARUKIDELTA 0:17f575135219 41 #define STRAIGHT_ROLL 4.0
HARUKIDELTA 0:17f575135219 42 #define STRAIGHT_PITCH 3.0
HARUKIDELTA 0:17f575135219 43 #define TAKEOFF_THR 0.8
HARUKIDELTA 0:17f575135219 44 #define LOOP_THR 0.6
HARUKIDELTA 0:17f575135219 45
HARUKIDELTA 13:77b13d5f4d78 46 //#define g_rightloopRUD 1500
HARUKIDELTA 2:23daa5fa28b4 47
HARUKIDELTA 0:17f575135219 48 #define RIGHT_ROLL_SHORT -12.0
HARUKIDELTA 0:17f575135219 49 #define RIGHT_PITCH_SHORT -5.0
HARUKIDELTA 0:17f575135219 50 #define LEFT_ROLL_SHORT 12.0
HARUKIDELTA 0:17f575135219 51 #define LEFT_PITCH_SHORT -5.0
HARUKIDELTA 39:b8d5be233b70 52 #define RIGHTLOOPROLL_APPROACH -17.0
HARUKIDELTA 39:b8d5be233b70 53 #define LEFTLOOPROLL_APPROACH 16.0
HARUKIDELTA 39:b8d5be233b70 54
HARUKIDELTA 0:17f575135219 55
HARUKIDELTA 27:61876b34ded4 56 #define rightloopROLL2 -10.0
HARUKIDELTA 27:61876b34ded4 57
HARUKIDELTA 17:55249ea37dff 58 /*#define rightloopRUD 1300 //1250
HARUKIDELTA 17:55249ea37dff 59 #define rightloopshortRUD 1250
HARUKIDELTA 17:55249ea37dff 60 #define leftloopRUD 1500
HARUKIDELTA 17:55249ea37dff 61 #define leftloopshortRUD 1500
HARUKIDELTA 17:55249ea37dff 62 #define glideloopRUD 1300
HARUKIDELTA 17:55249ea37dff 63 */
TUATBM 9:f6367b7fd7be 64 #define AIL_R_correctionrightloop 0
HARUKIDELTA 18:cce82f3374fc 65 #define AIL_L_correctionrightloop 0
HARUKIDELTA 3:206b17251f5b 66 #define AIL_L_correctionrightloopshort 0
HARUKIDELTA 3:206b17251f5b 67 #define AIL_L_correctionleftloop -0
HARUKIDELTA 3:206b17251f5b 68 #define AIL_L_correctionleftloopshort 0
HARUKIDELTA 3:206b17251f5b 69
HARUKIDELTA 19:0955311b0db6 70
HARUKIDELTA 8:66bba39b95a9 71 #define RIGHTLOOP_RUD 1250
HARUKIDELTA 8:66bba39b95a9 72 #define RIGHTLOOPSHORT_RUD 1250
HARUKIDELTA 8:66bba39b95a9 73 #define LEFTLOOP_RUD 1500
HARUKIDELTA 8:66bba39b95a9 74 #define LEFTLOOPSHORT_RUD 1500
HARUKIDELTA 39:b8d5be233b70 75 #define GLIDELOOP_RUD 1300
HARUKIDELTA 39:b8d5be233b70 76 #define RIGHTLOOPRUD_APPROACH 1500
HARUKIDELTA 39:b8d5be233b70 77 #define LEFTLOOPRUD_APPROACH 1500
HARUKIDELTA 39:b8d5be233b70 78
HARUKIDELTA 8:66bba39b95a9 79 #define AIL_L_CORRECTION_RIGHTLOOP 0
HARUKIDELTA 8:66bba39b95a9 80 #define AIL_L_CORRECTION_RIGHTLOOPSHORT 0
HARUKIDELTA 8:66bba39b95a9 81 #define AIL_L_CORRECTION_LEFTLOOP 0
HARUKIDELTA 8:66bba39b95a9 82 #define AIL_L_CORRECTION_LEFTLOOPSHORT 0
HARUKIDELTA 3:206b17251f5b 83
HARUKIDELTA 0:17f575135219 84 #define GLIDE_ROLL -12.0
HARUKIDELTA 0:17f575135219 85 #define GLIDE_PITCH -3.0
HARUKIDELTA 0:17f575135219 86
HARUKIDELTA 3:206b17251f5b 87
HARUKIDELTA 3:206b17251f5b 88 #define AIL_L_RatioRising 0.5
HARUKIDELTA 3:206b17251f5b 89 #define AIL_L_RatioDescent 2
HARUKIDELTA 3:206b17251f5b 90
HARUKIDELTA 0:17f575135219 91 //コンパスキャリブレーション
HARUKIDELTA 0:17f575135219 92 //SkipperS2基板
HARUKIDELTA 0:17f575135219 93 /*
HARUKIDELTA 0:17f575135219 94 #define MAGBIAS_X -35.0
HARUKIDELTA 0:17f575135219 95 #define MAGBIAS_Y 535.0
HARUKIDELTA 0:17f575135219 96 #define MAGBIAS_Z -50.0
HARUKIDELTA 0:17f575135219 97 */
HARUKIDELTA 0:17f575135219 98 //S2v2 1番基板
HARUKIDELTA 0:17f575135219 99 #define MAGBIAS_X 395.0
HARUKIDELTA 0:17f575135219 100 #define MAGBIAS_Y 505.0
HARUKIDELTA 0:17f575135219 101 #define MAGBIAS_Z -725.0
HARUKIDELTA 0:17f575135219 102 //S2v2 2番基板
HARUKIDELTA 0:17f575135219 103 /*
HARUKIDELTA 0:17f575135219 104 #define MAGBIAS_X 185.0
HARUKIDELTA 0:17f575135219 105 #define MAGBIAS_Y 220.0
HARUKIDELTA 0:17f575135219 106 #define MAGBIAS_Z -350.0
HARUKIDELTA 0:17f575135219 107 */
HARUKIDELTA 0:17f575135219 108
HARUKIDELTA 0:17f575135219 109 #define ELEMENT 1
HARUKIDELTA 0:17f575135219 110 #define LIMIT_STRAIGHT_YAW 5.0
HARUKIDELTA 0:17f575135219 111 #define THRESHOLD_TURNINGRADIUS_YAW 60.0
HARUKIDELTA 0:17f575135219 112 #define ALLOWHEIGHT 15
HARUKIDELTA 0:17f575135219 113
HARUKIDELTA 0:17f575135219 114 #ifndef PI
HARUKIDELTA 0:17f575135219 115 #define PI 3.14159265358979
HARUKIDELTA 0:17f575135219 116 #endif
HARUKIDELTA 0:17f575135219 117
HARUKIDELTA 0:17f575135219 118 const int16_t lengthdivpwm = 320;
HARUKIDELTA 0:17f575135219 119 const int16_t changeModeCount = 6;
HARUKIDELTA 0:17f575135219 120
HARUKIDELTA 0:17f575135219 121
HARUKIDELTA 0:17f575135219 122 SBUS sbus(PA_9, PA_10); //SBUS
HARUKIDELTA 0:17f575135219 123
HARUKIDELTA 0:17f575135219 124 PwmOut servo1(PC_6); // TIM3_CH1 //old echo
HARUKIDELTA 0:17f575135219 125 PwmOut servo2(PC_7); // TIM3_CH2 //PC_7
HARUKIDELTA 0:17f575135219 126 PwmOut servo3(PB_0); // TIM3_CH3
HARUKIDELTA 0:17f575135219 127 PwmOut servo4(PB_1); // TIM3_CH4
HARUKIDELTA 0:17f575135219 128 PwmOut servo5(PB_6); // TIM4_CH1
HARUKIDELTA 0:17f575135219 129 PwmOut servo6(PB_7); // TIM4_CH2 //old trigger
HARUKIDELTA 0:17f575135219 130 //PwmOut servo7(PB_8); // TIM4_CH3 //PB_8 new echo
HARUKIDELTA 0:17f575135219 131 //PwmOut servo8(PB_9); // TIM4_CH4 //new trigger
HARUKIDELTA 0:17f575135219 132
HARUKIDELTA 0:17f575135219 133 RawSerial pc(PA_2,PA_3, 115200); //tx,rx.baudrate pin;PA_2=UART2_TX, PA_3=UART2_RX
taknokolat 1:f383708a5a52 134 //RawSerial pc2(PB_6,PB_7, 115200); //sbus確認用
HARUKIDELTA 0:17f575135219 135 SDFileSystem sd(PB_15, PB_14, PB_13, PB_12, "sd");
HARUKIDELTA 0:17f575135219 136
HARUKIDELTA 0:17f575135219 137 DigitalOut led1(PA_0); //黄色のコネクタ
HARUKIDELTA 0:17f575135219 138 DigitalOut led2(PA_1);
HARUKIDELTA 0:17f575135219 139 DigitalOut led3(PB_4);
HARUKIDELTA 0:17f575135219 140 DigitalOut led4(PB_5);
HARUKIDELTA 0:17f575135219 141
HARUKIDELTA 0:17f575135219 142 //InterruptIn switch2(PC_14);
HARUKIDELTA 0:17f575135219 143 MPU6050DMP6 mpu6050(PC_0,&pc); //割り込みピン,シリアルポインタ i2cのピン指定は MPU6050>>I2Cdev.h 内のdefine
HARUKIDELTA 31:dba3216c2755 144 HCSR04 usensor(PB_9,PB_8); //trig,echo 9,8
HARUKIDELTA 0:17f575135219 145
taknokolat 1:f383708a5a52 146 PID pid_AIL(g_kpAIL,g_kiAIL,g_kdAIL);
HARUKIDELTA 0:17f575135219 147 PID pid_ELE(g_kpELE,g_kiELE,g_kdELE);
HARUKIDELTA 0:17f575135219 148 PID pid_RUD(g_kpRUD,g_kiRUD,g_kdRUD);
HARUKIDELTA 0:17f575135219 149
HARUKIDELTA 0:17f575135219 150 enum Channel{AIL_R, ELE, THR, RUD, DROP, AIL_L, Ch7, Ch8};
HARUKIDELTA 0:17f575135219 151 enum Angle{ROLL, PITCH, YAW}; //yaw:北を0とした絶対角度
HARUKIDELTA 0:17f575135219 152 enum OperationMode{StartUp, SemiAuto, RightLoop, LeftLoop, GoStraight, BombwithPC, ZERO, Moebius, Glide};
HARUKIDELTA 0:17f575135219 153 enum BombingMode{Takeoff, Chicken, Transition, Approach};
HARUKIDELTA 0:17f575135219 154 enum OutputStatus{Manual, Auto};
HARUKIDELTA 0:17f575135219 155
HARUKIDELTA 0:17f575135219 156 static OutputStatus output_status = Manual;
HARUKIDELTA 0:17f575135219 157 OperationMode operation_mode = StartUp;
HARUKIDELTA 0:17f575135219 158 BombingMode bombing_mode = Takeoff;
TUATBM 15:43427b0241d9 159
HARUKIDELTA 35:25e1afadd455 160 static int16_t autopwm[8] = {1455,1450,1176,1628,1512,1452};
HARUKIDELTA 35:25e1afadd455 161 /*
TUATBM 15:43427b0241d9 162 //1号機
taknokolat 30:624cb32e13a3 163 static int16_t trimpwm[6] = {1580,1600,1176,1404,1440,1448};
HARUKIDELTA 18:cce82f3374fc 164 int16_t maxpwm[6] = {1796,1936,1848,1740,1820,1856};
HARUKIDELTA 18:cce82f3374fc 165 int16_t minpwm[6] = {1182,1265,1176,1068,1180,1176};
TUATBM 15:43427b0241d9 166 const int16_t reverce[4] = {Reverce_falfalla[0],Reverce_falfalla[1],Reverce_falfalla[2],Reverce_falfalla[3]};
HARUKIDELTA 35:25e1afadd455 167 */
taknokolat 26:bc185a3d16b6 168
TUATBM 15:43427b0241d9 169 //2号機
HARUKIDELTA 35:25e1afadd455 170
HARUKIDELTA 35:25e1afadd455 171 static int16_t trimpwm[6] = {1455,1450,1176,1628,1512,1452};
HARUKIDELTA 35:25e1afadd455 172 int16_t maxpwm[6] = {1672,1786,1848,1964,1820,1860};
HARUKIDELTA 35:25e1afadd455 173 int16_t minpwm[6] = {1057,1115,1176,1292,1180,1180};
TUATBM 15:43427b0241d9 174 const int16_t reverce[4] = {Reverce_falfalla[0],Reverce_falfalla[1],Reverce_falfalla[2],Reverce_falfalla[3]};
HARUKIDELTA 35:25e1afadd455 175
TUATBM 15:43427b0241d9 176
HARUKIDELTA 0:17f575135219 177 int16_t oldTHR = 1000;
HARUKIDELTA 0:17f575135219 178
HARUKIDELTA 2:23daa5fa28b4 179 int16_t g_AIL_L_Ratio_rightloop = 0.5;
HARUKIDELTA 2:23daa5fa28b4 180
HARUKIDELTA 2:23daa5fa28b4 181
HARUKIDELTA 0:17f575135219 182 static float nowAngle[3] = {0,0,0};
HARUKIDELTA 0:17f575135219 183 const float trimAngle[3] = {0.0, 0.0, 0.0};
HARUKIDELTA 0:17f575135219 184 const float maxAngle[2] = {90, 90};
HARUKIDELTA 0:17f575135219 185 const float minAngle[2] = {-90, -90};
HARUKIDELTA 0:17f575135219 186
HARUKIDELTA 0:17f575135219 187 float FirstROLL = 0.0, FirstPITCH = 0.0 ,FirstYAW = 0.0;
HARUKIDELTA 0:17f575135219 188
HARUKIDELTA 0:17f575135219 189 unsigned int g_distance;
HARUKIDELTA 31:dba3216c2755 190 Ticker USsensor;
HARUKIDELTA 0:17f575135219 191 static char g_buf[16];
taknokolat 10:652071c20bf6 192 char g_landingcommand='Z';
HARUKIDELTA 0:17f575135219 193 float g_SerialTargetYAW;
HARUKIDELTA 0:17f575135219 194
HARUKIDELTA 0:17f575135219 195 Timer t;
HARUKIDELTA 27:61876b34ded4 196 Timer t2;
HARUKIDELTA 0:17f575135219 197 Timeout RerurnChickenServo1;
HARUKIDELTA 0:17f575135219 198 Timeout RerurnChickenServo2;
HARUKIDELTA 0:17f575135219 199
HARUKIDELTA 0:17f575135219 200 /*-----関数のプロトタイプ宣言-----*/
HARUKIDELTA 0:17f575135219 201 void setup();
HARUKIDELTA 0:17f575135219 202 void loop();
HARUKIDELTA 0:17f575135219 203
HARUKIDELTA 0:17f575135219 204 void Init_PWM();
HARUKIDELTA 0:17f575135219 205 void Init_servo(); //サーボ初期化
HARUKIDELTA 0:17f575135219 206 void Init_sbus(); //SBUS初期化
HARUKIDELTA 0:17f575135219 207 void Init_sensors();
HARUKIDELTA 0:17f575135219 208 void DisplayClock(); //クロック状態確認
HARUKIDELTA 0:17f575135219 209
HARUKIDELTA 0:17f575135219 210 //センサの値取得
HARUKIDELTA 0:17f575135219 211 void SensingMPU();
HARUKIDELTA 0:17f575135219 212 void UpdateDist();
HARUKIDELTA 0:17f575135219 213
HARUKIDELTA 0:17f575135219 214 //void offsetRollPitch(float FirstROLL, float FirstPITCH);
HARUKIDELTA 0:17f575135219 215 //void TransYaw(float FirstYAW);
HARUKIDELTA 0:17f575135219 216 float TranslateNewYaw(float beforeYaw, float newzeroYaw);
HARUKIDELTA 0:17f575135219 217 void UpdateTargetAngle(float targetAngle[3]);
HARUKIDELTA 0:17f575135219 218 void CalculateControlValue(float targetAngle[3], float controlValue[3]);
HARUKIDELTA 0:17f575135219 219 void UpdateAutoPWM(float controlValue[3]);
HARUKIDELTA 0:17f575135219 220 void ConvertPWMintoRAD(float targetAngle[3]);
HARUKIDELTA 0:17f575135219 221 inline float CalcRatio(float value, float trim, float limit);
HARUKIDELTA 0:17f575135219 222 bool CheckSW_Up(Channel ch);
HARUKIDELTA 0:17f575135219 223 int16_t ThresholdMaxMin(int16_t value, int16_t max, int16_t min);
HARUKIDELTA 0:17f575135219 224 inline int16_t SetTHRinRatio(float ratio);
HARUKIDELTA 0:17f575135219 225
HARUKIDELTA 0:17f575135219 226 //sbus割り込み
HARUKIDELTA 0:17f575135219 227 void Update_PWM(); //マニュアル・自動モードのpwmデータを整形しpwm変数に入力
HARUKIDELTA 0:17f575135219 228 void Output_PWM(int16_t pwm[6]); //pwmをサーボへ出力
HARUKIDELTA 0:17f575135219 229
HARUKIDELTA 0:17f575135219 230 //シリアル割り込み
HARUKIDELTA 0:17f575135219 231 void getSF_Serial();
HARUKIDELTA 0:17f575135219 232 float ConvertByteintoFloat(char high, char low);
TUATBM 15:43427b0241d9 233
HARUKIDELTA 0:17f575135219 234
HARUKIDELTA 0:17f575135219 235 //SD設定
HARUKIDELTA 0:17f575135219 236 int GetParameter(FILE *fp, const char *paramName,char parameter[]);
HARUKIDELTA 0:17f575135219 237 int SetOptions(float *g_kpELE, float *g_kiELE, float *g_kdELE,
HARUKIDELTA 0:17f575135219 238 float *g_kpRUD, float *g_kiRUD, float *g_kdRUD,
HARUKIDELTA 0:17f575135219 239 float *g_rightloopROLL, float *g_rightloopPITCH,
HARUKIDELTA 0:17f575135219 240 float *g_leftloopROLL, float *g_leftloopPITCH,
HARUKIDELTA 0:17f575135219 241 float *g_gostraightROLL, float *g_gostraightPITCH,
HARUKIDELTA 0:17f575135219 242 float *g_takeoffTHR, float *g_loopTHR,
HARUKIDELTA 0:17f575135219 243 float *g_rightloopROLLshort, float *g_rightloopPITCHshort,
HARUKIDELTA 0:17f575135219 244 float *g_leftloopROLLshort, float *g_leftloopPITCHshort,
HARUKIDELTA 12:763bf416ba4b 245 float *g_glideloopROLL, float *g_glideloopPITCH,
HARUKIDELTA 13:77b13d5f4d78 246 float *g_kpAIL, float *g_kiAIL, float *g_kdAIL,
HARUKIDELTA 13:77b13d5f4d78 247 int *g_rightloopRUD, int *g_rightloopshortRUD,
HARUKIDELTA 13:77b13d5f4d78 248 int *g_leftloopRUD, int *g_leftloopshortRUD,
HARUKIDELTA 13:77b13d5f4d78 249 int *g_glideRUD,
HARUKIDELTA 39:b8d5be233b70 250 float *g_rightloopROLL_approach,float *g_leftloopROLL_approach,
HARUKIDELTA 39:b8d5be233b70 251 int *g_rightloopRUD_approach,int *g_leftloopRUD_approach
HARUKIDELTA 13:77b13d5f4d78 252 );
HARUKIDELTA 0:17f575135219 253 //switch2割り込み
HARUKIDELTA 0:17f575135219 254 void ResetTrim();
HARUKIDELTA 0:17f575135219 255
HARUKIDELTA 0:17f575135219 256 //自動操縦
HARUKIDELTA 0:17f575135219 257 void UpdateTargetAngle_GoStraight(float targetAngle[3]);
HARUKIDELTA 19:0955311b0db6 258 void UpdateTargetAngle_GoStraight_zero(float targetAngle[3]); //着陸時にスロットルが0の時の直進
HARUKIDELTA 0:17f575135219 259 void UpdateTargetAngle_Rightloop(float targetAngle[3]);
HARUKIDELTA 0:17f575135219 260 void UpdateTargetAngle_Rightloop_short(float targetAngle[3]);
HARUKIDELTA 19:0955311b0db6 261 void UpdateTargetAngle_Rightloop_zero(float targetAngle[3]); //着陸時にスロットルが0の時の右旋回
HARUKIDELTA 0:17f575135219 262 void UpdateTargetAngle_Leftloop(float targetAngle[3]);
HARUKIDELTA 0:17f575135219 263 void UpdateTargetAngle_Leftloop_short(float targetAngle[3]);
HARUKIDELTA 19:0955311b0db6 264 void UpdateTargetAngle_Leftloop_zero(float targetAngle[3]); //着陸時にスロットルが0の時の左旋回
HARUKIDELTA 0:17f575135219 265 void UpdateTargetAngle_Moebius(float targetAngle[3]);
HARUKIDELTA 0:17f575135219 266 void UpdateTargetAngle_Glide(float targetAngle[3]);
HARUKIDELTA 0:17f575135219 267 void UpdateTargetAngle_Takeoff(float targetAngle[3]);
HARUKIDELTA 0:17f575135219 268 void UpdateTargetAngle_Approach(float targetAngle[3]);
HARUKIDELTA 0:17f575135219 269 void Take_off_and_landing(float targetAngle[3]);
HARUKIDELTA 0:17f575135219 270
HARUKIDELTA 0:17f575135219 271 int Rotate(float targetAngle[3], float TargetYAW);
HARUKIDELTA 0:17f575135219 272
HARUKIDELTA 0:17f575135219 273 //投下
HARUKIDELTA 0:17f575135219 274 void Chicken_Drop();
HARUKIDELTA 0:17f575135219 275 void ReturnChickenServo1();
HARUKIDELTA 0:17f575135219 276 void ReturnChickenServo2();
HARUKIDELTA 0:17f575135219 277
HARUKIDELTA 0:17f575135219 278 //超音波による高度補正
HARUKIDELTA 0:17f575135219 279 void checkHeight(float targetAngle[3]);
HARUKIDELTA 0:17f575135219 280 void UpdateTargetAngle_NoseUP(float targetAngle[3]);
HARUKIDELTA 0:17f575135219 281 void UpdateTargetAngle_NoseDOWN(float targetAngle[3]);
HARUKIDELTA 0:17f575135219 282
HARUKIDELTA 0:17f575135219 283 //デバッグ用
HARUKIDELTA 18:cce82f3374fc 284 void Sbusprintf();
HARUKIDELTA 0:17f575135219 285 void DebugPrint();
HARUKIDELTA 0:17f575135219 286
HARUKIDELTA 0:17f575135219 287 /*---関数のプロトタイプ宣言終わり---*/
HARUKIDELTA 0:17f575135219 288
HARUKIDELTA 0:17f575135219 289 int main()
HARUKIDELTA 0:17f575135219 290 {
HARUKIDELTA 0:17f575135219 291 setup();
HARUKIDELTA 0:17f575135219 292
HARUKIDELTA 0:17f575135219 293
HARUKIDELTA 0:17f575135219 294 while(1){
HARUKIDELTA 0:17f575135219 295
HARUKIDELTA 0:17f575135219 296 loop();
HARUKIDELTA 0:17f575135219 297
taknokolat 10:652071c20bf6 298
taknokolat 29:887a38540508 299 NVIC_DisableIRQ(USART1_IRQn);
HARUKIDELTA 0:17f575135219 300 if(!CheckSW_Up(Ch7)){
HARUKIDELTA 0:17f575135219 301 led3=0;
HARUKIDELTA 0:17f575135219 302 }else{
HARUKIDELTA 0:17f575135219 303 led3=1;
HARUKIDELTA 0:17f575135219 304 }
taknokolat 29:887a38540508 305 NVIC_EnableIRQ(USART1_IRQn);
HARUKIDELTA 0:17f575135219 306 }
HARUKIDELTA 0:17f575135219 307
HARUKIDELTA 0:17f575135219 308 }
HARUKIDELTA 0:17f575135219 309
HARUKIDELTA 0:17f575135219 310 void setup(){
HARUKIDELTA 0:17f575135219 311 //buzzer = 0;
HARUKIDELTA 0:17f575135219 312 led1 = 1;
HARUKIDELTA 0:17f575135219 313 led2 = 1;
HARUKIDELTA 0:17f575135219 314 led3 = 1;
HARUKIDELTA 0:17f575135219 315 led4 = 1;
HARUKIDELTA 0:17f575135219 316
HARUKIDELTA 0:17f575135219 317 SetOptions(&g_kpELE, &g_kiELE, &g_kdELE,
HARUKIDELTA 0:17f575135219 318 &g_kpRUD, &g_kiRUD, &g_kdRUD,
HARUKIDELTA 0:17f575135219 319 &g_rightloopROLL, &g_rightloopPITCH,
HARUKIDELTA 0:17f575135219 320 &g_leftloopROLL, &g_leftloopPITCH,
HARUKIDELTA 0:17f575135219 321 &g_gostraightROLL, &g_gostraightPITCH,
HARUKIDELTA 0:17f575135219 322 &g_takeoffTHR, &g_loopTHR,
HARUKIDELTA 0:17f575135219 323 &g_rightloopROLLshort, &g_rightloopPITCHshort,
HARUKIDELTA 0:17f575135219 324 &g_leftloopROLLshort, &g_leftloopPITCHshort,
HARUKIDELTA 12:763bf416ba4b 325 &g_glideloopROLL, &g_glideloopPITCH,
HARUKIDELTA 13:77b13d5f4d78 326 &g_kpAIL, &g_kiAIL,&g_kdAIL,
HARUKIDELTA 13:77b13d5f4d78 327 &g_rightloopRUD, &g_rightloopshortRUD,
HARUKIDELTA 13:77b13d5f4d78 328 &g_leftloopRUD, &g_leftloopshortRUD,
HARUKIDELTA 13:77b13d5f4d78 329 &g_glideloopRUD,
HARUKIDELTA 39:b8d5be233b70 330 &g_rightloopROLL_approach,&g_leftloopROLL_approach,
HARUKIDELTA 39:b8d5be233b70 331 &g_rightloopRUD_approach,&g_leftloopRUD_approach
HARUKIDELTA 13:77b13d5f4d78 332 );
HARUKIDELTA 0:17f575135219 333
HARUKIDELTA 0:17f575135219 334
HARUKIDELTA 0:17f575135219 335 Init_PWM();
HARUKIDELTA 0:17f575135219 336 Init_servo();
HARUKIDELTA 0:17f575135219 337 Init_sbus();
HARUKIDELTA 0:17f575135219 338 Init_sensors();
HARUKIDELTA 0:17f575135219 339 //switch2.rise(ResetTrim);
taknokolat 21:18fe7bf9e187 340
HARUKIDELTA 31:dba3216c2755 341 USsensor.attach(&UpdateDist, 0.05);
HARUKIDELTA 0:17f575135219 342
HARUKIDELTA 0:17f575135219 343 NVIC_SetPriority(USART1_IRQn,0);
HARUKIDELTA 0:17f575135219 344 NVIC_SetPriority(EXTI0_IRQn,1);
HARUKIDELTA 0:17f575135219 345 NVIC_SetPriority(TIM5_IRQn,2);
HARUKIDELTA 0:17f575135219 346 NVIC_SetPriority(EXTI9_5_IRQn,3);
HARUKIDELTA 0:17f575135219 347 DisplayClock();
HARUKIDELTA 0:17f575135219 348 t.start();
HARUKIDELTA 0:17f575135219 349
HARUKIDELTA 0:17f575135219 350
HARUKIDELTA 0:17f575135219 351 pc.printf("MPU calibration start\r\n");
HARUKIDELTA 0:17f575135219 352
HARUKIDELTA 0:17f575135219 353 float offsetstart = t.read();
HARUKIDELTA 0:17f575135219 354 while(t.read() - offsetstart < 26){
HARUKIDELTA 0:17f575135219 355 SensingMPU();
HARUKIDELTA 0:17f575135219 356 for(uint8_t i=0; i<3; i++) pc.printf("%3.2f\t",nowAngle[i]);
HARUKIDELTA 0:17f575135219 357 pc.printf("\r\n");
HARUKIDELTA 0:17f575135219 358 led1 = !led1;
HARUKIDELTA 0:17f575135219 359 led2 = !led2;
HARUKIDELTA 0:17f575135219 360 led3 = !led3;
HARUKIDELTA 0:17f575135219 361 led4 = !led4;
HARUKIDELTA 0:17f575135219 362 }
HARUKIDELTA 0:17f575135219 363
taknokolat 21:18fe7bf9e187 364 pc.attach(getSF_Serial, Serial::RxIrq);
taknokolat 21:18fe7bf9e187 365 NVIC_SetPriority(USART2_IRQn,4);
taknokolat 21:18fe7bf9e187 366
HARUKIDELTA 0:17f575135219 367 FirstROLL = nowAngle[ROLL];
HARUKIDELTA 0:17f575135219 368 FirstPITCH = nowAngle[PITCH];
HARUKIDELTA 0:17f575135219 369 nowAngle[ROLL] -=FirstROLL;
HARUKIDELTA 0:17f575135219 370 nowAngle[PITCH] -=FirstPITCH;
HARUKIDELTA 0:17f575135219 371
HARUKIDELTA 0:17f575135219 372 led1 = 0;
HARUKIDELTA 0:17f575135219 373 led2 = 0;
HARUKIDELTA 0:17f575135219 374 led3 = 0;
HARUKIDELTA 0:17f575135219 375 led4 = 0;
HARUKIDELTA 0:17f575135219 376 wait(0.2);
HARUKIDELTA 0:17f575135219 377
HARUKIDELTA 0:17f575135219 378
HARUKIDELTA 0:17f575135219 379 pc.printf("All initialized\r\n");
HARUKIDELTA 0:17f575135219 380 }
HARUKIDELTA 0:17f575135219 381
HARUKIDELTA 0:17f575135219 382 void loop(){
HARUKIDELTA 0:17f575135219 383 static float targetAngle[3] = {0.0, 0.0, 0.0}, controlValue[2] = {0.0, 0.0};
HARUKIDELTA 0:17f575135219 384 SensingMPU();
HARUKIDELTA 0:17f575135219 385 UpdateTargetAngle(targetAngle);
HARUKIDELTA 0:17f575135219 386 CalculateControlValue(targetAngle, controlValue);
HARUKIDELTA 0:17f575135219 387 UpdateAutoPWM(controlValue);
taknokolat 28:aa44903a01e1 388
taknokolat 25:37bee299a276 389
taknokolat 28:aa44903a01e1 390 //NVIC_SetPriority(TIM5_IRQn,4);
taknokolat 28:aa44903a01e1 391 //NVIC_SetPriority(USART2_IRQn,2);
taknokolat 25:37bee299a276 392
taknokolat 11:c0b9ad25d3db 393 wait_ms(23);
taknokolat 25:37bee299a276 394
taknokolat 28:aa44903a01e1 395 //NVIC_SetPriority(TIM5_IRQn,2);
taknokolat 28:aa44903a01e1 396 //NVIC_SetPriority(USART2_IRQn,4);
taknokolat 25:37bee299a276 397
taknokolat 25:37bee299a276 398
taknokolat 25:37bee299a276 399 // pc.printf("6\r\n");
taknokolat 25:37bee299a276 400 //NVIC_DisableIRQ(USART2_IRQn);
taknokolat 25:37bee299a276 401 //pc.printf("%c",g_landingcommand);
taknokolat 25:37bee299a276 402 //NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 0:17f575135219 403 #if DEBUG_PRINT_INLOOP
taknokolat 30:624cb32e13a3 404 //Sbusprintf();
HARUKIDELTA 31:dba3216c2755 405 DebugPrint();
HARUKIDELTA 0:17f575135219 406 #endif
HARUKIDELTA 0:17f575135219 407 }
HARUKIDELTA 0:17f575135219 408
HARUKIDELTA 0:17f575135219 409 //サーボ初期化関数
HARUKIDELTA 0:17f575135219 410 void Init_servo(){
HARUKIDELTA 0:17f575135219 411
HARUKIDELTA 0:17f575135219 412 servo1.period_ms(14);
HARUKIDELTA 0:17f575135219 413 servo1.pulsewidth_us(trimpwm[AIL_R]);
HARUKIDELTA 0:17f575135219 414
HARUKIDELTA 0:17f575135219 415 servo2.period_ms(14);
HARUKIDELTA 0:17f575135219 416 servo2.pulsewidth_us(trimpwm[ELE]);
HARUKIDELTA 0:17f575135219 417
HARUKIDELTA 0:17f575135219 418 servo3.period_ms(14);
HARUKIDELTA 0:17f575135219 419 servo3.pulsewidth_us(trimpwm[THR]);
HARUKIDELTA 0:17f575135219 420
HARUKIDELTA 0:17f575135219 421 servo4.period_ms(14);
HARUKIDELTA 0:17f575135219 422 servo4.pulsewidth_us(trimpwm[RUD]);
HARUKIDELTA 0:17f575135219 423
HARUKIDELTA 0:17f575135219 424 servo5.period_ms(14);
taknokolat 28:aa44903a01e1 425 servo5.pulsewidth_us(trimpwm[DROP]);
HARUKIDELTA 0:17f575135219 426
HARUKIDELTA 0:17f575135219 427 servo6.period_ms(14);
HARUKIDELTA 0:17f575135219 428 servo6.pulsewidth_us(trimpwm[AIL_L]);
HARUKIDELTA 0:17f575135219 429
HARUKIDELTA 0:17f575135219 430 pc.printf("servo initialized\r\n");
HARUKIDELTA 0:17f575135219 431 }
HARUKIDELTA 0:17f575135219 432
HARUKIDELTA 0:17f575135219 433 //Sbus初期化
HARUKIDELTA 0:17f575135219 434 void Init_sbus(){
HARUKIDELTA 0:17f575135219 435 sbus.initialize();
HARUKIDELTA 0:17f575135219 436 sbus.setLastfuncPoint(Update_PWM);
HARUKIDELTA 0:17f575135219 437 sbus.startInterrupt();
HARUKIDELTA 0:17f575135219 438 }
HARUKIDELTA 0:17f575135219 439
HARUKIDELTA 0:17f575135219 440 void Init_sensors(){
HARUKIDELTA 0:17f575135219 441 if(mpu6050.setup() == -1){
HARUKIDELTA 0:17f575135219 442 pc.printf("failed initialize\r\n");
HARUKIDELTA 0:17f575135219 443 while(1){
HARUKIDELTA 0:17f575135219 444 led1 = 1; led2 = 0; led3 = 1; led4 = 0;
HARUKIDELTA 0:17f575135219 445 wait(1);
HARUKIDELTA 0:17f575135219 446 led1 = 0; led2 = 1; led3 = 0; led4 = 1;
HARUKIDELTA 0:17f575135219 447 wait(1);
HARUKIDELTA 0:17f575135219 448 }
HARUKIDELTA 0:17f575135219 449 }
HARUKIDELTA 0:17f575135219 450 }
HARUKIDELTA 0:17f575135219 451
HARUKIDELTA 0:17f575135219 452 void Init_PWM(){
HARUKIDELTA 0:17f575135219 453 pc.printf("PWM initialized\r\n");
HARUKIDELTA 0:17f575135219 454 }
HARUKIDELTA 0:17f575135219 455
HARUKIDELTA 0:17f575135219 456 void DisplayClock(){
HARUKIDELTA 0:17f575135219 457 pc.printf("System Clock = %d[MHz]\r\n", HAL_RCC_GetSysClockFreq()/1000000);
HARUKIDELTA 0:17f575135219 458 pc.printf("HCLK Clock = %d[MHz]\r\n", HAL_RCC_GetHCLKFreq()/1000000);
HARUKIDELTA 0:17f575135219 459 pc.printf("PCLK1 Clock = %d[MHz]\r\n", HAL_RCC_GetPCLK1Freq()/1000000);
HARUKIDELTA 0:17f575135219 460 pc.printf("PCLK2 Clock = %d[MHz]\r\n", HAL_RCC_GetPCLK2Freq()/1000000);
HARUKIDELTA 0:17f575135219 461 pc.printf("\r\n");
HARUKIDELTA 0:17f575135219 462 }
HARUKIDELTA 0:17f575135219 463
HARUKIDELTA 0:17f575135219 464 void UpdateTargetAngle(float targetAngle[3]){
taknokolat 28:aa44903a01e1 465
taknokolat 28:aa44903a01e1 466
HARUKIDELTA 0:17f575135219 467 static int16_t count_op = 0;
HARUKIDELTA 0:17f575135219 468 #if DEBUG_SEMIAUTO
HARUKIDELTA 0:17f575135219 469 switch(operation_mode){
HARUKIDELTA 0:17f575135219 470 case StartUp:
HARUKIDELTA 0:17f575135219 471 if(!CheckSW_Up(Ch7) && CheckSW_Up(Ch8)){
HARUKIDELTA 0:17f575135219 472 count_op++;
HARUKIDELTA 0:17f575135219 473 if(count_op > changeModeCount){
HARUKIDELTA 0:17f575135219 474 operation_mode = SemiAuto;
HARUKIDELTA 0:17f575135219 475 pc.printf("Goto SemiAuto mode\r\n");
HARUKIDELTA 0:17f575135219 476 count_op = 0;
HARUKIDELTA 0:17f575135219 477 }
HARUKIDELTA 0:17f575135219 478 }else count_op = 0;
HARUKIDELTA 0:17f575135219 479 break;
HARUKIDELTA 0:17f575135219 480
HARUKIDELTA 0:17f575135219 481 case SemiAuto:
HARUKIDELTA 0:17f575135219 482 /* 大会用では以下のif文を入れてoperation_modeを変える
HARUKIDELTA 0:17f575135219 483 if(CheckSW_Up(Ch6)){
HARUKIDELTA 0:17f575135219 484 count_op++;
HARUKIDELTA 0:17f575135219 485 if(count_op>changeModeCount){
HARUKIDELTA 0:17f575135219 486 output_status = XXX;
HARUKIDELTA 0:17f575135219 487 led2 = 0;
HARUKIDELTA 0:17f575135219 488 pc.printf("Goto XXX mode\r\n");
HARUKIDELTA 0:17f575135219 489 count_op = 0;
HARUKIDELTA 0:17f575135219 490 }else count_op = 0;
HARUKIDELTA 0:17f575135219 491 ConvertPWMintoRAD(targetAngle);
HARUKIDELTA 0:17f575135219 492 }
HARUKIDELTA 0:17f575135219 493 */
HARUKIDELTA 0:17f575135219 494 ConvertPWMintoRAD(targetAngle);
HARUKIDELTA 0:17f575135219 495 break;
HARUKIDELTA 0:17f575135219 496
HARUKIDELTA 0:17f575135219 497 default:
HARUKIDELTA 0:17f575135219 498 operation_mode = SemiAuto;
HARUKIDELTA 0:17f575135219 499 break;
HARUKIDELTA 0:17f575135219 500 }
HARUKIDELTA 0:17f575135219 501
HARUKIDELTA 0:17f575135219 502 #else
HARUKIDELTA 0:17f575135219 503
HARUKIDELTA 0:17f575135219 504 switch(operation_mode){
HARUKIDELTA 0:17f575135219 505 case StartUp:
HARUKIDELTA 0:17f575135219 506 if(!CheckSW_Up(Ch7) && !CheckSW_Up(Ch8)){ //ch7;自動・手動切り替え ch8;自動操縦モード切替
HARUKIDELTA 0:17f575135219 507 count_op++;
HARUKIDELTA 0:17f575135219 508 if(count_op > changeModeCount){
HARUKIDELTA 0:17f575135219 509 operation_mode = RightLoop;
HARUKIDELTA 0:17f575135219 510 pc.printf("Goto RightLoop mode\r\n");
HARUKIDELTA 0:17f575135219 511 count_op = 0;
HARUKIDELTA 0:17f575135219 512 }
HARUKIDELTA 0:17f575135219 513 }else count_op = 0;
HARUKIDELTA 0:17f575135219 514 break;
HARUKIDELTA 0:17f575135219 515
HARUKIDELTA 0:17f575135219 516 case RightLoop:
HARUKIDELTA 0:17f575135219 517 if(!CheckSW_Up(Ch7) && CheckSW_Up(Ch8)){
HARUKIDELTA 0:17f575135219 518 count_op++;
HARUKIDELTA 0:17f575135219 519 if(count_op > changeModeCount){
HARUKIDELTA 0:17f575135219 520 operation_mode = LeftLoop;
HARUKIDELTA 0:17f575135219 521 pc.printf("Goto LeftLoop mode\r\n");
HARUKIDELTA 0:17f575135219 522 count_op = 0;
HARUKIDELTA 0:17f575135219 523 }
HARUKIDELTA 0:17f575135219 524 }else count_op = 0;
HARUKIDELTA 0:17f575135219 525 UpdateTargetAngle_Rightloop(targetAngle);
HARUKIDELTA 0:17f575135219 526
HARUKIDELTA 0:17f575135219 527 break;
HARUKIDELTA 0:17f575135219 528
HARUKIDELTA 0:17f575135219 529 case LeftLoop:
HARUKIDELTA 0:17f575135219 530 if(!CheckSW_Up(Ch7) && !CheckSW_Up(Ch8)){
HARUKIDELTA 0:17f575135219 531 count_op++;
HARUKIDELTA 0:17f575135219 532 if(count_op > changeModeCount){
HARUKIDELTA 0:17f575135219 533 operation_mode = GoStraight;
HARUKIDELTA 0:17f575135219 534 pc.printf("Goto GoStraight mode\r\n");
HARUKIDELTA 0:17f575135219 535 count_op = 0;
HARUKIDELTA 0:17f575135219 536 }
HARUKIDELTA 0:17f575135219 537 }else count_op = 0;
HARUKIDELTA 0:17f575135219 538 UpdateTargetAngle_Leftloop(targetAngle);
HARUKIDELTA 0:17f575135219 539 break;
HARUKIDELTA 0:17f575135219 540
HARUKIDELTA 0:17f575135219 541 case GoStraight:
HARUKIDELTA 0:17f575135219 542 if(!CheckSW_Up(Ch7) && CheckSW_Up(Ch8)){
HARUKIDELTA 0:17f575135219 543 count_op++;
HARUKIDELTA 0:17f575135219 544 if(count_op > changeModeCount){
HARUKIDELTA 0:17f575135219 545 operation_mode = Moebius;
HARUKIDELTA 0:17f575135219 546 pc.printf("Goto Moebius mode\r\n");
HARUKIDELTA 0:17f575135219 547 count_op = 0;
HARUKIDELTA 0:17f575135219 548 }
HARUKIDELTA 0:17f575135219 549 }else count_op = 0;
HARUKIDELTA 0:17f575135219 550 UpdateTargetAngle_GoStraight(targetAngle);
HARUKIDELTA 0:17f575135219 551 break;
HARUKIDELTA 0:17f575135219 552
HARUKIDELTA 0:17f575135219 553 case Moebius:
HARUKIDELTA 0:17f575135219 554 if(!CheckSW_Up(Ch7) && !CheckSW_Up(Ch8)){
HARUKIDELTA 0:17f575135219 555 count_op++;
HARUKIDELTA 0:17f575135219 556 if(count_op > changeModeCount){
HARUKIDELTA 0:17f575135219 557 operation_mode = Glide;
HARUKIDELTA 0:17f575135219 558 pc.printf("Goto Glide mode\r\n");
HARUKIDELTA 0:17f575135219 559 count_op = 0;
HARUKIDELTA 0:17f575135219 560 }
HARUKIDELTA 0:17f575135219 561 }else count_op = 0;
HARUKIDELTA 0:17f575135219 562 UpdateTargetAngle_Moebius(targetAngle);
HARUKIDELTA 0:17f575135219 563 break;
HARUKIDELTA 0:17f575135219 564
HARUKIDELTA 0:17f575135219 565 case Glide:
HARUKIDELTA 0:17f575135219 566 if(!CheckSW_Up(Ch7) && CheckSW_Up(Ch8)){
HARUKIDELTA 0:17f575135219 567 count_op++;
HARUKIDELTA 0:17f575135219 568 if(count_op > changeModeCount){
HARUKIDELTA 0:17f575135219 569 operation_mode = BombwithPC;
HARUKIDELTA 0:17f575135219 570 pc.printf("Goto Bombing mode\r\n");
taknokolat 32:48d5d3f77c41 571 pc.attach(getSF_Serial, Serial::RxIrq);
HARUKIDELTA 0:17f575135219 572 count_op = 0;
HARUKIDELTA 0:17f575135219 573 }
HARUKIDELTA 0:17f575135219 574 }else count_op = 0;
HARUKIDELTA 0:17f575135219 575 UpdateTargetAngle_Glide(targetAngle);
HARUKIDELTA 0:17f575135219 576 break;
HARUKIDELTA 0:17f575135219 577
HARUKIDELTA 0:17f575135219 578 case BombwithPC:
HARUKIDELTA 0:17f575135219 579 if(!CheckSW_Up(Ch7) && !CheckSW_Up(Ch8)){
HARUKIDELTA 0:17f575135219 580 count_op++;
HARUKIDELTA 0:17f575135219 581 if(count_op > changeModeCount){
HARUKIDELTA 0:17f575135219 582 operation_mode = RightLoop;
HARUKIDELTA 0:17f575135219 583 pc.printf("Goto RightLoop mode\r\n");
taknokolat 32:48d5d3f77c41 584 pc.attach(NULL, Serial::RxIrq);
HARUKIDELTA 0:17f575135219 585 count_op = 0;
HARUKIDELTA 0:17f575135219 586 }
HARUKIDELTA 0:17f575135219 587 }else count_op = 0;
HARUKIDELTA 0:17f575135219 588 Take_off_and_landing(targetAngle);
HARUKIDELTA 0:17f575135219 589 break;
HARUKIDELTA 0:17f575135219 590
HARUKIDELTA 0:17f575135219 591 default:
HARUKIDELTA 0:17f575135219 592 operation_mode = StartUp;
HARUKIDELTA 0:17f575135219 593 break;
HARUKIDELTA 0:17f575135219 594 }
HARUKIDELTA 0:17f575135219 595 #endif
HARUKIDELTA 0:17f575135219 596
taknokolat 26:bc185a3d16b6 597 if(CheckSW_Up(Ch7)){
taknokolat 26:bc185a3d16b6 598 output_status = Auto;
taknokolat 26:bc185a3d16b6 599 led1 = 1;
taknokolat 26:bc185a3d16b6 600 }else{
taknokolat 26:bc185a3d16b6 601 output_status = Manual;
taknokolat 26:bc185a3d16b6 602 led1 = 0;
taknokolat 26:bc185a3d16b6 603 }
taknokolat 26:bc185a3d16b6 604
taknokolat 28:aa44903a01e1 605
HARUKIDELTA 0:17f575135219 606 }
HARUKIDELTA 0:17f575135219 607
HARUKIDELTA 0:17f575135219 608 int GetParameter(FILE *fp, const char *paramName,char parameter[]){
HARUKIDELTA 0:17f575135219 609 int i=0, j=0;
HARUKIDELTA 0:17f575135219 610 int strmax = 200;
HARUKIDELTA 0:17f575135219 611 char str[strmax];
HARUKIDELTA 0:17f575135219 612
HARUKIDELTA 0:17f575135219 613 rewind(fp); //ファイル位置を先頭に
HARUKIDELTA 0:17f575135219 614 while(1){
HARUKIDELTA 0:17f575135219 615 if (fgets(str, strmax, fp) == NULL) {
HARUKIDELTA 0:17f575135219 616 return 0;
HARUKIDELTA 0:17f575135219 617 }
HARUKIDELTA 0:17f575135219 618 if (!strncmp(str, paramName, strlen(paramName))) {
HARUKIDELTA 0:17f575135219 619 while (str[i++] != '=') {}
HARUKIDELTA 0:17f575135219 620 while (str[i] != '\n') {
HARUKIDELTA 0:17f575135219 621 parameter[j++] = str[i++];
HARUKIDELTA 0:17f575135219 622 }
HARUKIDELTA 0:17f575135219 623 parameter[j] = '\0';
HARUKIDELTA 0:17f575135219 624 return 1;
HARUKIDELTA 0:17f575135219 625 }
HARUKIDELTA 0:17f575135219 626 }
HARUKIDELTA 0:17f575135219 627 }
HARUKIDELTA 0:17f575135219 628
HARUKIDELTA 0:17f575135219 629
HARUKIDELTA 0:17f575135219 630 //sdによる設定
HARUKIDELTA 0:17f575135219 631 int SetOptions(float *g_kpELE, float *g_kiELE, float *g_kdELE,
HARUKIDELTA 0:17f575135219 632 float *g_kpRUD, float *g_kiRUD, float *g_kdRUD,
HARUKIDELTA 0:17f575135219 633 float *g_rightloopROLL, float *g_rightloopPITCH,
HARUKIDELTA 0:17f575135219 634 float *g_leftloopROLL, float *g_leftloopPITCH,
HARUKIDELTA 0:17f575135219 635 float *g_gostraightROLL, float *g_gostraightPITCH,
HARUKIDELTA 0:17f575135219 636 float *g_takeoffTHR, float *g_loopTHR,
HARUKIDELTA 0:17f575135219 637 float *g_rightloopROLLshort, float *g_rightloopPITCHshort,
HARUKIDELTA 0:17f575135219 638 float *g_leftloopROLLshort, float *g_leftloopPITCHshort,
HARUKIDELTA 12:763bf416ba4b 639 float *g_glideloopROLL, float *g_glideloopPITCH,
HARUKIDELTA 13:77b13d5f4d78 640 float *g_kpAIL, float *g_kiAIL, float *g_kdAIL,
HARUKIDELTA 13:77b13d5f4d78 641 int *g_rightloopRUD, int *g_rightloopshortRUD,
HARUKIDELTA 13:77b13d5f4d78 642 int *g_leftloopRUD, int *g_leftloopshortRUD,
HARUKIDELTA 13:77b13d5f4d78 643 int *g_glideloopRUD,
HARUKIDELTA 39:b8d5be233b70 644 float *g_rightloopROLL_approach,float *g_leftloopROLL_approach,
HARUKIDELTA 39:b8d5be233b70 645 int *g_rightloopRUD_approach,int *g_leftloopRUD_approach
HARUKIDELTA 0:17f575135219 646 ){
HARUKIDELTA 0:17f575135219 647
HARUKIDELTA 0:17f575135219 648 pc.printf("SDsetup start.\r\n");
HARUKIDELTA 0:17f575135219 649
HARUKIDELTA 0:17f575135219 650 FILE *fp;
HARUKIDELTA 13:77b13d5f4d78 651 char parameter[40]; //文字列渡す用の配列
HARUKIDELTA 0:17f575135219 652 int SDerrorcount = 0; //取得できなかった数を返す
HARUKIDELTA 0:17f575135219 653 const char *paramNames[] = {
HARUKIDELTA 0:17f575135219 654 "KP_ELEVATOR",
HARUKIDELTA 0:17f575135219 655 "KI_ELEVATOR",
HARUKIDELTA 0:17f575135219 656 "KD_ELEVATOR",
HARUKIDELTA 0:17f575135219 657 "KP_RUDDER",
HARUKIDELTA 0:17f575135219 658 "KI_RUDDER",
HARUKIDELTA 0:17f575135219 659 "KD_RUDDER",
HARUKIDELTA 0:17f575135219 660 "RIGHTLOOP_ROLL",
HARUKIDELTA 0:17f575135219 661 "RIGHTLOOP_PITCH",
HARUKIDELTA 0:17f575135219 662 "LEFTLOOP_ROLL",
HARUKIDELTA 0:17f575135219 663 "LEFTLOOP_PITCH",
HARUKIDELTA 0:17f575135219 664 "GOSTRAIGHT_ROLL",
HARUKIDELTA 0:17f575135219 665 "GOSTRAIGHT_PITCH",
HARUKIDELTA 0:17f575135219 666 "TAKEOFF_THR_RATE",
HARUKIDELTA 0:17f575135219 667 "LOOP_THR_RATE",
HARUKIDELTA 0:17f575135219 668 "RIGHTLOOP_ROLL_SHORT",
HARUKIDELTA 0:17f575135219 669 "RIGHTLOOP_PITCH_SHORT",
HARUKIDELTA 0:17f575135219 670 "LEFTLOOP_ROLL_SHORT",
HARUKIDELTA 0:17f575135219 671 "LEFTLOOP_PITCH_SHORT",
HARUKIDELTA 0:17f575135219 672 "AUTOGLIDE_ROLL",
HARUKIDELTA 12:763bf416ba4b 673 "AUTOGLIDE PITCH",
HARUKIDELTA 12:763bf416ba4b 674 "KP_AILERON",
HARUKIDELTA 12:763bf416ba4b 675 "KI_AILERON",
HARUKIDELTA 13:77b13d5f4d78 676 "KD_AILERON",
HARUKIDELTA 13:77b13d5f4d78 677 "RIGHTLOOP_RUDDER",
HARUKIDELTA 13:77b13d5f4d78 678 "RIGHTLOOPSHORT_RUDDER",
HARUKIDELTA 13:77b13d5f4d78 679 "LEFTLOOP_RUDDER",
HARUKIDELTA 13:77b13d5f4d78 680 "LEFTLOOPSHORT_RUDDER",
HARUKIDELTA 13:77b13d5f4d78 681 "GLIDELOOP_RUDDER",
HARUKIDELTA 39:b8d5be233b70 682 "RIGHTLOOP_ROLL_APPROACH",
HARUKIDELTA 39:b8d5be233b70 683 "LEFTLOOP_ROLL_APPROACH",
HARUKIDELTA 39:b8d5be233b70 684 "RIGHTLOOP_RUDDER_APPROACH",
HARUKIDELTA 39:b8d5be233b70 685 "LEFTLOOP_RUDDER_APPROACH"
HARUKIDELTA 0:17f575135219 686 };
HARUKIDELTA 0:17f575135219 687
HARUKIDELTA 0:17f575135219 688 fp = fopen("/sd/option.txt","r");
HARUKIDELTA 0:17f575135219 689
HARUKIDELTA 0:17f575135219 690 if(fp != NULL){ //開けたら
HARUKIDELTA 0:17f575135219 691 pc.printf("File was openned.\r\n");
HARUKIDELTA 0:17f575135219 692 if(GetParameter(fp,paramNames[0],parameter)) *g_kpELE = atof(parameter);
HARUKIDELTA 0:17f575135219 693 else{ *g_kpELE = KP_ELE;
HARUKIDELTA 0:17f575135219 694 SDerrorcount++;
HARUKIDELTA 0:17f575135219 695 }
HARUKIDELTA 0:17f575135219 696 if(GetParameter(fp,paramNames[1],parameter)) *g_kiELE = atof(parameter);
HARUKIDELTA 0:17f575135219 697 else{ *g_kiELE = KI_ELE;
HARUKIDELTA 0:17f575135219 698 SDerrorcount++;
HARUKIDELTA 0:17f575135219 699 }
HARUKIDELTA 0:17f575135219 700 if(GetParameter(fp,paramNames[2],parameter)) *g_kdELE = atof(parameter);
HARUKIDELTA 0:17f575135219 701 else{ *g_kdELE = KD_ELE;
HARUKIDELTA 0:17f575135219 702 SDerrorcount++;
HARUKIDELTA 0:17f575135219 703 }
HARUKIDELTA 0:17f575135219 704 if(GetParameter(fp,paramNames[3],parameter)) *g_kpRUD = atof(parameter);
HARUKIDELTA 0:17f575135219 705 else{ *g_kpRUD = KP_RUD;
HARUKIDELTA 0:17f575135219 706 SDerrorcount++;
HARUKIDELTA 0:17f575135219 707 }
HARUKIDELTA 0:17f575135219 708 if(GetParameter(fp,paramNames[4],parameter)) *g_kiRUD = atof(parameter);
HARUKIDELTA 0:17f575135219 709 else{ *g_kiRUD = KI_RUD;
HARUKIDELTA 0:17f575135219 710 SDerrorcount++;
HARUKIDELTA 0:17f575135219 711 }
HARUKIDELTA 0:17f575135219 712 if(GetParameter(fp,paramNames[5],parameter)) *g_kdRUD = atof(parameter);
HARUKIDELTA 0:17f575135219 713 else{ *g_kdRUD = KD_RUD;
HARUKIDELTA 0:17f575135219 714 SDerrorcount++;
HARUKIDELTA 0:17f575135219 715 }
HARUKIDELTA 0:17f575135219 716 if(GetParameter(fp,paramNames[6],parameter)) *g_rightloopROLL = atof(parameter);
HARUKIDELTA 0:17f575135219 717 else{ *g_rightloopROLL = RIGHT_ROLL;
HARUKIDELTA 0:17f575135219 718 SDerrorcount++;
HARUKIDELTA 0:17f575135219 719 }
HARUKIDELTA 0:17f575135219 720 if(GetParameter(fp,paramNames[7],parameter)) *g_rightloopPITCH = atof(parameter);
HARUKIDELTA 0:17f575135219 721 else{ *g_rightloopPITCH = RIGHT_PITCH;
HARUKIDELTA 0:17f575135219 722 SDerrorcount++;
HARUKIDELTA 0:17f575135219 723 }
HARUKIDELTA 0:17f575135219 724 if(GetParameter(fp,paramNames[8],parameter)) *g_leftloopROLL = atof(parameter);
HARUKIDELTA 0:17f575135219 725 else{ *g_leftloopROLL = LEFT_ROLL;
HARUKIDELTA 0:17f575135219 726 SDerrorcount++;
HARUKIDELTA 0:17f575135219 727 }
HARUKIDELTA 0:17f575135219 728 if(GetParameter(fp,paramNames[9],parameter)) *g_leftloopPITCH = atof(parameter);
HARUKIDELTA 0:17f575135219 729 else{ *g_leftloopPITCH = LEFT_PITCH;
HARUKIDELTA 0:17f575135219 730 SDerrorcount++;
HARUKIDELTA 0:17f575135219 731 }
HARUKIDELTA 0:17f575135219 732 if(GetParameter(fp,paramNames[10],parameter)) *g_gostraightROLL = atof(parameter);
HARUKIDELTA 0:17f575135219 733 else{ *g_gostraightROLL = STRAIGHT_ROLL;
HARUKIDELTA 0:17f575135219 734 SDerrorcount++;
HARUKIDELTA 0:17f575135219 735 }
HARUKIDELTA 0:17f575135219 736 if(GetParameter(fp,paramNames[11],parameter)) *g_gostraightPITCH = atof(parameter);
HARUKIDELTA 0:17f575135219 737 else{ *g_gostraightPITCH = STRAIGHT_PITCH;
HARUKIDELTA 0:17f575135219 738 SDerrorcount++;
HARUKIDELTA 0:17f575135219 739 }
HARUKIDELTA 0:17f575135219 740 if(GetParameter(fp,paramNames[12],parameter)) *g_takeoffTHR = atof(parameter);
HARUKIDELTA 0:17f575135219 741 else{ *g_takeoffTHR = TAKEOFF_THR;
HARUKIDELTA 0:17f575135219 742 SDerrorcount++;
HARUKIDELTA 0:17f575135219 743 }
HARUKIDELTA 0:17f575135219 744 if(GetParameter(fp,paramNames[13],parameter)) *g_loopTHR = atof(parameter);
HARUKIDELTA 0:17f575135219 745 else{ *g_loopTHR = LOOP_THR;
HARUKIDELTA 0:17f575135219 746 SDerrorcount++;
HARUKIDELTA 0:17f575135219 747 }
HARUKIDELTA 0:17f575135219 748 if(GetParameter(fp,paramNames[14],parameter)) *g_rightloopROLLshort = atof(parameter);
HARUKIDELTA 0:17f575135219 749 else{ *g_rightloopROLLshort = RIGHT_ROLL_SHORT;
HARUKIDELTA 0:17f575135219 750 SDerrorcount++;
HARUKIDELTA 0:17f575135219 751 }
HARUKIDELTA 0:17f575135219 752 if(GetParameter(fp,paramNames[15],parameter)) *g_rightloopPITCHshort = atof(parameter);
HARUKIDELTA 0:17f575135219 753 else{ *g_rightloopPITCHshort = RIGHT_PITCH_SHORT;
HARUKIDELTA 0:17f575135219 754 SDerrorcount++;
HARUKIDELTA 0:17f575135219 755 }
HARUKIDELTA 0:17f575135219 756 if(GetParameter(fp,paramNames[16],parameter)) *g_leftloopROLLshort = atof(parameter);
HARUKIDELTA 0:17f575135219 757 else{ *g_leftloopROLLshort = LEFT_ROLL_SHORT;
HARUKIDELTA 0:17f575135219 758 SDerrorcount++;
HARUKIDELTA 0:17f575135219 759 }
HARUKIDELTA 0:17f575135219 760 if(GetParameter(fp,paramNames[17],parameter)) *g_leftloopPITCHshort = atof(parameter);
HARUKIDELTA 0:17f575135219 761 else{ *g_leftloopPITCHshort = LEFT_PITCH_SHORT;
HARUKIDELTA 0:17f575135219 762 SDerrorcount++;
HARUKIDELTA 0:17f575135219 763 }
HARUKIDELTA 0:17f575135219 764 if(GetParameter(fp,paramNames[18],parameter)) *g_glideloopROLL = atof(parameter);
HARUKIDELTA 0:17f575135219 765 else{ *g_glideloopROLL = GLIDE_ROLL;
HARUKIDELTA 0:17f575135219 766 SDerrorcount++;
HARUKIDELTA 0:17f575135219 767 }
HARUKIDELTA 0:17f575135219 768 if(GetParameter(fp,paramNames[19],parameter)) *g_glideloopPITCH = atof(parameter);
HARUKIDELTA 0:17f575135219 769 else{ *g_glideloopPITCH = GLIDE_PITCH;
HARUKIDELTA 0:17f575135219 770 SDerrorcount++;
HARUKIDELTA 0:17f575135219 771 }
HARUKIDELTA 18:cce82f3374fc 772 if(GetParameter(fp,paramNames[20],parameter)) *g_kpAIL = atof(parameter);
HARUKIDELTA 12:763bf416ba4b 773 else{ *g_kpAIL = KP_AIL;
HARUKIDELTA 12:763bf416ba4b 774 SDerrorcount++;
HARUKIDELTA 12:763bf416ba4b 775 }
HARUKIDELTA 12:763bf416ba4b 776 if(GetParameter(fp,paramNames[21],parameter)) *g_kiAIL = atof(parameter);
HARUKIDELTA 12:763bf416ba4b 777 else{ *g_kiAIL = KI_AIL;
HARUKIDELTA 12:763bf416ba4b 778 SDerrorcount++;
HARUKIDELTA 12:763bf416ba4b 779 }
HARUKIDELTA 12:763bf416ba4b 780 if(GetParameter(fp,paramNames[22],parameter)) *g_kdAIL = atof(parameter);
HARUKIDELTA 12:763bf416ba4b 781 else{ *g_kdAIL = KP_AIL;
HARUKIDELTA 12:763bf416ba4b 782 SDerrorcount++;
HARUKIDELTA 12:763bf416ba4b 783 }
HARUKIDELTA 13:77b13d5f4d78 784 if(GetParameter(fp,paramNames[23],parameter)) *g_rightloopRUD = atof(parameter);
HARUKIDELTA 13:77b13d5f4d78 785 else{ *g_rightloopRUD = RIGHTLOOP_RUD;
HARUKIDELTA 13:77b13d5f4d78 786 SDerrorcount++;
HARUKIDELTA 13:77b13d5f4d78 787 }
HARUKIDELTA 13:77b13d5f4d78 788 if(GetParameter(fp,paramNames[24],parameter)) *g_rightloopshortRUD = atof(parameter);
HARUKIDELTA 13:77b13d5f4d78 789 else{ *g_rightloopshortRUD = RIGHTLOOPSHORT_RUD;
HARUKIDELTA 13:77b13d5f4d78 790 SDerrorcount++;
HARUKIDELTA 13:77b13d5f4d78 791 }
HARUKIDELTA 13:77b13d5f4d78 792 if(GetParameter(fp,paramNames[25],parameter)) *g_leftloopRUD = atof(parameter);
HARUKIDELTA 13:77b13d5f4d78 793 else{ *g_leftloopshortRUD = LEFTLOOP_RUD;
HARUKIDELTA 13:77b13d5f4d78 794 SDerrorcount++;
HARUKIDELTA 13:77b13d5f4d78 795 }
HARUKIDELTA 13:77b13d5f4d78 796 if(GetParameter(fp,paramNames[26],parameter)) *g_leftloopshortRUD = atof(parameter);
HARUKIDELTA 13:77b13d5f4d78 797 else{ *g_leftloopshortRUD = LEFTLOOPSHORT_RUD;
HARUKIDELTA 13:77b13d5f4d78 798 SDerrorcount++;
HARUKIDELTA 13:77b13d5f4d78 799 }
HARUKIDELTA 13:77b13d5f4d78 800 if(GetParameter(fp,paramNames[27],parameter)) *g_glideloopRUD = atof(parameter);
HARUKIDELTA 13:77b13d5f4d78 801 else{ *g_glideloopRUD = GLIDELOOP_RUD;
HARUKIDELTA 13:77b13d5f4d78 802 SDerrorcount++;
HARUKIDELTA 13:77b13d5f4d78 803 }
HARUKIDELTA 39:b8d5be233b70 804 if(GetParameter(fp,paramNames[28],parameter)) *g_rightloopROLL_approach = atof(parameter);
HARUKIDELTA 39:b8d5be233b70 805 else{ *g_rightloopROLL_approach = RIGHTLOOPROLL_APPROACH;
HARUKIDELTA 13:77b13d5f4d78 806 SDerrorcount++;
HARUKIDELTA 13:77b13d5f4d78 807 }
HARUKIDELTA 39:b8d5be233b70 808 if(GetParameter(fp,paramNames[29],parameter)) *g_leftloopROLL_approach= atof(parameter);
HARUKIDELTA 39:b8d5be233b70 809 else{ *g_leftloopROLL_approach = LEFTLOOPROLL_APPROACH;
HARUKIDELTA 13:77b13d5f4d78 810 SDerrorcount++;
HARUKIDELTA 13:77b13d5f4d78 811 }
HARUKIDELTA 39:b8d5be233b70 812 if(GetParameter(fp,paramNames[30],parameter)) *g_rightloopRUD_approach = atof(parameter);
HARUKIDELTA 39:b8d5be233b70 813 else{ *g_rightloopRUD_approach = RIGHTLOOPRUD_APPROACH;
HARUKIDELTA 13:77b13d5f4d78 814 SDerrorcount++;
HARUKIDELTA 13:77b13d5f4d78 815 }
HARUKIDELTA 39:b8d5be233b70 816 if(GetParameter(fp,paramNames[31],parameter)) *g_leftloopRUD= atof(parameter);
HARUKIDELTA 39:b8d5be233b70 817 else{ *g_leftloopRUD= LEFTLOOPRUD_APPROACH;
HARUKIDELTA 13:77b13d5f4d78 818 SDerrorcount++;
HARUKIDELTA 13:77b13d5f4d78 819 }
HARUKIDELTA 13:77b13d5f4d78 820
HARUKIDELTA 0:17f575135219 821 fclose(fp);
HARUKIDELTA 0:17f575135219 822
HARUKIDELTA 0:17f575135219 823 }else{ //ファイルがなかったら
HARUKIDELTA 0:17f575135219 824 pc.printf("fp was null.\r\n");
HARUKIDELTA 0:17f575135219 825 *g_kpELE = KP_ELE;
HARUKIDELTA 0:17f575135219 826 *g_kiELE = KI_ELE;
HARUKIDELTA 0:17f575135219 827 *g_kdELE = KD_ELE;
HARUKIDELTA 0:17f575135219 828 *g_kpRUD = KP_RUD;
HARUKIDELTA 0:17f575135219 829 *g_kiRUD = KI_RUD;
HARUKIDELTA 0:17f575135219 830 *g_kdRUD = KD_RUD;
HARUKIDELTA 0:17f575135219 831 *g_rightloopROLL = RIGHT_ROLL;
HARUKIDELTA 0:17f575135219 832 *g_rightloopPITCH = RIGHT_PITCH;
HARUKIDELTA 0:17f575135219 833 *g_leftloopROLL = LEFT_ROLL;
HARUKIDELTA 0:17f575135219 834 *g_leftloopPITCH = LEFT_PITCH;
HARUKIDELTA 0:17f575135219 835 *g_gostraightROLL = STRAIGHT_ROLL;
HARUKIDELTA 0:17f575135219 836 *g_gostraightPITCH = STRAIGHT_PITCH;
HARUKIDELTA 0:17f575135219 837 *g_takeoffTHR = TAKEOFF_THR;
HARUKIDELTA 0:17f575135219 838 *g_loopTHR = LOOP_THR;
HARUKIDELTA 12:763bf416ba4b 839 *g_kpAIL = KP_AIL; //パラメータ変えるのお忘れなく!!
HARUKIDELTA 12:763bf416ba4b 840 *g_kiAIL = KI_AIL;
HARUKIDELTA 12:763bf416ba4b 841 *g_kdAIL = KD_AIL;
HARUKIDELTA 13:77b13d5f4d78 842 *g_rightloopRUD = RIGHTLOOP_RUD;
HARUKIDELTA 13:77b13d5f4d78 843 *g_rightloopshortRUD = RIGHTLOOPSHORT_RUD;
HARUKIDELTA 13:77b13d5f4d78 844 *g_leftloopRUD = LEFTLOOP_RUD;
HARUKIDELTA 13:77b13d5f4d78 845 *g_leftloopshortRUD = LEFTLOOPSHORT_RUD;
HARUKIDELTA 13:77b13d5f4d78 846 *g_glideloopRUD = GLIDELOOP_RUD;
HARUKIDELTA 39:b8d5be233b70 847 *g_rightloopROLL_approach = RIGHTLOOPROLL_APPROACH;
HARUKIDELTA 39:b8d5be233b70 848 *g_leftloopROLL_approach = LEFTLOOPROLL_APPROACH;
HARUKIDELTA 39:b8d5be233b70 849 *g_rightloopRUD_approach = RIGHTLOOPRUD_APPROACH;
HARUKIDELTA 39:b8d5be233b70 850 *g_leftloopRUD_approach = LEFTLOOPRUD_APPROACH;
HARUKIDELTA 13:77b13d5f4d78 851
HARUKIDELTA 13:77b13d5f4d78 852
HARUKIDELTA 0:17f575135219 853 SDerrorcount = -1;
HARUKIDELTA 0:17f575135219 854 }
HARUKIDELTA 0:17f575135219 855 pc.printf("SDsetup finished.\r\n");
HARUKIDELTA 0:17f575135219 856 if(SDerrorcount == 0) pc.printf("setting option is success\r\n");
HARUKIDELTA 0:17f575135219 857 else if(SDerrorcount == -1) pc.printf("ERROR 1. cannot open option\r\n");
HARUKIDELTA 0:17f575135219 858 else if(SDerrorcount > 0) pc.printf("ERROR 2. reading parameter is failed[%d]\r\n",SDerrorcount);
HARUKIDELTA 0:17f575135219 859
HARUKIDELTA 0:17f575135219 860 pc.printf("kpELE = %f, kiELE = %f, kdELE = %f\r\n", *g_kpRUD, *g_kiRUD, *g_kdRUD);
HARUKIDELTA 0:17f575135219 861 pc.printf("kpRUD = %f, kiRUD = %f, kdRUD = %f\r\n", *g_kpELE, *g_kiELE, *g_kdELE);
HARUKIDELTA 0:17f575135219 862 pc.printf("rightloopROLL = %f, rightloopPITCH = %f\r\n", *g_rightloopROLL, *g_rightloopPITCH);
HARUKIDELTA 0:17f575135219 863 pc.printf("leftloopROLL = %f, g_leftloopPITCH = %f\r\n", *g_leftloopROLL, *g_leftloopPITCH);
HARUKIDELTA 0:17f575135219 864 pc.printf("gostraightROLL = %f, g_gostraightPITCH = %f\r\n", *g_gostraightROLL, *g_gostraightPITCH);
HARUKIDELTA 0:17f575135219 865 pc.printf("g_takeoffTHR = %f, g_loopTHR = %f\r\n", *g_takeoffTHR, *g_loopTHR);
HARUKIDELTA 0:17f575135219 866 pc.printf("rightloopROLLshort = %f, rightloopPITCHshort = %f\r\n", *g_rightloopROLLshort, *g_rightloopPITCHshort);
HARUKIDELTA 0:17f575135219 867 pc.printf("leftloopROLLshort = %f, g_leftloopPITCHshort = %f\r\n", *g_leftloopROLLshort, *g_leftloopPITCHshort);
HARUKIDELTA 0:17f575135219 868 pc.printf("glideROLL = %f, glidePITCH = %f\r\n", *g_glideloopROLL, *g_glideloopPITCH);
HARUKIDELTA 16:7fca5b938da6 869 pc.printf("kpAIL = %f,kiAIL = %f,kdAIL = %f\r\n ",*g_kpAIL,*g_kiAIL,*g_kdAIL);
HARUKIDELTA 16:7fca5b938da6 870 pc.printf("RIGHTLOOPRUD = %d,RIGHTLOOPSHORTRUD = %d\r\n",*g_rightloopRUD,*g_rightloopshortRUD);
HARUKIDELTA 16:7fca5b938da6 871 pc.printf("LEFTTLOOPRUD = %d,LEFTLOOPSHORTRUD = %d\r\n",*g_leftloopRUD,*g_leftloopshortRUD);
HARUKIDELTA 16:7fca5b938da6 872 pc.printf("GLIDELOOPRUD = %d\r\n",*g_glideloopRUD);
HARUKIDELTA 39:b8d5be233b70 873 pc.printf("RIGHTLOOP_ROLL_APPROACH = %f, LEFTLOOP_ROLL_APPROACH= %f\r\n",*g_rightloopROLL_approach,*g_leftloopROLL_approach);
HARUKIDELTA 39:b8d5be233b70 874 pc.printf("RIGHTLOOP_RUD_APPROACH = %d, LEFTLOOP_RUD_APPROACH = %d\r\n",*g_rightloopRUD_approach,*g_leftloopRUD_approach);
HARUKIDELTA 0:17f575135219 875 return SDerrorcount;
HARUKIDELTA 0:17f575135219 876 }
HARUKIDELTA 0:17f575135219 877
HARUKIDELTA 0:17f575135219 878 void CalculateControlValue(float targetAngle[3], float controlValue[3]){
taknokolat 28:aa44903a01e1 879
HARUKIDELTA 0:17f575135219 880 static int t_last;
HARUKIDELTA 0:17f575135219 881 int t_now;
HARUKIDELTA 0:17f575135219 882 float dt;
HARUKIDELTA 0:17f575135219 883
HARUKIDELTA 0:17f575135219 884 t_now = t.read_us();
HARUKIDELTA 0:17f575135219 885 dt = (float)((t_now - t_last)/1000000.0f) ;
HARUKIDELTA 0:17f575135219 886 t_last = t_now;
HARUKIDELTA 0:17f575135219 887
taknokolat 1:f383708a5a52 888
taknokolat 1:f383708a5a52 889 //controlValue[ROLL] = pid_RUD.calcPID(nowAngle[ROLL], targetAngle[ROLL], dt);
taknokolat 1:f383708a5a52 890 controlValue[ROLL] = pid_AIL.calcPID(nowAngle[ROLL], targetAngle[ROLL], dt); //エルロンでロール制御
HARUKIDELTA 0:17f575135219 891 controlValue[PITCH] = pid_ELE.calcPID(nowAngle[PITCH], targetAngle[PITCH], dt);
taknokolat 28:aa44903a01e1 892
HARUKIDELTA 0:17f575135219 893 }
HARUKIDELTA 0:17f575135219 894
taknokolat 28:aa44903a01e1 895 void UpdateAutoPWM(float controlValue[3]){
taknokolat 28:aa44903a01e1 896 NVIC_DisableIRQ(USART1_IRQn);
HARUKIDELTA 0:17f575135219 897 int16_t addpwm[2]; //-500~500
HARUKIDELTA 0:17f575135219 898 addpwm[PITCH] = (float)GAIN_CONTROLVALUE_TO_PWM * controlValue[PITCH]; //センサ:機首下げ正 レバー:機首上げ正
HARUKIDELTA 0:17f575135219 899 addpwm[ROLL] = (float)GAIN_CONTROLVALUE_TO_PWM * controlValue[ROLL]; //センサ:右回転正(8月13日時点;左回転が正!) レバー:右回転正
HARUKIDELTA 0:17f575135219 900
HARUKIDELTA 2:23daa5fa28b4 901 autopwm[ELE] = trimpwm[ELE] + reverce[ELE] * addpwm[PITCH]; //rewrite
HARUKIDELTA 8:66bba39b95a9 902 autopwm[AIL_R] = trimpwm[AIL_R] - reverce[AIL_R] * addpwm[ROLL];
HARUKIDELTA 0:17f575135219 903 //autopwm[THR] = oldTHR;
HARUKIDELTA 0:17f575135219 904
HARUKIDELTA 0:17f575135219 905 autopwm[ELE] = ThresholdMaxMin(autopwm[ELE], maxpwm[ELE], minpwm[ELE]);
taknokolat 1:f383708a5a52 906 autopwm[AIL_R] = ThresholdMaxMin(autopwm[AIL_R], maxpwm[AIL_R], minpwm[AIL_R]);
HARUKIDELTA 2:23daa5fa28b4 907
taknokolat 28:aa44903a01e1 908 NVIC_EnableIRQ(USART1_IRQn);
HARUKIDELTA 0:17f575135219 909 }
HARUKIDELTA 0:17f575135219 910
HARUKIDELTA 0:17f575135219 911 inline float CalcRatio(float value, float trim, float limit){
HARUKIDELTA 0:17f575135219 912 return (value - trim) / (limit - trim);
HARUKIDELTA 0:17f575135219 913 }
HARUKIDELTA 0:17f575135219 914
HARUKIDELTA 0:17f575135219 915 bool CheckSW_Up(Channel ch){
taknokolat 28:aa44903a01e1 916
HARUKIDELTA 0:17f575135219 917 if(SWITCH_CHECK < sbus.manualpwm[ch]){
HARUKIDELTA 0:17f575135219 918 return true;
HARUKIDELTA 0:17f575135219 919 }else{
HARUKIDELTA 0:17f575135219 920 return false;
HARUKIDELTA 0:17f575135219 921 }
taknokolat 28:aa44903a01e1 922
HARUKIDELTA 0:17f575135219 923 }
HARUKIDELTA 0:17f575135219 924
HARUKIDELTA 0:17f575135219 925 int16_t ThresholdMaxMin(int16_t value, int16_t max, int16_t min){
HARUKIDELTA 0:17f575135219 926 if(value > max) return max;
HARUKIDELTA 0:17f575135219 927 if(value < min) return min;
HARUKIDELTA 0:17f575135219 928 return value;
HARUKIDELTA 0:17f575135219 929 }
HARUKIDELTA 0:17f575135219 930
HARUKIDELTA 0:17f575135219 931 inline int16_t SetTHRinRatio(float ratio){
HARUKIDELTA 0:17f575135219 932 return minpwm[THR] + (int16_t)(2 * lengthdivpwm * ratio);
HARUKIDELTA 0:17f575135219 933 }
HARUKIDELTA 0:17f575135219 934
HARUKIDELTA 2:23daa5fa28b4 935
HARUKIDELTA 2:23daa5fa28b4 936
HARUKIDELTA 0:17f575135219 937 /*---SBUS割り込み処理---*/
HARUKIDELTA 0:17f575135219 938
HARUKIDELTA 0:17f575135219 939 //udate_Inputで抽出したpwmデータを整形して各変数に代入する。(マニュアルモード)
HARUKIDELTA 0:17f575135219 940 //各stabiGylo関数で算出したpwmを各変数に代入する(自動モード)
HARUKIDELTA 0:17f575135219 941 void Update_PWM()
taknokolat 28:aa44903a01e1 942 {
taknokolat 28:aa44903a01e1 943 NVIC_DisableIRQ(USART1_IRQn);
HARUKIDELTA 0:17f575135219 944 static int16_t pwm[6];
HARUKIDELTA 0:17f575135219 945 static int16_t temppwm[6]={trimpwm[0],trimpwm[1],trimpwm[2],trimpwm[3],trimpwm[4],trimpwm[5]};
taknokolat 33:0f7a35d55316 946 static int16_t FailsafeCounter=0;
taknokolat 33:0f7a35d55316 947 static int16_t OKCounter=0;
taknokolat 33:0f7a35d55316 948
taknokolat 33:0f7a35d55316 949 if(sbus.flg_ch_update == true && sbus.failsafe_status==SBUS_SIGNAL_OK){
taknokolat 33:0f7a35d55316 950
HARUKIDELTA 0:17f575135219 951 switch(output_status){ //マニュアルモード,自動モード,自動着陸もモードを切替
taknokolat 33:0f7a35d55316 952 case Manual:
taknokolat 33:0f7a35d55316 953 if(OKCounter!=0) break;
HARUKIDELTA 0:17f575135219 954 for(uint8_t i=0;i<6;i++){
taknokolat 1:f383708a5a52 955 pwm[i] = sbus.manualpwm[i];
HARUKIDELTA 0:17f575135219 956 }
HARUKIDELTA 0:17f575135219 957 oldTHR = sbus.manualpwm[THR];
HARUKIDELTA 0:17f575135219 958 //pc.printf("update_manual\r\n");
taknokolat 28:aa44903a01e1 959 NVIC_EnableIRQ(USART1_IRQn);
HARUKIDELTA 0:17f575135219 960 break;
HARUKIDELTA 0:17f575135219 961
HARUKIDELTA 0:17f575135219 962 case Auto:
taknokolat 33:0f7a35d55316 963 if(OKCounter!=0) break;
HARUKIDELTA 0:17f575135219 964 pwm[AIL_R] = autopwm[AIL_R]; //sbus.manualpwm[AIL];
HARUKIDELTA 0:17f575135219 965 pwm[ELE] = autopwm[ELE];
HARUKIDELTA 0:17f575135219 966 pwm[THR] = autopwm[THR];
HARUKIDELTA 0:17f575135219 967 pwm[RUD] = autopwm[RUD];
HARUKIDELTA 0:17f575135219 968 pwm[DROP] = autopwm[DROP];
HARUKIDELTA 0:17f575135219 969 pwm[AIL_L] = autopwm[AIL_L];
taknokolat 33:0f7a35d55316 970
taknokolat 28:aa44903a01e1 971 NVIC_EnableIRQ(USART1_IRQn);
HARUKIDELTA 0:17f575135219 972 break;
HARUKIDELTA 0:17f575135219 973
HARUKIDELTA 0:17f575135219 974 default:
taknokolat 33:0f7a35d55316 975 if(OKCounter!=0) break;
HARUKIDELTA 0:17f575135219 976 for(uint8_t i=0;i<6;i++){
HARUKIDELTA 0:17f575135219 977 pwm[i] = sbus.manualpwm[i];
HARUKIDELTA 0:17f575135219 978 } //pc.printf("update_manual\r\n");
taknokolat 28:aa44903a01e1 979 NVIC_EnableIRQ(USART1_IRQn);
HARUKIDELTA 0:17f575135219 980 break;
HARUKIDELTA 0:17f575135219 981 }
taknokolat 28:aa44903a01e1 982
HARUKIDELTA 0:17f575135219 983 for(uint8_t i=0;i<6;i++){
taknokolat 33:0f7a35d55316 984 if(pwm[i]<1000 || pwm[i]>2000) pwm[i]=temppwm[i];
taknokolat 33:0f7a35d55316 985 temppwm[i]=pwm[i];
taknokolat 33:0f7a35d55316 986 }
taknokolat 33:0f7a35d55316 987
taknokolat 33:0f7a35d55316 988 }
taknokolat 33:0f7a35d55316 989 //else(sbus.flg_ch_update == false) pc.printf("0\r\n");
taknokolat 33:0f7a35d55316 990 /* if(sbus.failsafe_status==SBUS_SIGNAL_OK){
taknokolat 33:0f7a35d55316 991 pc.printf("OK\r\n");
HARUKIDELTA 0:17f575135219 992 }
taknokolat 33:0f7a35d55316 993 */
taknokolat 33:0f7a35d55316 994 //pc.printf("%d\r\n",sbus.failsafe_status);
taknokolat 33:0f7a35d55316 995
taknokolat 33:0f7a35d55316 996 if(sbus.failsafe_status==SBUS_SIGNAL_LOST||sbus.failsafe_status==SBUS_SIGNAL_FAILSAFE) FailsafeCounter++;
taknokolat 33:0f7a35d55316 997 else FailsafeCounter=0;
taknokolat 33:0f7a35d55316 998
taknokolat 33:0f7a35d55316 999 if(FailsafeCounter>10){
taknokolat 33:0f7a35d55316 1000 for(uint8_t i=0;i<6;i++) pwm[i] = trimpwm[i];
taknokolat 33:0f7a35d55316 1001
taknokolat 33:0f7a35d55316 1002 if(sbus.failsafe_status==SBUS_SIGNAL_OK) OKCounter++;
taknokolat 33:0f7a35d55316 1003 if(OKCounter>10) {
taknokolat 33:0f7a35d55316 1004 OKCounter=0;
taknokolat 33:0f7a35d55316 1005 }
taknokolat 33:0f7a35d55316 1006
taknokolat 33:0f7a35d55316 1007 //pc.printf("%d\r\n",sbus.failsafe_status);
taknokolat 33:0f7a35d55316 1008 //if(sbus.failsafe_status!=SBUS_SIGNAL_FAILSAFE)break;
taknokolat 33:0f7a35d55316 1009
taknokolat 33:0f7a35d55316 1010 }
taknokolat 33:0f7a35d55316 1011 //if(sbus.failsafe_status==SBUS_SIGNAL_OK){FailsafeCounter=0;}
taknokolat 33:0f7a35d55316 1012
taknokolat 33:0f7a35d55316 1013
HARUKIDELTA 0:17f575135219 1014 sbus.flg_ch_update = false;
HARUKIDELTA 0:17f575135219 1015 Output_PWM(pwm);
HARUKIDELTA 0:17f575135219 1016 }
taknokolat 33:0f7a35d55316 1017
taknokolat 33:0f7a35d55316 1018
HARUKIDELTA 0:17f575135219 1019 //pwmをサーボに出力。
HARUKIDELTA 0:17f575135219 1020 void Output_PWM(int16_t pwm[5])
HARUKIDELTA 0:17f575135219 1021 {
taknokolat 10:652071c20bf6 1022 NVIC_DisableIRQ(USART1_IRQn);
HARUKIDELTA 0:17f575135219 1023 servo1.pulsewidth_us(pwm[0]);
HARUKIDELTA 0:17f575135219 1024 servo2.pulsewidth_us(pwm[1]);
HARUKIDELTA 0:17f575135219 1025 servo3.pulsewidth_us(pwm[2]);
HARUKIDELTA 0:17f575135219 1026 servo4.pulsewidth_us(pwm[3]);
HARUKIDELTA 0:17f575135219 1027 servo5.pulsewidth_us(pwm[4]);
HARUKIDELTA 0:17f575135219 1028 servo6.pulsewidth_us(pwm[5]);
taknokolat 10:652071c20bf6 1029 NVIC_EnableIRQ(USART1_IRQn);
HARUKIDELTA 0:17f575135219 1030
HARUKIDELTA 0:17f575135219 1031 }
HARUKIDELTA 0:17f575135219 1032
HARUKIDELTA 0:17f575135219 1033 void ResetTrim(){
HARUKIDELTA 0:17f575135219 1034 for(uint8_t i=0; i<6; i++){ //i=4から書き換え_投下サーボは入ってない模様
HARUKIDELTA 0:17f575135219 1035 trimpwm[i] = sbus.manualpwm[i];
HARUKIDELTA 0:17f575135219 1036 }
HARUKIDELTA 0:17f575135219 1037 pc.printf("reset PWM trim\r\n");
HARUKIDELTA 0:17f575135219 1038 }
HARUKIDELTA 0:17f575135219 1039
HARUKIDELTA 0:17f575135219 1040
HARUKIDELTA 0:17f575135219 1041 void SensingMPU(){
HARUKIDELTA 0:17f575135219 1042 //static int16_t deltaT = 0, t_start = 0;
HARUKIDELTA 0:17f575135219 1043 //t_start = t.read_us();
HARUKIDELTA 0:17f575135219 1044
HARUKIDELTA 0:17f575135219 1045 float rpy[3] = {0}, oldrpy[3] = {0};
HARUKIDELTA 0:17f575135219 1046 static uint16_t count_changeRPY = 0;
HARUKIDELTA 0:17f575135219 1047 static bool flg_checkoutlier = false;
HARUKIDELTA 0:17f575135219 1048 NVIC_DisableIRQ(USART1_IRQn);
HARUKIDELTA 0:17f575135219 1049 NVIC_DisableIRQ(USART2_IRQn);
HARUKIDELTA 0:17f575135219 1050 NVIC_DisableIRQ(TIM5_IRQn);
taknokolat 10:652071c20bf6 1051 NVIC_DisableIRQ(EXTI0_IRQn);//MPU割り込み禁止
taknokolat 10:652071c20bf6 1052 NVIC_DisableIRQ(EXTI9_5_IRQn);//超音波割り込み禁止
HARUKIDELTA 0:17f575135219 1053
HARUKIDELTA 0:17f575135219 1054 mpu6050.getRollPitchYaw_Skipper(rpy);
HARUKIDELTA 0:17f575135219 1055
HARUKIDELTA 0:17f575135219 1056 NVIC_EnableIRQ(USART1_IRQn);
HARUKIDELTA 0:17f575135219 1057 NVIC_EnableIRQ(USART2_IRQn);
HARUKIDELTA 0:17f575135219 1058 NVIC_EnableIRQ(TIM5_IRQn);
HARUKIDELTA 0:17f575135219 1059 NVIC_EnableIRQ(EXTI0_IRQn);
HARUKIDELTA 0:17f575135219 1060 NVIC_EnableIRQ(EXTI9_5_IRQn);
HARUKIDELTA 0:17f575135219 1061
HARUKIDELTA 0:17f575135219 1062
HARUKIDELTA 0:17f575135219 1063 //外れ値対策
HARUKIDELTA 0:17f575135219 1064 for(uint8_t i=0; i<3; i++) rpy[i] *= 180.0f/PI;
HARUKIDELTA 0:17f575135219 1065 rpy[ROLL] -= FirstROLL;
HARUKIDELTA 0:17f575135219 1066 rpy[PITCH] -= FirstPITCH;
HARUKIDELTA 0:17f575135219 1067 rpy[YAW] -= FirstYAW;
HARUKIDELTA 0:17f575135219 1068
HARUKIDELTA 0:17f575135219 1069 for(uint8_t i=0; i<3; i++) {if(rpy[i] < nowAngle[i]-10 || rpy[i] > nowAngle[i]+10) {flg_checkoutlier = true;}}
HARUKIDELTA 0:17f575135219 1070 if(!flg_checkoutlier || count_changeRPY >= 2){
HARUKIDELTA 0:17f575135219 1071 for(uint8_t i=0; i<3; i++){
HARUKIDELTA 0:17f575135219 1072 nowAngle[i] = (rpy[i] + nowAngle[i])/2.0f; //2つの移動平均
HARUKIDELTA 0:17f575135219 1073 }
HARUKIDELTA 0:17f575135219 1074 count_changeRPY = 0;
HARUKIDELTA 0:17f575135219 1075 }else count_changeRPY++;
HARUKIDELTA 0:17f575135219 1076 flg_checkoutlier = false;
HARUKIDELTA 0:17f575135219 1077
HARUKIDELTA 0:17f575135219 1078 }
HARUKIDELTA 0:17f575135219 1079
HARUKIDELTA 0:17f575135219 1080 float TranslateNewYaw(float beforeYaw, float newzeroYaw){
HARUKIDELTA 0:17f575135219 1081 float newYaw = beforeYaw - newzeroYaw;
HARUKIDELTA 0:17f575135219 1082
HARUKIDELTA 0:17f575135219 1083 if(newYaw<-180.0f) newYaw += 360.0f;
HARUKIDELTA 0:17f575135219 1084 else if(newYaw>180.0f) newYaw -= 360.0f;
HARUKIDELTA 0:17f575135219 1085 return newYaw;
HARUKIDELTA 0:17f575135219 1086 }
HARUKIDELTA 0:17f575135219 1087
HARUKIDELTA 0:17f575135219 1088
HARUKIDELTA 0:17f575135219 1089 void getSF_Serial(){
taknokolat 25:37bee299a276 1090 //NVIC_DisableIRQ(USART1_IRQn);
taknokolat 28:aa44903a01e1 1091 //NVIC_DisableIRQ(EXTI0_IRQn);
taknokolat 25:37bee299a276 1092 //NVIC_DisableIRQ(TIM5_IRQn);
taknokolat 25:37bee299a276 1093
taknokolat 25:37bee299a276 1094
taknokolat 25:37bee299a276 1095 static char SFbuf[16]={'Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q'};
taknokolat 25:37bee299a276 1096
HARUKIDELTA 0:17f575135219 1097 static int bufcounter=0;
HARUKIDELTA 0:17f575135219 1098
taknokolat 28:aa44903a01e1 1099
taknokolat 28:aa44903a01e1 1100
taknokolat 14:bbd5ff31fb67 1101 if(pc.readable()) { // 受信確認
taknokolat 25:37bee299a276 1102
taknokolat 14:bbd5ff31fb67 1103 SFbuf[bufcounter] = pc.getc(); // 1文字取り出し
taknokolat 28:aa44903a01e1 1104 if(SFbuf[0]!='S'){
taknokolat 28:aa44903a01e1 1105 //pc.printf("x");
taknokolat 28:aa44903a01e1 1106 return;
taknokolat 28:aa44903a01e1 1107 }
taknokolat 29:887a38540508 1108
taknokolat 25:37bee299a276 1109
taknokolat 11:c0b9ad25d3db 1110
taknokolat 25:37bee299a276 1111 //pc.printf("%c",SFbuf[bufcounter]);
HARUKIDELTA 0:17f575135219 1112
taknokolat 25:37bee299a276 1113 if(SFbuf[0]=='S'&&bufcounter<5)bufcounter++;
taknokolat 25:37bee299a276 1114
taknokolat 25:37bee299a276 1115 if(bufcounter==5 && SFbuf[4]=='F'){
taknokolat 25:37bee299a276 1116
taknokolat 25:37bee299a276 1117 g_landingcommand = SFbuf[1];
taknokolat 25:37bee299a276 1118 //wait_ms(20);
taknokolat 36:197b514eae3b 1119 //if(g_landingcommand=='Y')g_SerialTargetYAW = ConvertByteintoFloat(SFbuf[2], SFbuf[3]);
taknokolat 36:197b514eae3b 1120 if(g_landingcommand=='Y')g_SerialTargetYAW =0.0f;
taknokolat 25:37bee299a276 1121 bufcounter = 0;
taknokolat 25:37bee299a276 1122 memset(SFbuf, 0, strlen(SFbuf));
taknokolat 28:aa44903a01e1 1123 NVIC_ClearPendingIRQ(USART2_IRQn);
taknokolat 25:37bee299a276 1124 //pc.printf("command = %c, commandYAW = %f\r\n", g_landingcommand, g_SerialTargetYAW);
taknokolat 25:37bee299a276 1125 }
taknokolat 25:37bee299a276 1126
taknokolat 28:aa44903a01e1 1127 else if(bufcounter>=5){
taknokolat 25:37bee299a276 1128 //pc.printf("Communication Falsed.\r\n");
taknokolat 25:37bee299a276 1129 memset(SFbuf, 0, strlen(SFbuf));
HARUKIDELTA 0:17f575135219 1130 bufcounter = 0;
taknokolat 28:aa44903a01e1 1131 NVIC_ClearPendingIRQ(USART2_IRQn);
HARUKIDELTA 0:17f575135219 1132 }
taknokolat 29:887a38540508 1133 }
taknokolat 25:37bee299a276 1134
taknokolat 25:37bee299a276 1135 //NVIC_EnableIRQ(TIM5_IRQn);
taknokolat 28:aa44903a01e1 1136 //NVIC_EnableIRQ(EXTI0_IRQn);
taknokolat 25:37bee299a276 1137 //NVIC_EnableIRQ(USART1_IRQn);
HARUKIDELTA 0:17f575135219 1138 }
HARUKIDELTA 0:17f575135219 1139
HARUKIDELTA 0:17f575135219 1140 float ConvertByteintoFloat(char high, char low){
HARUKIDELTA 0:17f575135219 1141
HARUKIDELTA 0:17f575135219 1142 //int16_t intvalue = (int16_t)high*256 + (int16_t)low;
HARUKIDELTA 0:17f575135219 1143 int16_t intvalue = (int16_t)(((int16_t)high << 8) | low); // Turn the MSB and LSB into a signed 16-bit value
HARUKIDELTA 0:17f575135219 1144 float floatvalue = (float)intvalue;
HARUKIDELTA 0:17f575135219 1145 return floatvalue;
HARUKIDELTA 0:17f575135219 1146 }
HARUKIDELTA 0:17f575135219 1147
HARUKIDELTA 0:17f575135219 1148
HARUKIDELTA 0:17f575135219 1149 //超音波割り込み
HARUKIDELTA 31:dba3216c2755 1150 void UpdateDist(){
HARUKIDELTA 0:17f575135219 1151 g_distance = usensor.get_dist_cm();
HARUKIDELTA 0:17f575135219 1152 usensor.start();
HARUKIDELTA 31:dba3216c2755 1153 }
HARUKIDELTA 0:17f575135219 1154
HARUKIDELTA 0:17f575135219 1155 //8の字旋回
HARUKIDELTA 0:17f575135219 1156 void UpdateTargetAngle_Moebius(float targetAngle[3]){
HARUKIDELTA 0:17f575135219 1157 static uint8_t RotateCounter=0;
HARUKIDELTA 0:17f575135219 1158 static bool flg_setInStartAuto = false;
HARUKIDELTA 0:17f575135219 1159 static float FirstYAW_Moebius = 0.0;
HARUKIDELTA 0:17f575135219 1160 float newYaw_Moebius;
HARUKIDELTA 0:17f575135219 1161
HARUKIDELTA 0:17f575135219 1162 if(!flg_setInStartAuto && CheckSW_Up(Ch7)){
HARUKIDELTA 0:17f575135219 1163 FirstYAW_Moebius = nowAngle[YAW];
HARUKIDELTA 0:17f575135219 1164 RotateCounter = 0;
HARUKIDELTA 0:17f575135219 1165 flg_setInStartAuto = true;
HARUKIDELTA 0:17f575135219 1166 }else if(!CheckSW_Up(Ch7)){
HARUKIDELTA 0:17f575135219 1167 flg_setInStartAuto = false;
HARUKIDELTA 38:ef0f39dfc98a 1168 led4 = 0;
HARUKIDELTA 0:17f575135219 1169 }
HARUKIDELTA 6:ed61ed8b8fab 1170 autopwm[THR]=oldTHR;
HARUKIDELTA 6:ed61ed8b8fab 1171
HARUKIDELTA 0:17f575135219 1172 newYaw_Moebius = TranslateNewYaw(nowAngle[YAW], FirstYAW_Moebius);
HARUKIDELTA 0:17f575135219 1173
HARUKIDELTA 38:ef0f39dfc98a 1174 if(RotateCounter == 0 && newYaw_Moebius >90.0 && newYaw_Moebius < 180.0) {RotateCounter++; led4 = 1; pc.printf("Rotate 90\r\n");}
HARUKIDELTA 38:ef0f39dfc98a 1175 if(RotateCounter == 1 && newYaw_Moebius >-180.0 && newYaw_Moebius < -90.0) {RotateCounter++; led4 = 0; pc.printf("Rotate 180\r\n");}
HARUKIDELTA 38:ef0f39dfc98a 1176 if(RotateCounter == 2 && newYaw_Moebius >-90.0 && newYaw_Moebius <-10.0) {RotateCounter++; led4 = 1; pc.printf("Rotate 270\r\n");}
HARUKIDELTA 38:ef0f39dfc98a 1177 if(RotateCounter == 3 && newYaw_Moebius >0.0 && newYaw_Moebius < 90.0) {RotateCounter++; led4 = 0; pc.printf("Change Rotate direction\r\n");}
HARUKIDELTA 0:17f575135219 1178
HARUKIDELTA 0:17f575135219 1179
HARUKIDELTA 0:17f575135219 1180 if(RotateCounter <= 3) UpdateTargetAngle_Rightloop_short(targetAngle);
HARUKIDELTA 0:17f575135219 1181 else UpdateTargetAngle_Leftloop_short(targetAngle); //左旋回
HARUKIDELTA 0:17f575135219 1182
HARUKIDELTA 0:17f575135219 1183 }
HARUKIDELTA 0:17f575135219 1184
HARUKIDELTA 0:17f575135219 1185 //自動滑空
HARUKIDELTA 0:17f575135219 1186 void UpdateTargetAngle_Glide(float targetAngle[3]){
HARUKIDELTA 0:17f575135219 1187 static int THRcount = 0;
HARUKIDELTA 0:17f575135219 1188 static int t_start = 0;
HARUKIDELTA 0:17f575135219 1189 static bool flg_tstart = false;
HARUKIDELTA 31:dba3216c2755 1190 static bool flg_ground = false;
HARUKIDELTA 0:17f575135219 1191 int t_diff = 0;
taknokolat 1:f383708a5a52 1192 static int groundcount = 0;
HARUKIDELTA 0:17f575135219 1193
HARUKIDELTA 0:17f575135219 1194 targetAngle[ROLL] = g_glideloopROLL;
HARUKIDELTA 0:17f575135219 1195 targetAngle[PITCH] = g_glideloopPITCH;
HARUKIDELTA 0:17f575135219 1196
HARUKIDELTA 16:7fca5b938da6 1197 autopwm[RUD]=g_glideloopRUD;
HARUKIDELTA 7:53b0eb6f6bd3 1198 // autopwm[THR]=oldTHR;
taknokolat 10:652071c20bf6 1199
taknokolat 1:f383708a5a52 1200
HARUKIDELTA 7:53b0eb6f6bd3 1201
HARUKIDELTA 0:17f575135219 1202 //時間計測開始設定
HARUKIDELTA 0:17f575135219 1203 if(!flg_tstart && CheckSW_Up(Ch7)){
HARUKIDELTA 0:17f575135219 1204 t_start = t.read();
HARUKIDELTA 0:17f575135219 1205 flg_tstart = true;
HARUKIDELTA 0:17f575135219 1206 pc.printf("timer start\r\n");
taknokolat 1:f383708a5a52 1207 }else if(!CheckSW_Up(Ch7)){
HARUKIDELTA 0:17f575135219 1208 t_start = 0;
HARUKIDELTA 0:17f575135219 1209 flg_tstart = false;
HARUKIDELTA 0:17f575135219 1210 }
HARUKIDELTA 0:17f575135219 1211
taknokolat 1:f383708a5a52 1212
HARUKIDELTA 0:17f575135219 1213 //フラグが偽であれば計測は行わない
HARUKIDELTA 0:17f575135219 1214 if(flg_tstart){
HARUKIDELTA 0:17f575135219 1215 t_diff = t.read() - t_start;
HARUKIDELTA 0:17f575135219 1216 //一定高度or15秒でled点灯
taknokolat 10:652071c20bf6 1217 NVIC_DisableIRQ(EXTI9_5_IRQn);
taknokolat 1:f383708a5a52 1218 if((groundcount>5 && g_distance>0) || t_diff > 15){
HARUKIDELTA 38:ef0f39dfc98a 1219 led4 = 1;
HARUKIDELTA 0:17f575135219 1220 //pc.printf("Call [Stop!] calling!\r\n");
HARUKIDELTA 0:17f575135219 1221 }
taknokolat 10:652071c20bf6 1222
HARUKIDELTA 38:ef0f39dfc98a 1223 if(g_distance<250 && g_distance > 0) {
HARUKIDELTA 31:dba3216c2755 1224 groundcount++;
HARUKIDELTA 31:dba3216c2755 1225 }
taknokolat 10:652071c20bf6 1226 NVIC_EnableIRQ(EXTI9_5_IRQn);
HARUKIDELTA 0:17f575135219 1227 }else{
HARUKIDELTA 0:17f575135219 1228 t_diff = 0;
taknokolat 1:f383708a5a52 1229 groundcount = 0;
HARUKIDELTA 38:ef0f39dfc98a 1230 led4 = 0;
HARUKIDELTA 0:17f575135219 1231 }
HARUKIDELTA 0:17f575135219 1232
taknokolat 10:652071c20bf6 1233 NVIC_DisableIRQ(EXTI9_5_IRQn);
HARUKIDELTA 31:dba3216c2755 1234 if(t_diff > 17) autopwm[THR] = SetTHRinRatio(0.5);
HARUKIDELTA 31:dba3216c2755 1235
HARUKIDELTA 31:dba3216c2755 1236 else if(g_distance<150 && g_distance>0 ){
HARUKIDELTA 31:dba3216c2755 1237 NVIC_DisableIRQ(EXTI9_5_IRQn);
HARUKIDELTA 0:17f575135219 1238 THRcount++;
HARUKIDELTA 31:dba3216c2755 1239 if(THRcount>5) flg_ground = true;
HARUKIDELTA 31:dba3216c2755 1240 }
HARUKIDELTA 31:dba3216c2755 1241 else THRcount = 0;
HARUKIDELTA 31:dba3216c2755 1242 NVIC_EnableIRQ(EXTI9_5_IRQn);
HARUKIDELTA 31:dba3216c2755 1243
HARUKIDELTA 31:dba3216c2755 1244 if(flg_ground == true) autopwm[THR] = SetTHRinRatio(0.6);
HARUKIDELTA 31:dba3216c2755 1245 else autopwm[THR] = minpwm[THR];
HARUKIDELTA 31:dba3216c2755 1246
HARUKIDELTA 31:dba3216c2755 1247 NVIC_DisableIRQ(USART1_IRQn);
HARUKIDELTA 31:dba3216c2755 1248 if(!CheckSW_Up(Ch7)){
HARUKIDELTA 31:dba3216c2755 1249 flg_ground = false;
HARUKIDELTA 0:17f575135219 1250 }
HARUKIDELTA 31:dba3216c2755 1251 NVIC_EnableIRQ(USART1_IRQn);
HARUKIDELTA 0:17f575135219 1252 }
HARUKIDELTA 31:dba3216c2755 1253
HARUKIDELTA 0:17f575135219 1254 //離陸-投下-着陸一連
HARUKIDELTA 0:17f575135219 1255 void Take_off_and_landing(float targetAngle[3]){
taknokolat 33:0f7a35d55316 1256
HARUKIDELTA 0:17f575135219 1257 if(!CheckSW_Up(Ch7)) bombing_mode = Takeoff;
HARUKIDELTA 0:17f575135219 1258
HARUKIDELTA 0:17f575135219 1259 switch(bombing_mode){
HARUKIDELTA 0:17f575135219 1260 case Takeoff:
HARUKIDELTA 0:17f575135219 1261 static bool flg_setFirstYaw = false;
HARUKIDELTA 0:17f575135219 1262 static int TakeoffCount = 0;
HARUKIDELTA 0:17f575135219 1263
HARUKIDELTA 0:17f575135219 1264 if(!flg_setFirstYaw && CheckSW_Up(Ch7)){
HARUKIDELTA 0:17f575135219 1265 FirstYAW = nowAngle[YAW];
HARUKIDELTA 0:17f575135219 1266 flg_setFirstYaw = true;
HARUKIDELTA 0:17f575135219 1267 }else if(flg_setFirstYaw && !CheckSW_Up(Ch7)){
HARUKIDELTA 0:17f575135219 1268 flg_setFirstYaw = false;
HARUKIDELTA 0:17f575135219 1269 }
HARUKIDELTA 0:17f575135219 1270
HARUKIDELTA 0:17f575135219 1271 UpdateTargetAngle_Takeoff(targetAngle);
taknokolat 33:0f7a35d55316 1272 NVIC_DisableIRQ(EXTI9_5_IRQn);
HARUKIDELTA 0:17f575135219 1273 if(g_distance>150) TakeoffCount++;
HARUKIDELTA 0:17f575135219 1274 else TakeoffCount = 0;
taknokolat 33:0f7a35d55316 1275 NVIC_EnableIRQ(EXTI9_5_IRQn);
HARUKIDELTA 0:17f575135219 1276 if(TakeoffCount>5){
HARUKIDELTA 0:17f575135219 1277 autopwm[THR] = 1180+320*2*0.5;
taknokolat 36:197b514eae3b 1278 targetAngle[PITCH]=g_gostraightPITCH;
taknokolat 34:5719e6977ec7 1279 //pc.printf("Now go to Approach mode!!");
HARUKIDELTA 0:17f575135219 1280 bombing_mode = Approach;
HARUKIDELTA 0:17f575135219 1281 }
HARUKIDELTA 0:17f575135219 1282 break;
taknokolat 10:652071c20bf6 1283
taknokolat 10:652071c20bf6 1284 //case Chicken:
taknokolat 10:652071c20bf6 1285 //break;
taknokolat 33:0f7a35d55316 1286 /*
HARUKIDELTA 0:17f575135219 1287 case Transition:
HARUKIDELTA 0:17f575135219 1288 static int ApproachCount = 0;
HARUKIDELTA 0:17f575135219 1289 targetAngle[YAW]=180.0;
HARUKIDELTA 0:17f575135219 1290 int Judge = Rotate(targetAngle, g_SerialTargetYAW);
HARUKIDELTA 0:17f575135219 1291
HARUKIDELTA 0:17f575135219 1292 if(Judge==0) ApproachCount++;
HARUKIDELTA 0:17f575135219 1293 if(ApproachCount>5) bombing_mode = Approach;
HARUKIDELTA 0:17f575135219 1294 break;
taknokolat 33:0f7a35d55316 1295 */
HARUKIDELTA 0:17f575135219 1296 case Approach:
taknokolat 33:0f7a35d55316 1297
taknokolat 10:652071c20bf6 1298 autopwm[THR] = SetTHRinRatio(g_loopTHR); //0.7;スロットルの割合
HARUKIDELTA 0:17f575135219 1299 UpdateTargetAngle_Approach(targetAngle);
taknokolat 33:0f7a35d55316 1300
HARUKIDELTA 0:17f575135219 1301 break;
HARUKIDELTA 0:17f575135219 1302
HARUKIDELTA 0:17f575135219 1303 default:
HARUKIDELTA 0:17f575135219 1304 bombing_mode = Takeoff;
HARUKIDELTA 0:17f575135219 1305 break;
HARUKIDELTA 0:17f575135219 1306 }
taknokolat 33:0f7a35d55316 1307
HARUKIDELTA 0:17f575135219 1308 }
HARUKIDELTA 0:17f575135219 1309
HARUKIDELTA 0:17f575135219 1310 //離陸モード
HARUKIDELTA 0:17f575135219 1311 void UpdateTargetAngle_Takeoff(float targetAngle[3]){
HARUKIDELTA 0:17f575135219 1312 //pc.printf("%d \r\n",g_distance);
taknokolat 34:5719e6977ec7 1313 static int tELE_start = 0;
taknokolat 34:5719e6977ec7 1314 static bool flg_ELEup = false;
taknokolat 34:5719e6977ec7 1315 int t_def = 0;
HARUKIDELTA 35:25e1afadd455 1316
HARUKIDELTA 35:25e1afadd455 1317 autopwm[RUD] = trimpwm[RUD];
HARUKIDELTA 35:25e1afadd455 1318
HARUKIDELTA 35:25e1afadd455 1319
taknokolat 34:5719e6977ec7 1320 if(!flg_ELEup && CheckSW_Up(Ch7)){
taknokolat 34:5719e6977ec7 1321 tELE_start = t.read_ms();
taknokolat 34:5719e6977ec7 1322 flg_ELEup = true;
taknokolat 34:5719e6977ec7 1323 pc.printf("timer start\r\n");
taknokolat 34:5719e6977ec7 1324 }else if(!CheckSW_Up(Ch7)){
taknokolat 34:5719e6977ec7 1325 tELE_start = 0;
taknokolat 34:5719e6977ec7 1326 flg_ELEup = false;
taknokolat 34:5719e6977ec7 1327 }
taknokolat 34:5719e6977ec7 1328 if(flg_ELEup){
taknokolat 34:5719e6977ec7 1329 t_def = t.read_ms() - tELE_start;
taknokolat 34:5719e6977ec7 1330
taknokolat 34:5719e6977ec7 1331 //1.5秒経過すればELE上げ舵へ
taknokolat 36:197b514eae3b 1332 if(t_def>500) targetAngle[PITCH]=-35.0;
taknokolat 34:5719e6977ec7 1333 else{
taknokolat 34:5719e6977ec7 1334 t_def = 0;
taknokolat 34:5719e6977ec7 1335 targetAngle[PITCH]=g_gostraightPITCH;
taknokolat 34:5719e6977ec7 1336 }
taknokolat 34:5719e6977ec7 1337 }
HARUKIDELTA 0:17f575135219 1338 targetAngle[ROLL] = g_gostraightROLL;
taknokolat 34:5719e6977ec7 1339 //targetAngle[PITCH] = g_loopTHR;
HARUKIDELTA 0:17f575135219 1340 autopwm[THR] = SetTHRinRatio(g_takeoffTHR); //0.7;スロットルの割合
HARUKIDELTA 0:17f575135219 1341 }
HARUKIDELTA 0:17f575135219 1342
taknokolat 34:5719e6977ec7 1343
HARUKIDELTA 0:17f575135219 1344 //ヨーを目標値にして許容角度になるまで水平旋回
HARUKIDELTA 0:17f575135219 1345 int Rotate(float targetAngle[3], float TargetYAW){
HARUKIDELTA 0:17f575135219 1346 float diffYaw = TranslateNewYaw(TargetYAW, nowAngle[YAW]);
HARUKIDELTA 0:17f575135219 1347
HARUKIDELTA 0:17f575135219 1348 if(diffYaw > LIMIT_STRAIGHT_YAW){
HARUKIDELTA 0:17f575135219 1349 /*
HARUKIDELTA 0:17f575135219 1350 if(diffYaw > THRESHOLD_TURNINGRADIUS_YAW) UpdateTargetAngle_Rightloop_short(targetAngle);
HARUKIDELTA 0:17f575135219 1351 else UpdateTargetAngle_Rightloop(targetAngle);
HARUKIDELTA 0:17f575135219 1352 */
HARUKIDELTA 0:17f575135219 1353 UpdateTargetAngle_Rightloop_short(targetAngle);
HARUKIDELTA 0:17f575135219 1354 return 1;
HARUKIDELTA 0:17f575135219 1355 }else if(diffYaw < -LIMIT_STRAIGHT_YAW){
HARUKIDELTA 0:17f575135219 1356 UpdateTargetAngle_Leftloop_short(targetAngle);
HARUKIDELTA 0:17f575135219 1357 /*
HARUKIDELTA 0:17f575135219 1358 if(diffYaw < -THRESHOLD_TURNINGRADIUS_YAW) UpdateTargetAngle_Leftloop_short(targetAngle);
HARUKIDELTA 0:17f575135219 1359 else UpdateTargetAngle_Leftloop(targetAngle);
HARUKIDELTA 0:17f575135219 1360 */
HARUKIDELTA 0:17f575135219 1361 return 1;
HARUKIDELTA 0:17f575135219 1362 }else{
HARUKIDELTA 0:17f575135219 1363 UpdateTargetAngle_GoStraight(targetAngle);
HARUKIDELTA 0:17f575135219 1364 return 0;
HARUKIDELTA 0:17f575135219 1365 }
HARUKIDELTA 0:17f575135219 1366 }
HARUKIDELTA 0:17f575135219 1367
HARUKIDELTA 0:17f575135219 1368 //チキラー投下
HARUKIDELTA 0:17f575135219 1369 void Chicken_Drop(){
HARUKIDELTA 0:17f575135219 1370 if(CheckSW_Up(Ch7)){
taknokolat 30:624cb32e13a3 1371 autopwm[DROP] = 1911;
HARUKIDELTA 0:17f575135219 1372 pc.printf("Bombed!\r\n");
taknokolat 30:624cb32e13a3 1373 //RerurnChickenServo1.attach(&ReturnChickenServo1, 3);
HARUKIDELTA 0:17f575135219 1374 //operation_mode = Approach;
HARUKIDELTA 0:17f575135219 1375 //buzzer = 0;
HARUKIDELTA 0:17f575135219 1376 pc.printf("Goto LeftLoop mode\r\n");
HARUKIDELTA 0:17f575135219 1377 }
HARUKIDELTA 0:17f575135219 1378 }
HARUKIDELTA 0:17f575135219 1379
HARUKIDELTA 0:17f575135219 1380 void ReturnChickenServo1(){
HARUKIDELTA 0:17f575135219 1381 autopwm[DROP] = 1344;
HARUKIDELTA 0:17f575135219 1382 pc.printf("first reverse\r\n");
HARUKIDELTA 0:17f575135219 1383 RerurnChickenServo2.attach(&ReturnChickenServo2, 1);
HARUKIDELTA 0:17f575135219 1384 }
HARUKIDELTA 0:17f575135219 1385
HARUKIDELTA 0:17f575135219 1386 void ReturnChickenServo2(){
HARUKIDELTA 0:17f575135219 1387 autopwm[DROP] = 1392;
HARUKIDELTA 0:17f575135219 1388 pc.printf("second reverse\r\n");
taknokolat 10:652071c20bf6 1389 }
taknokolat 10:652071c20bf6 1390
taknokolat 10:652071c20bf6 1391 //着陸モード(PCからの指令に従う)
taknokolat 28:aa44903a01e1 1392 void UpdateTargetAngle_Approach(float targetAngle[3]){
taknokolat 10:652071c20bf6 1393
taknokolat 26:bc185a3d16b6 1394 static bool zeroTHR=true;//着陸時のスロットル動作確認用
taknokolat 24:2cc7a3a10e72 1395
taknokolat 26:bc185a3d16b6 1396 if(CheckSW_Up(Ch7)){
taknokolat 26:bc185a3d16b6 1397 output_status = Auto;
taknokolat 26:bc185a3d16b6 1398 led1 = 1;
taknokolat 26:bc185a3d16b6 1399 }else{
taknokolat 26:bc185a3d16b6 1400 output_status = Manual;
taknokolat 26:bc185a3d16b6 1401 led1 = 0;
taknokolat 26:bc185a3d16b6 1402 zeroTHR=true;
taknokolat 26:bc185a3d16b6 1403 }
taknokolat 26:bc185a3d16b6 1404
taknokolat 24:2cc7a3a10e72 1405
taknokolat 28:aa44903a01e1 1406 NVIC_DisableIRQ(USART2_IRQn);
taknokolat 10:652071c20bf6 1407 switch(g_landingcommand){
taknokolat 10:652071c20bf6 1408 case 'R': //右旋回セヨ
taknokolat 23:4928a6fd9eee 1409 if(zeroTHR==false){
HARUKIDELTA 19:0955311b0db6 1410 UpdateTargetAngle_Rightloop_zero(targetAngle);
HARUKIDELTA 19:0955311b0db6 1411 }
HARUKIDELTA 19:0955311b0db6 1412 else{
HARUKIDELTA 39:b8d5be233b70 1413 targetAngle[ROLL] = g_rightloopROLL_approach;
taknokolat 10:652071c20bf6 1414 targetAngle[PITCH] = g_rightloopPITCH ;
HARUKIDELTA 39:b8d5be233b70 1415 autopwm[RUD]=g_rightloopRUD_approach; //RUD固定
taknokolat 28:aa44903a01e1 1416 if(autopwm[AIL_R]<trimpwm[AIL_R]){ //エルロン上がりやすさ調節
taknokolat 28:aa44903a01e1 1417 autopwm[AIL_L]=trimpwm[AIL_L]+AIL_L_correctionrightloop+(autopwm[AIL_R]-trimpwm[AIL_R])*AIL_L_RatioRising;
taknokolat 28:aa44903a01e1 1418 }
taknokolat 28:aa44903a01e1 1419 else {autopwm[AIL_L]=trimpwm[AIL_L]+AIL_L_correctionrightloop+(autopwm[AIL_R]-trimpwm[AIL_R])*AIL_L_RatioDescent;
taknokolat 28:aa44903a01e1 1420 autopwm[AIL_R]=autopwm[AIL_R]+AIL_R_correctionrightloop;
taknokolat 10:652071c20bf6 1421 }
taknokolat 20:9393b0cfa44d 1422 }
taknokolat 28:aa44903a01e1 1423 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 10:652071c20bf6 1424 break;
taknokolat 20:9393b0cfa44d 1425
taknokolat 10:652071c20bf6 1426 case 'L': //左旋回セヨ
taknokolat 23:4928a6fd9eee 1427 if(zeroTHR==false){
HARUKIDELTA 19:0955311b0db6 1428 UpdateTargetAngle_Leftloop_zero(targetAngle);
taknokolat 28:aa44903a01e1 1429 }
HARUKIDELTA 19:0955311b0db6 1430 else{
HARUKIDELTA 39:b8d5be233b70 1431 targetAngle[ROLL] = g_leftloopROLL_approach;
taknokolat 28:aa44903a01e1 1432 targetAngle[PITCH] = g_leftloopPITCH;
HARUKIDELTA 39:b8d5be233b70 1433 autopwm[RUD]=g_leftloopRUD_approach;
taknokolat 28:aa44903a01e1 1434 if(autopwm[AIL_R]<trimpwm[AIL_R]){
taknokolat 28:aa44903a01e1 1435 autopwm[AIL_L]=trimpwm[AIL_L]+AIL_L_correctionleftloop+(autopwm[AIL_R]-trimpwm[AIL_R])*AIL_L_RatioRising;
taknokolat 28:aa44903a01e1 1436 }
taknokolat 28:aa44903a01e1 1437 else autopwm[AIL_L]=trimpwm[AIL_L]+AIL_L_correctionleftloop+(autopwm[AIL_R]-trimpwm[AIL_R])*AIL_L_RatioDescent;
taknokolat 28:aa44903a01e1 1438 }
taknokolat 28:aa44903a01e1 1439 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 28:aa44903a01e1 1440 break;
taknokolat 10:652071c20bf6 1441
taknokolat 10:652071c20bf6 1442 case 'G': //直進セヨ
taknokolat 23:4928a6fd9eee 1443 if(zeroTHR==false){
HARUKIDELTA 19:0955311b0db6 1444 UpdateTargetAngle_GoStraight_zero(targetAngle);
HARUKIDELTA 19:0955311b0db6 1445 }
HARUKIDELTA 19:0955311b0db6 1446 else{
taknokolat 10:652071c20bf6 1447 targetAngle[ROLL] = g_gostraightROLL;
taknokolat 10:652071c20bf6 1448 targetAngle[PITCH] = g_gostraightPITCH;
HARUKIDELTA 19:0955311b0db6 1449 }
taknokolat 28:aa44903a01e1 1450 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 10:652071c20bf6 1451 break;
taknokolat 10:652071c20bf6 1452
taknokolat 10:652071c20bf6 1453 case 'Y': //指定ノヨー方向ニ移動セヨ
taknokolat 10:652071c20bf6 1454 Rotate(targetAngle, g_SerialTargetYAW);
taknokolat 28:aa44903a01e1 1455 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 10:652071c20bf6 1456 break;
taknokolat 10:652071c20bf6 1457
taknokolat 29:887a38540508 1458 /*case 'B': //ブザーヲ鳴ラセ
taknokolat 10:652071c20bf6 1459 //buzzer = 1;
taknokolat 28:aa44903a01e1 1460 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 29:887a38540508 1461 break;*/
taknokolat 10:652071c20bf6 1462
taknokolat 29:887a38540508 1463 case 'B': //物資ヲ落トセ
taknokolat 10:652071c20bf6 1464 Chicken_Drop();
taknokolat 28:aa44903a01e1 1465 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 10:652071c20bf6 1466 break;
taknokolat 10:652071c20bf6 1467
taknokolat 10:652071c20bf6 1468 case 'C': //停止セヨ
taknokolat 10:652071c20bf6 1469 targetAngle[ROLL] = 0.0;
taknokolat 10:652071c20bf6 1470 targetAngle[PITCH] = -3.0;
taknokolat 10:652071c20bf6 1471 autopwm[THR] = minpwm[THR];
taknokolat 23:4928a6fd9eee 1472 zeroTHR=false;
taknokolat 28:aa44903a01e1 1473 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 10:652071c20bf6 1474 break;
taknokolat 28:aa44903a01e1 1475
taknokolat 28:aa44903a01e1 1476 default :
taknokolat 28:aa44903a01e1 1477 NVIC_EnableIRQ(USART2_IRQn);
taknokolat 28:aa44903a01e1 1478 break;
taknokolat 28:aa44903a01e1 1479
HARUKIDELTA 0:17f575135219 1480
taknokolat 10:652071c20bf6 1481 }
taknokolat 28:aa44903a01e1 1482
taknokolat 10:652071c20bf6 1483 }
taknokolat 10:652071c20bf6 1484
taknokolat 10:652071c20bf6 1485 void checkHeight(float targetAngle[3]){
taknokolat 10:652071c20bf6 1486
taknokolat 10:652071c20bf6 1487 static int targetHeight = 200;
taknokolat 33:0f7a35d55316 1488
taknokolat 10:652071c20bf6 1489 NVIC_DisableIRQ(EXTI9_5_IRQn);
taknokolat 10:652071c20bf6 1490 if(g_distance < targetHeight + ALLOWHEIGHT){
taknokolat 10:652071c20bf6 1491 UpdateTargetAngle_NoseUP(targetAngle);
taknokolat 10:652071c20bf6 1492 if(CheckSW_Up(Ch7)) led2 = 1;
taknokolat 10:652071c20bf6 1493 }
taknokolat 10:652071c20bf6 1494 else if(g_distance > targetHeight - ALLOWHEIGHT){
taknokolat 10:652071c20bf6 1495 UpdateTargetAngle_NoseDOWN(targetAngle);
taknokolat 10:652071c20bf6 1496 if(CheckSW_Up(Ch7)) led2 = 1;
taknokolat 10:652071c20bf6 1497 }
taknokolat 10:652071c20bf6 1498 else led2=0;
taknokolat 10:652071c20bf6 1499 NVIC_EnableIRQ(EXTI9_5_IRQn);
HARUKIDELTA 0:17f575135219 1500 }
HARUKIDELTA 0:17f575135219 1501
taknokolat 10:652071c20bf6 1502 void UpdateTargetAngle_NoseUP(float targetAngle[3]){
HARUKIDELTA 0:17f575135219 1503
HARUKIDELTA 0:17f575135219 1504 //targetAngle[PITCH] += 2.0f;
HARUKIDELTA 0:17f575135219 1505 //if(nowAngle[PITCH]<targetAngle[PITCH]) autopwm[THR] = SetTHRinRatio(0.6);
HARUKIDELTA 0:17f575135219 1506 autopwm[THR] = SetTHRinRatio(g_loopTHR+0.05);
HARUKIDELTA 0:17f575135219 1507 //pc.printf("nose UP");
HARUKIDELTA 0:17f575135219 1508 }
HARUKIDELTA 0:17f575135219 1509
HARUKIDELTA 0:17f575135219 1510 void UpdateTargetAngle_NoseDOWN(float targetAngle[3]){
HARUKIDELTA 0:17f575135219 1511
HARUKIDELTA 0:17f575135219 1512 //targetAngle[PITCH] -= 2.0f;
HARUKIDELTA 0:17f575135219 1513 autopwm[THR] = SetTHRinRatio(g_loopTHR-0.05);
HARUKIDELTA 0:17f575135219 1514 //pc.printf("nose DOWN");
HARUKIDELTA 0:17f575135219 1515 }
HARUKIDELTA 0:17f575135219 1516
HARUKIDELTA 0:17f575135219 1517 //直進
HARUKIDELTA 0:17f575135219 1518 void UpdateTargetAngle_GoStraight(float targetAngle[3]){
HARUKIDELTA 0:17f575135219 1519
HARUKIDELTA 19:0955311b0db6 1520 autopwm[RUD] = trimpwm[RUD];
HARUKIDELTA 0:17f575135219 1521 targetAngle[ROLL] = g_gostraightROLL;
HARUKIDELTA 0:17f575135219 1522 targetAngle[PITCH] = g_gostraightPITCH;
HARUKIDELTA 0:17f575135219 1523 autopwm[THR] = SetTHRinRatio(g_loopTHR);
HARUKIDELTA 0:17f575135219 1524
HARUKIDELTA 0:17f575135219 1525 //pc.printf("Roll = %f, PITCH = %f, THR = %d \r\n", targetAngle[ROLL], targetAngle[PITCH], autopwm[THR]);
HARUKIDELTA 0:17f575135219 1526 }
HARUKIDELTA 0:17f575135219 1527
HARUKIDELTA 19:0955311b0db6 1528 //直進(着陸時スロットル0のとき)
HARUKIDELTA 19:0955311b0db6 1529 void UpdateTargetAngle_GoStraight_zero(float targetAngle[3]){
HARUKIDELTA 19:0955311b0db6 1530
HARUKIDELTA 19:0955311b0db6 1531 autopwm[RUD] = trimpwm[RUD];
HARUKIDELTA 19:0955311b0db6 1532 targetAngle[ROLL] = g_gostraightROLL;
HARUKIDELTA 19:0955311b0db6 1533 targetAngle[PITCH] = g_gostraightPITCH;
HARUKIDELTA 19:0955311b0db6 1534 autopwm[THR] = minpwm[THR];
HARUKIDELTA 19:0955311b0db6 1535
HARUKIDELTA 19:0955311b0db6 1536 //pc.printf("Roll = %f, PITCH = %f, THR = %d \r\n", targetAngle[ROLL], targetAngle[PITCH], autopwm[THR]);
HARUKIDELTA 19:0955311b0db6 1537 }
HARUKIDELTA 3:206b17251f5b 1538
HARUKIDELTA 0:17f575135219 1539 //右旋回
HARUKIDELTA 0:17f575135219 1540 void UpdateTargetAngle_Rightloop(float targetAngle[3]){ //右旋回
HARUKIDELTA 0:17f575135219 1541
HARUKIDELTA 0:17f575135219 1542 targetAngle[PITCH] = g_rightloopPITCH ;
HARUKIDELTA 16:7fca5b938da6 1543 autopwm[RUD]=g_rightloopRUD; //RUD固定
TUATBM 9:f6367b7fd7be 1544 autopwm[THR] = SetTHRinRatio(0.5); //手動スロットル記憶
HARUKIDELTA 27:61876b34ded4 1545
taknokolat 28:aa44903a01e1 1546 /*
HARUKIDELTA 27:61876b34ded4 1547 if (nowAngle[ROLL]>20.0||nowAngle[ROLL]<-20.0){
HARUKIDELTA 27:61876b34ded4 1548 t2.start();
HARUKIDELTA 27:61876b34ded4 1549 pc.printf("Timer start.");
HARUKIDELTA 27:61876b34ded4 1550 }
HARUKIDELTA 27:61876b34ded4 1551 if(0.0<t2.read()<5.0){
taknokolat 28:aa44903a01e1 1552 //pc.printf("tagetAngle is changed.");
HARUKIDELTA 27:61876b34ded4 1553 targetAngle[ROLL] = rightloopROLL2;
HARUKIDELTA 27:61876b34ded4 1554 }
HARUKIDELTA 27:61876b34ded4 1555 else {
HARUKIDELTA 27:61876b34ded4 1556 t2.stop();
HARUKIDELTA 27:61876b34ded4 1557 t2.reset();
HARUKIDELTA 27:61876b34ded4 1558 pc.printf("Timer stopped.");
HARUKIDELTA 27:61876b34ded4 1559 targetAngle[ROLL] = g_rightloopROLL;
HARUKIDELTA 27:61876b34ded4 1560 }
taknokolat 28:aa44903a01e1 1561 */
HARUKIDELTA 22:438bedf24707 1562 if(autopwm[AIL_R]<trimpwm[AIL_R]){ //エルロン上がりやすさ調節
HARUKIDELTA 3:206b17251f5b 1563 autopwm[AIL_L]=trimpwm[AIL_L]+AIL_L_correctionrightloop+(autopwm[AIL_R]-trimpwm[AIL_R])*AIL_L_RatioRising;
HARUKIDELTA 3:206b17251f5b 1564 }
HARUKIDELTA 3:206b17251f5b 1565 else autopwm[AIL_L]=trimpwm[AIL_L]+AIL_L_correctionrightloop+(autopwm[AIL_R]-trimpwm[AIL_R])*AIL_L_RatioDescent;
TUATBM 9:f6367b7fd7be 1566 autopwm[AIL_R]=autopwm[AIL_R]+AIL_R_correctionrightloop;
TUATBM 9:f6367b7fd7be 1567
HARUKIDELTA 27:61876b34ded4 1568
HARUKIDELTA 0:17f575135219 1569 //checkHeight(targetAngle);
HARUKIDELTA 0:17f575135219 1570 //pc.printf("Roll = %f, PITCH = %f, THR = %d \r\n", targetAngle[ROLL], targetAngle[PITCH], autopwm[THR]);
HARUKIDELTA 0:17f575135219 1571 }
HARUKIDELTA 0:17f575135219 1572
HARUKIDELTA 4:fff1165ca50c 1573 //右旋回(着陸時スロットル0の時)
HARUKIDELTA 4:fff1165ca50c 1574 void UpdateTargetAngle_Rightloop_zero(float targetAngle[3]){ //右旋回
taknokolat 20:9393b0cfa44d 1575 autopwm[THR]=minpwm[THR];
HARUKIDELTA 39:b8d5be233b70 1576 targetAngle[ROLL] = g_rightloopROLL_approach;
HARUKIDELTA 4:fff1165ca50c 1577 targetAngle[PITCH] = g_rightloopPITCH ;
HARUKIDELTA 39:b8d5be233b70 1578 autopwm[RUD]=g_rightloopRUD_approach; //RUD固定
HARUKIDELTA 22:438bedf24707 1579 if(autopwm[AIL_R]<trimpwm[AIL_R]){ //エルロン上がりやすさ調節
taknokolat 20:9393b0cfa44d 1580 autopwm[AIL_L]=trimpwm[AIL_L]+AIL_L_correctionrightloop+(autopwm[AIL_R]-trimpwm[AIL_R])*AIL_L_RatioRising;
taknokolat 20:9393b0cfa44d 1581 }
taknokolat 20:9393b0cfa44d 1582 else autopwm[AIL_L]=trimpwm[AIL_L]+AIL_L_correctionrightloop+(autopwm[AIL_R]-trimpwm[AIL_R])*AIL_L_RatioDescent;
taknokolat 20:9393b0cfa44d 1583 autopwm[AIL_R]=autopwm[AIL_R]+AIL_R_correctionrightloop;
HARUKIDELTA 4:fff1165ca50c 1584
HARUKIDELTA 4:fff1165ca50c 1585 //checkHeight(targetAngle);
HARUKIDELTA 4:fff1165ca50c 1586 //pc.printf("Roll = %f, PITCH = %f, THR = %d \r\n", targetAngle[ROLL], targetAngle[PITCH], autopwm[THR]);
HARUKIDELTA 4:fff1165ca50c 1587 }
HARUKIDELTA 4:fff1165ca50c 1588
HARUKIDELTA 0:17f575135219 1589 void UpdateTargetAngle_Rightloop_short(float targetAngle[3]){ //右旋回
HARUKIDELTA 0:17f575135219 1590
HARUKIDELTA 0:17f575135219 1591 targetAngle[ROLL] = g_rightloopROLLshort;
HARUKIDELTA 0:17f575135219 1592 targetAngle[PITCH] = g_rightloopPITCHshort;
HARUKIDELTA 16:7fca5b938da6 1593 autopwm[RUD]=g_rightloopshortRUD;
HARUKIDELTA 19:0955311b0db6 1594 autopwm[THR] = SetTHRinRatio(0.5);
HARUKIDELTA 22:438bedf24707 1595 if(autopwm[AIL_R]<trimpwm[AIL_R]){
HARUKIDELTA 3:206b17251f5b 1596 autopwm[AIL_L]=trimpwm[AIL_L]+AIL_L_correctionrightloopshort+(autopwm[AIL_R]-trimpwm[AIL_R])*AIL_L_RatioRising;
HARUKIDELTA 3:206b17251f5b 1597 }
HARUKIDELTA 3:206b17251f5b 1598 else autopwm[AIL_L]=trimpwm[AIL_L]+AIL_L_correctionrightloopshort+(autopwm[AIL_R]-trimpwm[AIL_R])*AIL_L_RatioDescent;
HARUKIDELTA 0:17f575135219 1599
HARUKIDELTA 0:17f575135219 1600 //pc.printf("Roll = %f, PITCH = %f, THR = %d \r\n", targetAngle[ROLL], targetAngle[PITCH], autopwm[THR]);
HARUKIDELTA 0:17f575135219 1601 }
HARUKIDELTA 0:17f575135219 1602
HARUKIDELTA 0:17f575135219 1603 //左旋回
HARUKIDELTA 0:17f575135219 1604 void UpdateTargetAngle_Leftloop(float targetAngle[3]){
HARUKIDELTA 0:17f575135219 1605
HARUKIDELTA 0:17f575135219 1606 targetAngle[ROLL] = g_leftloopROLL;
HARUKIDELTA 0:17f575135219 1607 targetAngle[PITCH] = g_leftloopPITCH;
HARUKIDELTA 16:7fca5b938da6 1608 autopwm[RUD]=g_leftloopRUD;
HARUKIDELTA 19:0955311b0db6 1609 autopwm[THR] = SetTHRinRatio(0.5);
HARUKIDELTA 22:438bedf24707 1610 if(autopwm[AIL_R]<trimpwm[AIL_R]){
HARUKIDELTA 17:55249ea37dff 1611 autopwm[AIL_L]=trimpwm[AIL_L]+g_AIL_L_correctionleftloop+(autopwm[AIL_R]-trimpwm[AIL_R])*AIL_L_RatioRising;
HARUKIDELTA 4:fff1165ca50c 1612 }
HARUKIDELTA 17:55249ea37dff 1613 else autopwm[AIL_L]=trimpwm[AIL_L]+g_AIL_L_correctionleftloop+(autopwm[AIL_R]-trimpwm[AIL_R])*AIL_L_RatioDescent;
HARUKIDELTA 4:fff1165ca50c 1614 //checkHeight(targetAngle);
HARUKIDELTA 4:fff1165ca50c 1615
HARUKIDELTA 4:fff1165ca50c 1616 //printf("Roll = %f, PITCH = %f, THR = %d \r\n", targetAngle[], targetAngle[PITCH], autopwm[THR]);
HARUKIDELTA 4:fff1165ca50c 1617 }
HARUKIDELTA 4:fff1165ca50c 1618
HARUKIDELTA 4:fff1165ca50c 1619 //左旋回(着陸時スロットル0のとき)
HARUKIDELTA 4:fff1165ca50c 1620 void UpdateTargetAngle_Leftloop_zero(float targetAngle[3]){
HARUKIDELTA 4:fff1165ca50c 1621
HARUKIDELTA 39:b8d5be233b70 1622 targetAngle[ROLL] = g_leftloopROLL_approach;
HARUKIDELTA 4:fff1165ca50c 1623 targetAngle[PITCH] = g_leftloopPITCH;
HARUKIDELTA 39:b8d5be233b70 1624 autopwm[RUD]=g_leftloopRUD_approach;
HARUKIDELTA 4:fff1165ca50c 1625 autopwm[THR] = minpwm[THR];
HARUKIDELTA 22:438bedf24707 1626 if(autopwm[AIL_R]<trimpwm[AIL_R]){
HARUKIDELTA 4:fff1165ca50c 1627 autopwm[AIL_L]=trimpwm[AIL_L]+AIL_L_correctionleftloop+(autopwm[AIL_R]-trimpwm[AIL_R])*AIL_L_RatioRising;
HARUKIDELTA 4:fff1165ca50c 1628 }
HARUKIDELTA 4:fff1165ca50c 1629 else autopwm[AIL_L]=trimpwm[AIL_L]+AIL_L_correctionleftloop+(autopwm[AIL_R]-trimpwm[AIL_R])*AIL_L_RatioDescent;
HARUKIDELTA 4:fff1165ca50c 1630 //autopwm[AIL_L]=trimpwm[AIL_L]+AIL_L_correctionleftloopshort+(autopwm[AIL_R]-trimpwm[AIL_R])*AIL_L_Ratio_leftloop;
HARUKIDELTA 0:17f575135219 1631 //checkHeight(targetAngle);
HARUKIDELTA 0:17f575135219 1632
HARUKIDELTA 2:23daa5fa28b4 1633 //printf("Roll = %f, PITCH = %f, THR = %d \r\n", targetAngle[], targetAngle[PITCH], autopwm[THR]);
HARUKIDELTA 0:17f575135219 1634 }
HARUKIDELTA 0:17f575135219 1635
HARUKIDELTA 0:17f575135219 1636 void UpdateTargetAngle_Leftloop_short(float targetAngle[3]){
HARUKIDELTA 0:17f575135219 1637
HARUKIDELTA 0:17f575135219 1638 targetAngle[ROLL] = g_leftloopROLLshort;
HARUKIDELTA 0:17f575135219 1639 targetAngle[PITCH] = g_leftloopPITCHshort;
HARUKIDELTA 16:7fca5b938da6 1640 autopwm[RUD]=g_leftloopRUD;
HARUKIDELTA 19:0955311b0db6 1641 autopwm[THR] = SetTHRinRatio(0.5);
HARUKIDELTA 22:438bedf24707 1642 if(autopwm[AIL_R]<trimpwm[AIL_R]){
HARUKIDELTA 4:fff1165ca50c 1643 autopwm[AIL_L]=trimpwm[AIL_L]+AIL_L_correctionleftloopshort+(autopwm[AIL_R]-trimpwm[AIL_R])*AIL_L_RatioRising;
HARUKIDELTA 4:fff1165ca50c 1644 }
HARUKIDELTA 4:fff1165ca50c 1645 else autopwm[AIL_L]=trimpwm[AIL_L]+AIL_L_correctionleftloopshort+(autopwm[AIL_R]-trimpwm[AIL_R])*AIL_L_RatioDescent;
HARUKIDELTA 4:fff1165ca50c 1646
HARUKIDELTA 0:17f575135219 1647 //pc.printf("Roll = %f, PITCH = %f, THR = %d \r\n", targetAngle[ROLL], targetAngle[PITCH], autopwm[THR]);
HARUKIDELTA 0:17f575135219 1648 }
taknokolat 10:652071c20bf6 1649
HARUKIDELTA 18:cce82f3374fc 1650 void Sbusprintf(){
HARUKIDELTA 18:cce82f3374fc 1651
HARUKIDELTA 18:cce82f3374fc 1652 for(uint8_t i=0; i<8; i++) pc.printf("ch.%d = %d ",i+1,sbus.manualpwm[i]);
HARUKIDELTA 18:cce82f3374fc 1653 pc.printf("\r\n");
HARUKIDELTA 18:cce82f3374fc 1654
HARUKIDELTA 18:cce82f3374fc 1655 }
HARUKIDELTA 18:cce82f3374fc 1656
HARUKIDELTA 0:17f575135219 1657
taknokolat 36:197b514eae3b 1658
HARUKIDELTA 0:17f575135219 1659 //デバッグ用
HARUKIDELTA 0:17f575135219 1660 void DebugPrint(){
HARUKIDELTA 0:17f575135219 1661 /*
HARUKIDELTA 0:17f575135219 1662 static int16_t deltaT = 0, t_start = 0;
HARUKIDELTA 0:17f575135219 1663 deltaT = t.read_u2s() - t_start;
HARUKIDELTA 0:17f575135219 1664 pc.printf("t:%d us, ",deltaT);
HARUKIDELTA 0:17f575135219 1665 pc.printf("\r\n");
HARUKIDELTA 0:17f575135219 1666 t_start = t.read_us();
HARUKIDELTA 0:17f575135219 1667 */
HARUKIDELTA 0:17f575135219 1668 //for(uint8_t i=0; i<8; i++) pc.printf("%d ",sbus.manualpwm[i]);
HARUKIDELTA 0:17f575135219 1669 //for(uint8_t i=1; i<4; i++) pc.printf("%d ",sbus.manualpwm[i]);
HARUKIDELTA 0:17f575135219 1670 //pc.printf("\r\n");
taknokolat 28:aa44903a01e1 1671 //for(uint8_t i=0; i<3; i++) pc.printf("%3.2f\t",nowAngle[i]);
HARUKIDELTA 0:17f575135219 1672 //for(uint8_t i=0; i<2; i++) pc.printf("%3.2f\t",nowAngle[i]); //ロール、ピッチのみ 小数点以下2ケタ
HARUKIDELTA 35:25e1afadd455 1673 //pc.printf("%d\t",autopwm[AIL_L]);
HARUKIDELTA 35:25e1afadd455 1674 //pc.printf("%d\t",autopwm[RUD]);
HARUKIDELTA 0:17f575135219 1675 //pc.printf("%d",g_distance);
taknokolat 33:0f7a35d55316 1676 //NVIC_DisableIRQ(EXTI9_5_IRQn);
taknokolat 33:0f7a35d55316 1677 //pc.printf("g_distance = %d",g_distance);
taknokolat 33:0f7a35d55316 1678 //NVIC_EnableIRQ(EXTI9_5_IRQn);
HARUKIDELTA 0:17f575135219 1679 //pc.printf("Mode: %c: ",g_buf[0]);
HARUKIDELTA 0:17f575135219 1680 //if(g_buf[0] == 'Y') pc.printf(" %3.1f",g_SerialTargetYAW);
taknokolat 33:0f7a35d55316 1681 //pc.printf("\r\n");
HARUKIDELTA 0:17f575135219 1682 }