ジャパンオープン用のメインプログラム
Dependencies: mbed AQM1602 HMC6352 PID
def.h
00001 #ifndef _DEF_H_ 00002 #define _DEF_H_ 00003 00004 //red or green 00005 #define RED_CAT//jj 00006 //#define GREEN_CAT//lily 00007 00008 //BT(BlueTooth) 00009 #define DATA_NUM 8+2//2byte→KEYCODE(拝啓)とCHECKCODE(敬具) 8byte→やりとりするデータ 00010 #define TX_KEYCODE 0xAA//あちらのKEYCODE 00011 #define RX_KEYCODE 0xAA//こちらのKEYCODE 00012 #define KEY 0//KEYCODEは配列の最初 00013 #define CHECK DATA_NUM-1//CHECKCODEは配列の最後 00014 00015 00016 //Switch 入力値 00017 #define NONE 0 00018 #define UP 1 00019 #define DOWN 2 00020 #define RIGHT 3 00021 #define LEFT 4 00022 00023 //Lcd 設定値 00024 #define LCD_COLUMN_NUM 0x11 00025 #define BUFSIZE 7 00026 #define STATE_NUM_X 0x08 00027 #define STATE_NUM_Y 0x10 00028 00029 #define JUMP_TAG_MAX 0xFFFF 00030 //tag 00031 #define ZERO_FUNCTION 0 00032 #define START 1 00033 #define GET_IR 2 00034 #define GET_SNS0 3 00035 #define GET_PID_VALUE 4 00036 #define CALIBRATION_ENTER 5 00037 #define CALIBRATION_EXIT 6 00038 #define FRONT_RESET 7 00039 #define SET_POWER1 8 00040 #define SET_POWER2 9 00041 #define SOFT_RESET 10 00042 #define SET_STRATEGY1 11 00043 #define SET_STRATEGY2 12 00044 #define SET_STRATEGY3 13 00045 #define SET_STRATEGY4 14 00046 #define START2 15 00047 00048 #define SET_POWER_DOWN 16 00049 #define SET_POWER_UP 17 00050 #define SET_STRATEGY_DOWN 18 00051 #define SET_STRATEGY_UP 19 00052 00053 #define DRIVE_KICKER 20 00054 #define DRIVE_DRIBBLER_AND_KICKER 21 00055 00056 #define CALIBRATION_TURN 22 00057 #define RW_PID 23 00058 00059 #define TURN_AND_START 24 00060 #define CALIBRATION_ENTER_OR_EXIT 25 00061 00062 typedef struct {//for command 00063 char LcdStr[STATE_NUM_X][BUFSIZE]; 00064 uint8_t str_num; 00065 uint8_t (*CommandFunction)(uint8_t x); 00066 uint16_t tag_num; 00067 } CommandItem; 00068 00069 00070 //tag 00071 #define MODE_ATTACK0 0 00072 #define MODE_ATTACK1 1 00073 #define MODE_ATTACK2 2 00074 #define MODE_ATTACK3 3 00075 #define MODE_ATTACK4 4 00076 #define MODE_ATTACK5 5 00077 00078 #define MODE_DEBUG0 6 00079 #define MODE_DEBUG1 7 00080 #define MODE_DEBUG2 8 00081 #define MODE_DEBUG3 9 00082 #define MODE_DEBUG4 10 00083 #define MODE_DEBUG5 11 00084 00085 typedef struct {//for active 00086 char LcdStr[LCD_COLUMN_NUM]; 00087 void (*ActiveFunction)(void); 00088 uint16_t tag_num; 00089 } ActiveItem; 00090 00091 //繰り返し割り込み 00092 #define DUTY_NUM 1 00093 00094 #define DUTY_SW 0 00095 #define DUTY_GYRO 1 00096 #define DUTY_PING 2 00097 #define DUTY_COLOR 3 00098 #define DUTY_MOUSE 4 00099 00100 /*PID処理*/ 00101 #define RATE 0.052//52 00102 #define PID_BIAS 0.0//1.0 00103 #define REFERENCE 180.0 00104 #define MINIMUM 0.0 00105 #define MAXIMUM 359.9 00106 #define P_GAIN 1.3//1.25//0.8 //0.78 00107 #define I_GAIN 0.0 //0.0 00108 #define D_GAIN 0.01//0.01 //0.009 00109 #define OUT_LIMIT 30.0 00110 #define MAX_POW 100 00111 #define MIN_POW -100 00112 #define PID_CYCLE 0.05 //s 00113 00114 #define PID_OUT_MIN 5 00115 00116 //hmc 00117 #define HMC_RUN 1 00118 #define HMC_RST 0 00119 00120 //ir 00121 //ir_pow_old 00122 #define IR_X 0 00123 #define IR_Y 1 00124 //ir_pow 00125 #define IR_X_DIR 0 00126 #define IR_Y_DIR 1 00127 #define IR_X_TURN 2 00128 #define IR_Y_TURN 3 00129 00130 #define IR_SHORT 0 00131 #define IR_LONG 1 00132 00133 #define X_AXIS 0 00134 #define Y_AXIS 1 00135 00136 00137 #define DIS_0 0x0//low_value 00138 #define DIS_1 0x1 00139 #define DIS_2 0x2 00140 #define DIS_3 0x3 00141 #define DIS_4 0x4 00142 #define DIS_5 0x5 00143 #define DIS_6 0x6 00144 #define DIS_7 0x7//high_value 00145 00146 //ping 00147 #define L_PING 1 00148 #define R_PING 0 00149 #define F_PING 2 00150 #define B_PING 3 00151 00152 #define X_PING 0 00153 #define Y_PING 1 00154 00155 //0,1...main 00156 //2,3...debug board 00157 00158 //line 00159 #define LINE_EMPTY 0xFF 00160 00161 #define A_SPOT 0 00162 #define B_SPOT 1 00163 #define C_SPOT 2 00164 #define AB_SPOT 3 00165 00166 #define LINE_RF 5 00167 #define LINE_DELAY_1 0.5//1.0 00168 #define LINE_DELAY_2 0.125//0.5//.25 00169 #define LINE_DELAY_3 0.125//.25 00170 00171 #define LINE_REPEAT 1 00172 00173 #define L_LINE 1 00174 #define R_LINE 0 00175 #define F_LINE 2 00176 #define B_LINE 3 00177 00178 #define X_LINE 0 00179 #define Y_LINE 1 00180 00181 #define LINE_INSIDE 0 00182 #define LINE_OUTSIDE 1 00183 00184 //hard error 00185 00186 #ifdef RED_CAT 00187 #define LINE_FIX 0x0 00188 #define LINE_FREE 0x7 00189 00190 //右後左ド 00191 #define MD_1CH (1) 00192 #define MD_2CH (1) 00193 #define MD_3CH (1) 00194 #define MD_4CH (-1) 00195 #endif /*RED_CAT*/ 00196 00197 #ifdef GREEN_CAT 00198 #define LINE_FIX 0x7 00199 #define LINE_FREE 0x0 00200 00201 //右後左ド 00202 #define MD_1CH (1) 00203 #define MD_2CH (1) 00204 #define MD_3CH (-1) 00205 #define MD_4CH (-1) 00206 #endif /*GREEN_CAT*/ 00207 00208 00209 //思考パターン 00210 #define STRATEGY_NUM 12 00211 00212 //計算 00213 #define ROUND(x) ((x > 0) ? (x + 0.5) : (x - 0.5))//x...整数 00214 #define PI 3.14159265358979323846 00215 #define DEG2RAD(deg) (PI*(deg)/180.0) 00216 #define RAD2DEG(rad) (180.0(rad)/PI) 00217 00218 //データ 00219 typedef struct { 00220 //cmps&pid 00221 double cmps, CmpsInitialValue, CmpsInitialValue2, CmpsInitialValue0, CmpsDiff;//0<x<360 00222 int16_t FrontDeg, AtkDeg, HoldDeg, GoalDeg; 00223 //正...右回転 00224 //負...左回転 00225 double InputPID;//<<gyrosensor 00226 int16_t OutputPID;//>>motor 00227 } CompassVal; 00228 typedef struct { 00229 //ping 00230 uint8_t ping[4]; 00231 //line 00232 uint8_t lineSpot[3]; 00233 uint8_t lnFlag[3]; 00234 uint8_t NonWall[4]; 00235 uint8_t NearWall[2]; 00236 uint8_t ReturnDir[2]; 00237 00238 uint8_t lnHold; 00239 uint8_t lnRaw; 00240 uint8_t lnRawMemory[3]; 00241 uint8_t lnRawOrder[3];//first_second_third 00242 uint8_t lnRawOrderLog1[3];//first_second_third 00243 uint8_t lnRawOrderLog2[3];//first_second_third 00244 uint8_t lnRawRise[3]; 00245 uint8_t lnRawReturn; 00246 uint8_t lnRawLastRise; 00247 uint8_t lnStop[2]; 00248 //uint8_t lnStay[2]; 00249 uint8_t lnStay[2]; 00250 uint8_t lnStayNow[2]; 00251 uint8_t lnCorner[4]; 00252 uint8_t lnRepeat; 00253 uint8_t FieldSpot;//0...inside,1...outside 00254 uint8_t lnOrder[3];//first_second_third 00255 00256 uint8_t lnState; 00257 /*uint8_t LineFlag[3]; 00258 uint8_t LinePriority[3]; 00259 uint8_t LineBind[3];*/ 00260 //ir(spi) 00261 uint8_t irKey;//2bit 00262 uint8_t irValPhase[2];//3*2bit 00263 uint8_t irDif[2];//3bit 00264 uint8_t irPosition;//5bit 00265 00266 uint8_t irSpot[2];//4*2bit//old 00267 //ir(playing) 00268 uint8_t irNotice; 00269 uint8_t irLastNotice; 00270 uint8_t irStayNotice; 00271 uint8_t irLastPosition; 00272 //ball 00273 uint8_t ball; 00274 } SensorVal; 00275 typedef struct { 00276 //system,flag 00277 uint8_t strategy; 00278 uint16_t jump_flag;//0<=x<=JUMP_TAG_NUM 00279 uint8_t stopflag; 00280 uint8_t KickOffFlag; 00281 uint8_t DribbleFlag; 00282 uint8_t KickStopFlag; 00283 uint8_t TurnStopFlag; 00284 00285 uint8_t BallHoldJudgeFlag; 00286 uint8_t BallHoldFlag; 00287 00288 uint8_t BackHomeFlag; 00289 uint8_t HomeStayFlag[2]; 00290 uint8_t TurnStartFlag; 00291 uint8_t MotorFlag; 00292 uint8_t InfoFlag; 00293 //uint8_t PidFlag; 00294 uint8_t DefenceFlag; 00295 //blind//on...1/off...0 00296 uint8_t IrBlind; 00297 uint8_t LineBlind; 00298 uint8_t PingBlind; 00299 00300 uint8_t DriBlind; 00301 uint8_t DriMotorBlind; 00302 uint8_t TurnAtkBlind; 00303 uint8_t TurnDriBlind; 00304 uint8_t TurnHoldBlind; 00305 uint8_t KickBlind; 00306 uint8_t HomeBlind; 00307 00308 //motor 00309 uint8_t pow_num; 00310 uint8_t s_pow; 00311 uint8_t m_pow; 00312 uint8_t l_pow; 00313 uint8_t dri_pow; 00314 uint8_t ir_pow_table; 00315 } SystemVal; 00316 00317 #endif
Generated on Wed Jul 13 2022 02:59:03 by 1.7.2