ジャパンオープン用のメインプログラム

Dependencies:   mbed AQM1602 HMC6352 PID

Committer:
lilac0112_1
Date:
Thu Mar 10 03:03:50 2016 +0000
Revision:
10:6df631c39f9b
Parent:
9:c966191926c5
Child:
11:3efae754e6ef
pid+alpha

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lilac0112_1 0:ea35c18c85fc 1 #ifndef _DEF_H_
lilac0112_1 0:ea35c18c85fc 2 #define _DEF_H_
lilac0112_1 0:ea35c18c85fc 3
lilac0112_1 0:ea35c18c85fc 4 //BT(BlueTooth)
lilac0112_1 0:ea35c18c85fc 5 #define DATA_NUM 8+2//2byte→KEYCODE(拝啓)とCHECKCODE(敬具) 8byte→やりとりするデータ
lilac0112_1 0:ea35c18c85fc 6 #define TX_KEYCODE 0xAA//あちらのKEYCODE
lilac0112_1 0:ea35c18c85fc 7 #define RX_KEYCODE 0xAA//こちらのKEYCODE
lilac0112_1 0:ea35c18c85fc 8 #define KEY 0//KEYCODEは配列の最初
lilac0112_1 0:ea35c18c85fc 9 #define CHECK DATA_NUM-1//CHECKCODEは配列の最後
lilac0112_1 0:ea35c18c85fc 10
lilac0112_1 0:ea35c18c85fc 11
lilac0112_1 0:ea35c18c85fc 12 //Switch 入力値
lilac0112_1 0:ea35c18c85fc 13 #define NONE 0
lilac0112_1 0:ea35c18c85fc 14 #define UP 1
lilac0112_1 0:ea35c18c85fc 15 #define DOWN 2
lilac0112_1 0:ea35c18c85fc 16 #define RIGHT 3
lilac0112_1 0:ea35c18c85fc 17 #define LEFT 4
lilac0112_1 0:ea35c18c85fc 18
lilac0112_1 0:ea35c18c85fc 19 //Lcd 設定値
lilac0112_1 7:efe90188a49d 20 #define LCD_COLUMN_NUM 0x11
lilac0112_1 3:c49ea7ad8e91 21 #define BUFSIZE 7
lilac0112_1 10:6df631c39f9b 22 #define STATE_NUM_X 0x08
lilac0112_1 0:ea35c18c85fc 23 #define STATE_NUM_Y 0x10
lilac0112_1 3:c49ea7ad8e91 24
lilac0112_1 4:52da8da146d4 25 #define JUMP_TAG_MAX 0xFFFF
lilac0112_1 4:52da8da146d4 26 //tag
lilac0112_1 8:25c8c75d182a 27 #define ZERO_FUNCTION 0
lilac0112_1 8:25c8c75d182a 28 #define START 1
lilac0112_1 8:25c8c75d182a 29 #define GET_IR 2
lilac0112_1 10:6df631c39f9b 30 #define GET_SNS0 3
lilac0112_1 8:25c8c75d182a 31 #define GET_PID_VALUE 4
lilac0112_1 8:25c8c75d182a 32 #define CALIBRATION_ENTER 5
lilac0112_1 8:25c8c75d182a 33 #define CALIBRATION_EXIT 6
lilac0112_1 8:25c8c75d182a 34 #define FRONT_RESET 7
lilac0112_1 8:25c8c75d182a 35 #define SET_POWER1 8
lilac0112_1 8:25c8c75d182a 36 #define SET_POWER2 9
lilac0112_1 8:25c8c75d182a 37 #define SOFT_RESET 10
lilac0112_1 8:25c8c75d182a 38 #define SET_STRATEGY1 11
lilac0112_1 8:25c8c75d182a 39 #define SET_STRATEGY2 12
lilac0112_1 8:25c8c75d182a 40 #define SET_STRATEGY3 13
lilac0112_1 8:25c8c75d182a 41 #define SET_STRATEGY4 14
lilac0112_1 8:25c8c75d182a 42 #define START2 15
lilac0112_1 8:25c8c75d182a 43
lilac0112_1 8:25c8c75d182a 44 #define SET_POWER_DOWN 16
lilac0112_1 8:25c8c75d182a 45 #define SET_POWER_UP 17
lilac0112_1 8:25c8c75d182a 46 #define SET_STRATEGY_DOWN 18
lilac0112_1 8:25c8c75d182a 47 #define SET_STRATEGY_UP 19
lilac0112_1 4:52da8da146d4 48
lilac0112_1 9:c966191926c5 49 #define DRIVE_KICKER 20
lilac0112_1 10:6df631c39f9b 50 #define DRIVE_DRIBBLER_AND_KICKER 21
lilac0112_1 10:6df631c39f9b 51
lilac0112_1 10:6df631c39f9b 52 #define CALIBRATION_TURN 22
lilac0112_1 10:6df631c39f9b 53 #define RW_PID 23
lilac0112_1 10:6df631c39f9b 54
lilac0112_1 10:6df631c39f9b 55 #define TURN_AND_START 24
lilac0112_1 9:c966191926c5 56
lilac0112_1 3:c49ea7ad8e91 57 typedef struct {//for command
lilac0112_1 3:c49ea7ad8e91 58 char LcdStr[STATE_NUM_X][BUFSIZE];
lilac0112_1 3:c49ea7ad8e91 59 uint8_t str_num;
lilac0112_1 3:c49ea7ad8e91 60 uint8_t (*CommandFunction)(uint8_t x);
lilac0112_1 4:52da8da146d4 61 uint16_t tag_num;
lilac0112_1 3:c49ea7ad8e91 62 } CommandItem;
lilac0112_1 3:c49ea7ad8e91 63
lilac0112_1 7:efe90188a49d 64
lilac0112_1 7:efe90188a49d 65 //tag
lilac0112_1 7:efe90188a49d 66 #define MODE_ATTACK0 0
lilac0112_1 7:efe90188a49d 67 #define MODE_ATTACK1 1
lilac0112_1 7:efe90188a49d 68 #define MODE_ATTACK2 2
lilac0112_1 7:efe90188a49d 69 #define MODE_ATTACK3 3
lilac0112_1 7:efe90188a49d 70 #define MODE_ATTACK4 4
lilac0112_1 7:efe90188a49d 71 #define MODE_ATTACK5 5
lilac0112_1 7:efe90188a49d 72
lilac0112_1 7:efe90188a49d 73 #define MODE_DEBUG0 6
lilac0112_1 7:efe90188a49d 74 #define MODE_DEBUG1 7
lilac0112_1 7:efe90188a49d 75 #define MODE_DEBUG2 8
lilac0112_1 7:efe90188a49d 76 #define MODE_DEBUG3 9
lilac0112_1 7:efe90188a49d 77 #define MODE_DEBUG4 10
lilac0112_1 7:efe90188a49d 78 #define MODE_DEBUG5 11
lilac0112_1 7:efe90188a49d 79
lilac0112_1 7:efe90188a49d 80 typedef struct {//for active
lilac0112_1 7:efe90188a49d 81 char LcdStr[LCD_COLUMN_NUM];
lilac0112_1 7:efe90188a49d 82 void (*ActiveFunction)(void);
lilac0112_1 7:efe90188a49d 83 uint16_t tag_num;
lilac0112_1 7:efe90188a49d 84 } ActiveItem;
lilac0112_1 7:efe90188a49d 85
lilac0112_1 0:ea35c18c85fc 86 //繰り返し割り込み
lilac0112_1 0:ea35c18c85fc 87 #define DUTY_NUM 1
lilac0112_1 0:ea35c18c85fc 88
lilac0112_1 0:ea35c18c85fc 89 #define DUTY_SW 0
lilac0112_1 0:ea35c18c85fc 90 #define DUTY_GYRO 1
lilac0112_1 0:ea35c18c85fc 91 #define DUTY_PING 2
lilac0112_1 0:ea35c18c85fc 92 #define DUTY_COLOR 3
lilac0112_1 0:ea35c18c85fc 93 #define DUTY_MOUSE 4
lilac0112_1 0:ea35c18c85fc 94
lilac0112_1 0:ea35c18c85fc 95 /*PID処理*/
lilac0112_1 0:ea35c18c85fc 96 #define RATE 0.052//52
lilac0112_1 9:c966191926c5 97 #define PID_BIAS 0.0//1.0
lilac0112_1 0:ea35c18c85fc 98 #define REFERENCE 180.0
lilac0112_1 0:ea35c18c85fc 99 #define MINIMUM 0.0
lilac0112_1 0:ea35c18c85fc 100 #define MAXIMUM 359.9
lilac0112_1 0:ea35c18c85fc 101 #define P_GAIN 1.3//1.25//0.8 //0.78
lilac0112_1 0:ea35c18c85fc 102 #define I_GAIN 0.0 //0.0
lilac0112_1 0:ea35c18c85fc 103 #define D_GAIN 0.01//0.01 //0.009
lilac0112_1 0:ea35c18c85fc 104 #define OUT_LIMIT 30.0
lilac0112_1 0:ea35c18c85fc 105 #define MAX_POW 100
lilac0112_1 0:ea35c18c85fc 106 #define MIN_POW -100
lilac0112_1 0:ea35c18c85fc 107 #define PID_CYCLE 0.05 //s
lilac0112_1 0:ea35c18c85fc 108
lilac0112_1 10:6df631c39f9b 109 #define PID_OUT_MIN 5
lilac0112_1 10:6df631c39f9b 110
lilac0112_1 10:6df631c39f9b 111 //hmc
lilac0112_1 10:6df631c39f9b 112 #define HMC_RUN 1
lilac0112_1 10:6df631c39f9b 113 #define HMC_RST 0
lilac0112_1 10:6df631c39f9b 114
lilac0112_1 0:ea35c18c85fc 115 //ir
lilac0112_1 5:5ff3a7d5d8c2 116 //ir_pow_old
lilac0112_1 0:ea35c18c85fc 117 #define IR_X 0
lilac0112_1 0:ea35c18c85fc 118 #define IR_Y 1
lilac0112_1 5:5ff3a7d5d8c2 119 //ir_pow
lilac0112_1 5:5ff3a7d5d8c2 120 #define IR_X_DIR 0
lilac0112_1 5:5ff3a7d5d8c2 121 #define IR_Y_DIR 1
lilac0112_1 5:5ff3a7d5d8c2 122 #define IR_X_TURN 2
lilac0112_1 5:5ff3a7d5d8c2 123 #define IR_Y_TURN 3
lilac0112_1 5:5ff3a7d5d8c2 124
lilac0112_1 0:ea35c18c85fc 125 #define IR_SHORT 0
lilac0112_1 0:ea35c18c85fc 126 #define IR_LONG 1
lilac0112_1 0:ea35c18c85fc 127
lilac0112_1 0:ea35c18c85fc 128 #define X_AXIS 0
lilac0112_1 0:ea35c18c85fc 129 #define Y_AXIS 1
lilac0112_1 0:ea35c18c85fc 130
lilac0112_1 1:3e013ae7900d 131
lilac0112_1 1:3e013ae7900d 132 #define DIS_0 0x0//low_value
lilac0112_1 1:3e013ae7900d 133 #define DIS_1 0x1
lilac0112_1 1:3e013ae7900d 134 #define DIS_2 0x2
lilac0112_1 1:3e013ae7900d 135 #define DIS_3 0x3
lilac0112_1 1:3e013ae7900d 136 #define DIS_4 0x4
lilac0112_1 1:3e013ae7900d 137 #define DIS_5 0x5
lilac0112_1 1:3e013ae7900d 138 #define DIS_6 0x6
lilac0112_1 1:3e013ae7900d 139 #define DIS_7 0x7//high_value
lilac0112_1 1:3e013ae7900d 140
lilac0112_1 0:ea35c18c85fc 141 //ping
lilac0112_1 10:6df631c39f9b 142 #define L_PING 1
lilac0112_1 10:6df631c39f9b 143 #define R_PING 0
lilac0112_1 0:ea35c18c85fc 144 #define F_PING 2
lilac0112_1 0:ea35c18c85fc 145 #define B_PING 3
lilac0112_1 0:ea35c18c85fc 146
lilac0112_1 0:ea35c18c85fc 147 //0,1...main
lilac0112_1 0:ea35c18c85fc 148 //2,3...debug board
lilac0112_1 0:ea35c18c85fc 149
lilac0112_1 0:ea35c18c85fc 150 //line
lilac0112_1 0:ea35c18c85fc 151 #define A_SPOT 0
lilac0112_1 0:ea35c18c85fc 152 #define B_SPOT 1
lilac0112_1 0:ea35c18c85fc 153 #define C_SPOT 2
lilac0112_1 0:ea35c18c85fc 154 #define AB_SPOT 3
lilac0112_1 0:ea35c18c85fc 155
lilac0112_1 0:ea35c18c85fc 156 #define LINE_RF 5
lilac0112_1 0:ea35c18c85fc 157 #define LINE_DELAY 0.5
lilac0112_1 0:ea35c18c85fc 158
lilac0112_1 0:ea35c18c85fc 159 //思考パターン
lilac0112_1 0:ea35c18c85fc 160 #define STRATEGY_NUM 12
lilac0112_1 0:ea35c18c85fc 161
lilac0112_1 0:ea35c18c85fc 162 //計算
lilac0112_1 0:ea35c18c85fc 163 #define ROUND(x) ((x > 0) ? (x + 0.5) : (x - 0.5))//x...整数
lilac0112_1 0:ea35c18c85fc 164 #define PI 3.14159265358979323846
lilac0112_1 0:ea35c18c85fc 165 #define DEG2RAD(deg) (PI*(deg)/180.0)
lilac0112_1 0:ea35c18c85fc 166 #define RAD2DEG(rad) (180.0(rad)/PI)
lilac0112_1 0:ea35c18c85fc 167
lilac0112_1 0:ea35c18c85fc 168 //データ
lilac0112_1 1:3e013ae7900d 169 /*
lilac0112_1 0:ea35c18c85fc 170 typedef struct {//ir,line,gyro,mouse,ping
lilac0112_1 0:ea35c18c85fc 171 //ping
lilac0112_1 0:ea35c18c85fc 172 uint8_t ping[4];
lilac0112_1 0:ea35c18c85fc 173 //ir
lilac0112_1 0:ea35c18c85fc 174 uint8_t irKey;
lilac0112_1 0:ea35c18c85fc 175 uint8_t irNotice;
lilac0112_1 0:ea35c18c85fc 176 uint8_t irSpot[2];
lilac0112_1 0:ea35c18c85fc 177 uint8_t irPosition;
lilac0112_1 0:ea35c18c85fc 178 uint8_t IrFlag;
lilac0112_1 0:ea35c18c85fc 179 //line
lilac0112_1 0:ea35c18c85fc 180 uint8_t lnFlag[3];
lilac0112_1 0:ea35c18c85fc 181 uint8_t ball;
lilac0112_1 0:ea35c18c85fc 182 uint8_t KickOffFlag;
lilac0112_1 0:ea35c18c85fc 183 //uint8_t LineBind[4];//宣言すると動かない⇒構造体の限界
lilac0112_1 0:ea35c18c85fc 184 uint8_t KickFlag;
lilac0112_1 0:ea35c18c85fc 185 //motor
lilac0112_1 0:ea35c18c85fc 186 int32_t motorlog[2];
lilac0112_1 0:ea35c18c85fc 187 uint8_t MotorFlag;
lilac0112_1 0:ea35c18c85fc 188 double s_pow;
lilac0112_1 0:ea35c18c85fc 189 double l_pow;
lilac0112_1 0:ea35c18c85fc 190 //cmps&pid
lilac0112_1 0:ea35c18c85fc 191 uint8_t PidFlag;
lilac0112_1 0:ea35c18c85fc 192 double cmps, CmpsInitialValue, CmpsDiff, FrontDeg;//0<x<360
lilac0112_1 0:ea35c18c85fc 193 double InputPID;//<<gyrosensor
lilac0112_1 0:ea35c18c85fc 194 int16_t OutputPID;//>>motor
lilac0112_1 0:ea35c18c85fc 195 uint8_t strategy;
lilac0112_1 0:ea35c18c85fc 196 uint8_t init_point_flag;
lilac0112_1 0:ea35c18c85fc 197 uint8_t stopflag;
lilac0112_1 0:ea35c18c85fc 198 } Record;
lilac0112_1 1:3e013ae7900d 199 */
lilac0112_1 0:ea35c18c85fc 200 //NewStruct
lilac0112_1 0:ea35c18c85fc 201 typedef struct {
lilac0112_1 0:ea35c18c85fc 202 //cmps&pid
lilac0112_1 0:ea35c18c85fc 203 double cmps, CmpsInitialValue, CmpsDiff, FrontDeg;//0<x<360
lilac0112_1 0:ea35c18c85fc 204 double InputPID;//<<gyrosensor
lilac0112_1 0:ea35c18c85fc 205 int16_t OutputPID;//>>motor
lilac0112_1 0:ea35c18c85fc 206 } CompassVal;
lilac0112_1 0:ea35c18c85fc 207 typedef struct {
lilac0112_1 0:ea35c18c85fc 208 //ping
lilac0112_1 0:ea35c18c85fc 209 uint8_t ping[4];
lilac0112_1 0:ea35c18c85fc 210 //line
lilac0112_1 0:ea35c18c85fc 211 uint8_t lineSpot[3];
lilac0112_1 2:635947de1583 212 uint8_t lnFlag[3];
lilac0112_1 2:635947de1583 213 /*uint8_t LineFlag[3];
lilac0112_1 2:635947de1583 214 uint8_t LinePriority[3];
lilac0112_1 2:635947de1583 215 uint8_t LineBind[3];*/
lilac0112_1 0:ea35c18c85fc 216 //ir(spi)
lilac0112_1 0:ea35c18c85fc 217 uint8_t irKey;//2bit
lilac0112_1 1:3e013ae7900d 218 uint8_t irValPhase[2];//3*2bit
lilac0112_1 2:635947de1583 219 uint8_t irDif[2];//3bit
lilac0112_1 2:635947de1583 220 uint8_t irPosition;//5bit
lilac0112_1 2:635947de1583 221
lilac0112_1 2:635947de1583 222 uint8_t irSpot[2];//4*2bit//old
lilac0112_1 0:ea35c18c85fc 223 //ir(playing)
lilac0112_1 0:ea35c18c85fc 224 uint8_t irNotice;
lilac0112_1 0:ea35c18c85fc 225 //ball
lilac0112_1 0:ea35c18c85fc 226 uint8_t ball;
lilac0112_1 0:ea35c18c85fc 227 } SensorVal;
lilac0112_1 0:ea35c18c85fc 228 typedef struct {
lilac0112_1 0:ea35c18c85fc 229 //system,flag
lilac0112_1 0:ea35c18c85fc 230 uint8_t strategy;
lilac0112_1 4:52da8da146d4 231 uint16_t jump_flag;//0<=x<=JUMP_TAG_NUM
lilac0112_1 0:ea35c18c85fc 232 uint8_t stopflag;
lilac0112_1 0:ea35c18c85fc 233 uint8_t KickOffFlag;
lilac0112_1 0:ea35c18c85fc 234 uint8_t DribbleFlag;
lilac0112_1 10:6df631c39f9b 235 uint8_t BallHoldFlag;
lilac0112_1 8:25c8c75d182a 236 uint8_t BackHomeFlag;
lilac0112_1 10:6df631c39f9b 237 uint8_t TurnStartFlag;
lilac0112_1 0:ea35c18c85fc 238 uint8_t KickFlag;
lilac0112_1 0:ea35c18c85fc 239 uint8_t MotorFlag;
lilac0112_1 0:ea35c18c85fc 240 uint8_t IrFlag;
lilac0112_1 0:ea35c18c85fc 241 uint8_t UswFlag;
lilac0112_1 10:6df631c39f9b 242 uint8_t UswFlag2;
lilac0112_1 0:ea35c18c85fc 243 uint8_t PidFlag;
lilac0112_1 8:25c8c75d182a 244 //blind//on...1/off...0
lilac0112_1 8:25c8c75d182a 245 uint8_t IrBlind;
lilac0112_1 8:25c8c75d182a 246 uint8_t LineBlind;
lilac0112_1 8:25c8c75d182a 247 uint8_t PingBlind;
lilac0112_1 0:ea35c18c85fc 248 //motor
lilac0112_1 7:efe90188a49d 249 uint8_t pow_num;
lilac0112_1 6:f9167470d819 250 uint8_t s_pow;
lilac0112_1 6:f9167470d819 251 uint8_t m_pow;
lilac0112_1 6:f9167470d819 252 uint8_t l_pow;
lilac0112_1 6:f9167470d819 253 uint8_t dri_pow;
lilac0112_1 2:635947de1583 254 uint8_t ir_pow_table;
lilac0112_1 0:ea35c18c85fc 255 } SystemVal;
lilac0112_1 2:635947de1583 256
lilac0112_1 0:ea35c18c85fc 257 #endif