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

Dependencies:   mbed AQM1602 HMC6352 PID

Committer:
lilac0112_1
Date:
Sun Mar 06 15:06:28 2016 +0000
Revision:
7:efe90188a49d
Parent:
6:f9167470d819
Child:
8:25c8c75d182a
active setting

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 0:ea35c18c85fc 22 #define STATE_NUM_X 0x04
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 4:52da8da146d4 27 #define ZERO_FUNCTION 0x0000
lilac0112_1 4:52da8da146d4 28 #define START 0x0001
lilac0112_1 4:52da8da146d4 29 #define GET_IR 0x0002
lilac0112_1 4:52da8da146d4 30 #define GET_LINE 0x0003
lilac0112_1 4:52da8da146d4 31 #define GET_PID_VALUE 0x0004
lilac0112_1 4:52da8da146d4 32 #define CALIBRATION_ENTER 0x0005
lilac0112_1 4:52da8da146d4 33 #define CALIBRATION_EXIT 0x0006
lilac0112_1 4:52da8da146d4 34 #define FRONT_RESET 0x0007
lilac0112_1 4:52da8da146d4 35 #define SET_POWER1 0x0008
lilac0112_1 4:52da8da146d4 36 #define SET_POWER2 0x0009
lilac0112_1 4:52da8da146d4 37 #define SOFT_RESET 0x000A
lilac0112_1 4:52da8da146d4 38 #define SET_STRATEGY1 0x000B
lilac0112_1 4:52da8da146d4 39 #define SET_STRATEGY2 0x000C
lilac0112_1 4:52da8da146d4 40 #define SET_STRATEGY3 0x000D
lilac0112_1 4:52da8da146d4 41 #define SET_STRATEGY4 0x000E
lilac0112_1 4:52da8da146d4 42 #define START2 0x000F
lilac0112_1 7:efe90188a49d 43 #define SET_POWER_DOWN 0x0010
lilac0112_1 7:efe90188a49d 44 #define SET_POWER_UP 0x0011
lilac0112_1 4:52da8da146d4 45
lilac0112_1 3:c49ea7ad8e91 46 typedef struct {//for command
lilac0112_1 3:c49ea7ad8e91 47 char LcdStr[STATE_NUM_X][BUFSIZE];
lilac0112_1 3:c49ea7ad8e91 48 uint8_t str_num;
lilac0112_1 3:c49ea7ad8e91 49 uint8_t (*CommandFunction)(uint8_t x);
lilac0112_1 4:52da8da146d4 50 uint16_t tag_num;
lilac0112_1 3:c49ea7ad8e91 51 } CommandItem;
lilac0112_1 3:c49ea7ad8e91 52
lilac0112_1 7:efe90188a49d 53
lilac0112_1 7:efe90188a49d 54 //tag
lilac0112_1 7:efe90188a49d 55 #define MODE_ATTACK0 0
lilac0112_1 7:efe90188a49d 56 #define MODE_ATTACK1 1
lilac0112_1 7:efe90188a49d 57 #define MODE_ATTACK2 2
lilac0112_1 7:efe90188a49d 58 #define MODE_ATTACK3 3
lilac0112_1 7:efe90188a49d 59 #define MODE_ATTACK4 4
lilac0112_1 7:efe90188a49d 60 #define MODE_ATTACK5 5
lilac0112_1 7:efe90188a49d 61
lilac0112_1 7:efe90188a49d 62 #define MODE_DEBUG0 6
lilac0112_1 7:efe90188a49d 63 #define MODE_DEBUG1 7
lilac0112_1 7:efe90188a49d 64 #define MODE_DEBUG2 8
lilac0112_1 7:efe90188a49d 65 #define MODE_DEBUG3 9
lilac0112_1 7:efe90188a49d 66 #define MODE_DEBUG4 10
lilac0112_1 7:efe90188a49d 67 #define MODE_DEBUG5 11
lilac0112_1 7:efe90188a49d 68
lilac0112_1 7:efe90188a49d 69 typedef struct {//for active
lilac0112_1 7:efe90188a49d 70 char LcdStr[LCD_COLUMN_NUM];
lilac0112_1 7:efe90188a49d 71 void (*ActiveFunction)(void);
lilac0112_1 7:efe90188a49d 72 uint16_t tag_num;
lilac0112_1 7:efe90188a49d 73 } ActiveItem;
lilac0112_1 7:efe90188a49d 74
lilac0112_1 0:ea35c18c85fc 75 //繰り返し割り込み
lilac0112_1 0:ea35c18c85fc 76 #define DUTY_NUM 1
lilac0112_1 0:ea35c18c85fc 77
lilac0112_1 0:ea35c18c85fc 78 #define DUTY_SW 0
lilac0112_1 0:ea35c18c85fc 79 #define DUTY_GYRO 1
lilac0112_1 0:ea35c18c85fc 80 #define DUTY_PING 2
lilac0112_1 0:ea35c18c85fc 81 #define DUTY_COLOR 3
lilac0112_1 0:ea35c18c85fc 82 #define DUTY_MOUSE 4
lilac0112_1 0:ea35c18c85fc 83
lilac0112_1 0:ea35c18c85fc 84 /*PID処理*/
lilac0112_1 0:ea35c18c85fc 85 #define RATE 0.052//52
lilac0112_1 0:ea35c18c85fc 86 #define PID_BIAS 1.0
lilac0112_1 0:ea35c18c85fc 87 #define REFERENCE 180.0
lilac0112_1 0:ea35c18c85fc 88 #define MINIMUM 0.0
lilac0112_1 0:ea35c18c85fc 89 #define MAXIMUM 359.9
lilac0112_1 0:ea35c18c85fc 90 #define P_GAIN 1.3//1.25//0.8 //0.78
lilac0112_1 0:ea35c18c85fc 91 #define I_GAIN 0.0 //0.0
lilac0112_1 0:ea35c18c85fc 92 #define D_GAIN 0.01//0.01 //0.009
lilac0112_1 0:ea35c18c85fc 93 #define OUT_LIMIT 30.0
lilac0112_1 0:ea35c18c85fc 94 #define MAX_POW 100
lilac0112_1 0:ea35c18c85fc 95 #define MIN_POW -100
lilac0112_1 0:ea35c18c85fc 96 #define PID_CYCLE 0.05 //s
lilac0112_1 0:ea35c18c85fc 97
lilac0112_1 0:ea35c18c85fc 98 //ir
lilac0112_1 5:5ff3a7d5d8c2 99 //ir_pow_old
lilac0112_1 0:ea35c18c85fc 100 #define IR_X 0
lilac0112_1 0:ea35c18c85fc 101 #define IR_Y 1
lilac0112_1 5:5ff3a7d5d8c2 102 //ir_pow
lilac0112_1 5:5ff3a7d5d8c2 103 #define IR_X_DIR 0
lilac0112_1 5:5ff3a7d5d8c2 104 #define IR_Y_DIR 1
lilac0112_1 5:5ff3a7d5d8c2 105 #define IR_X_TURN 2
lilac0112_1 5:5ff3a7d5d8c2 106 #define IR_Y_TURN 3
lilac0112_1 5:5ff3a7d5d8c2 107
lilac0112_1 0:ea35c18c85fc 108 #define IR_SHORT 0
lilac0112_1 0:ea35c18c85fc 109 #define IR_LONG 1
lilac0112_1 0:ea35c18c85fc 110
lilac0112_1 0:ea35c18c85fc 111 #define X_AXIS 0
lilac0112_1 0:ea35c18c85fc 112 #define Y_AXIS 1
lilac0112_1 0:ea35c18c85fc 113
lilac0112_1 1:3e013ae7900d 114
lilac0112_1 1:3e013ae7900d 115 #define DIS_0 0x0//low_value
lilac0112_1 1:3e013ae7900d 116 #define DIS_1 0x1
lilac0112_1 1:3e013ae7900d 117 #define DIS_2 0x2
lilac0112_1 1:3e013ae7900d 118 #define DIS_3 0x3
lilac0112_1 1:3e013ae7900d 119 #define DIS_4 0x4
lilac0112_1 1:3e013ae7900d 120 #define DIS_5 0x5
lilac0112_1 1:3e013ae7900d 121 #define DIS_6 0x6
lilac0112_1 1:3e013ae7900d 122 #define DIS_7 0x7//high_value
lilac0112_1 1:3e013ae7900d 123
lilac0112_1 0:ea35c18c85fc 124 //ping
lilac0112_1 0:ea35c18c85fc 125 #define L_PING 0
lilac0112_1 0:ea35c18c85fc 126 #define R_PING 1
lilac0112_1 0:ea35c18c85fc 127 #define F_PING 2
lilac0112_1 0:ea35c18c85fc 128 #define B_PING 3
lilac0112_1 0:ea35c18c85fc 129
lilac0112_1 0:ea35c18c85fc 130 //0,1...main
lilac0112_1 0:ea35c18c85fc 131 //2,3...debug board
lilac0112_1 0:ea35c18c85fc 132
lilac0112_1 0:ea35c18c85fc 133 //line
lilac0112_1 0:ea35c18c85fc 134 #define A_SPOT 0
lilac0112_1 0:ea35c18c85fc 135 #define B_SPOT 1
lilac0112_1 0:ea35c18c85fc 136 #define C_SPOT 2
lilac0112_1 0:ea35c18c85fc 137 #define AB_SPOT 3
lilac0112_1 0:ea35c18c85fc 138
lilac0112_1 0:ea35c18c85fc 139 #define LINE_RF 5
lilac0112_1 0:ea35c18c85fc 140 #define LINE_DELAY 0.5
lilac0112_1 0:ea35c18c85fc 141
lilac0112_1 0:ea35c18c85fc 142 //思考パターン
lilac0112_1 0:ea35c18c85fc 143 #define STRATEGY_NUM 12
lilac0112_1 0:ea35c18c85fc 144
lilac0112_1 0:ea35c18c85fc 145 //計算
lilac0112_1 0:ea35c18c85fc 146 #define ROUND(x) ((x > 0) ? (x + 0.5) : (x - 0.5))//x...整数
lilac0112_1 0:ea35c18c85fc 147 #define PI 3.14159265358979323846
lilac0112_1 0:ea35c18c85fc 148 #define DEG2RAD(deg) (PI*(deg)/180.0)
lilac0112_1 0:ea35c18c85fc 149 #define RAD2DEG(rad) (180.0(rad)/PI)
lilac0112_1 0:ea35c18c85fc 150
lilac0112_1 0:ea35c18c85fc 151 //データ
lilac0112_1 1:3e013ae7900d 152 /*
lilac0112_1 0:ea35c18c85fc 153 typedef struct {//ir,line,gyro,mouse,ping
lilac0112_1 0:ea35c18c85fc 154 //ping
lilac0112_1 0:ea35c18c85fc 155 uint8_t ping[4];
lilac0112_1 0:ea35c18c85fc 156 //ir
lilac0112_1 0:ea35c18c85fc 157 uint8_t irKey;
lilac0112_1 0:ea35c18c85fc 158 uint8_t irNotice;
lilac0112_1 0:ea35c18c85fc 159 uint8_t irSpot[2];
lilac0112_1 0:ea35c18c85fc 160 uint8_t irPosition;
lilac0112_1 0:ea35c18c85fc 161 uint8_t IrFlag;
lilac0112_1 0:ea35c18c85fc 162 //line
lilac0112_1 0:ea35c18c85fc 163 uint8_t lnFlag[3];
lilac0112_1 0:ea35c18c85fc 164 uint8_t ball;
lilac0112_1 0:ea35c18c85fc 165 uint8_t KickOffFlag;
lilac0112_1 0:ea35c18c85fc 166 //uint8_t LineBind[4];//宣言すると動かない⇒構造体の限界
lilac0112_1 0:ea35c18c85fc 167 uint8_t KickFlag;
lilac0112_1 0:ea35c18c85fc 168 //motor
lilac0112_1 0:ea35c18c85fc 169 int32_t motorlog[2];
lilac0112_1 0:ea35c18c85fc 170 uint8_t MotorFlag;
lilac0112_1 0:ea35c18c85fc 171 double s_pow;
lilac0112_1 0:ea35c18c85fc 172 double l_pow;
lilac0112_1 0:ea35c18c85fc 173 //cmps&pid
lilac0112_1 0:ea35c18c85fc 174 uint8_t PidFlag;
lilac0112_1 0:ea35c18c85fc 175 double cmps, CmpsInitialValue, CmpsDiff, FrontDeg;//0<x<360
lilac0112_1 0:ea35c18c85fc 176 double InputPID;//<<gyrosensor
lilac0112_1 0:ea35c18c85fc 177 int16_t OutputPID;//>>motor
lilac0112_1 0:ea35c18c85fc 178 uint8_t strategy;
lilac0112_1 0:ea35c18c85fc 179 uint8_t init_point_flag;
lilac0112_1 0:ea35c18c85fc 180 uint8_t stopflag;
lilac0112_1 0:ea35c18c85fc 181 } Record;
lilac0112_1 1:3e013ae7900d 182 */
lilac0112_1 0:ea35c18c85fc 183 //NewStruct
lilac0112_1 0:ea35c18c85fc 184 typedef struct {
lilac0112_1 0:ea35c18c85fc 185 //cmps&pid
lilac0112_1 0:ea35c18c85fc 186 double cmps, CmpsInitialValue, CmpsDiff, FrontDeg;//0<x<360
lilac0112_1 0:ea35c18c85fc 187 double InputPID;//<<gyrosensor
lilac0112_1 0:ea35c18c85fc 188 int16_t OutputPID;//>>motor
lilac0112_1 0:ea35c18c85fc 189 } CompassVal;
lilac0112_1 0:ea35c18c85fc 190 typedef struct {
lilac0112_1 0:ea35c18c85fc 191 //ping
lilac0112_1 0:ea35c18c85fc 192 uint8_t ping[4];
lilac0112_1 0:ea35c18c85fc 193 //line
lilac0112_1 0:ea35c18c85fc 194 uint8_t lineSpot[3];
lilac0112_1 2:635947de1583 195 uint8_t lnFlag[3];
lilac0112_1 2:635947de1583 196 /*uint8_t LineFlag[3];
lilac0112_1 2:635947de1583 197 uint8_t LinePriority[3];
lilac0112_1 2:635947de1583 198 uint8_t LineBind[3];*/
lilac0112_1 0:ea35c18c85fc 199 //ir(spi)
lilac0112_1 0:ea35c18c85fc 200 uint8_t irKey;//2bit
lilac0112_1 1:3e013ae7900d 201 uint8_t irValPhase[2];//3*2bit
lilac0112_1 2:635947de1583 202 uint8_t irDif[2];//3bit
lilac0112_1 2:635947de1583 203 uint8_t irPosition;//5bit
lilac0112_1 2:635947de1583 204
lilac0112_1 2:635947de1583 205 uint8_t irSpot[2];//4*2bit//old
lilac0112_1 0:ea35c18c85fc 206 //ir(playing)
lilac0112_1 0:ea35c18c85fc 207 uint8_t irNotice;
lilac0112_1 0:ea35c18c85fc 208 //ball
lilac0112_1 0:ea35c18c85fc 209 uint8_t ball;
lilac0112_1 0:ea35c18c85fc 210 } SensorVal;
lilac0112_1 0:ea35c18c85fc 211 typedef struct {
lilac0112_1 0:ea35c18c85fc 212 //system,flag
lilac0112_1 0:ea35c18c85fc 213 uint8_t strategy;
lilac0112_1 4:52da8da146d4 214 uint16_t jump_flag;//0<=x<=JUMP_TAG_NUM
lilac0112_1 0:ea35c18c85fc 215 uint8_t stopflag;
lilac0112_1 0:ea35c18c85fc 216 uint8_t KickOffFlag;
lilac0112_1 0:ea35c18c85fc 217 uint8_t DribbleFlag;
lilac0112_1 0:ea35c18c85fc 218 uint8_t KickFlag;
lilac0112_1 0:ea35c18c85fc 219 uint8_t MotorFlag;
lilac0112_1 0:ea35c18c85fc 220 uint8_t IrFlag;
lilac0112_1 0:ea35c18c85fc 221 uint8_t UswFlag;
lilac0112_1 0:ea35c18c85fc 222 uint8_t UswFlag_2;
lilac0112_1 0:ea35c18c85fc 223 uint8_t PidFlag;
lilac0112_1 0:ea35c18c85fc 224 //motor
lilac0112_1 7:efe90188a49d 225 uint8_t pow_num;
lilac0112_1 6:f9167470d819 226 uint8_t s_pow;
lilac0112_1 6:f9167470d819 227 uint8_t m_pow;
lilac0112_1 6:f9167470d819 228 uint8_t l_pow;
lilac0112_1 6:f9167470d819 229 uint8_t dri_pow;
lilac0112_1 2:635947de1583 230 uint8_t ir_pow_table;
lilac0112_1 0:ea35c18c85fc 231 } SystemVal;
lilac0112_1 2:635947de1583 232
lilac0112_1 0:ea35c18c85fc 233 #endif