ジャパンオープン用のメインプログラム
Dependencies: mbed AQM1602 HMC6352 PID
setting/def.h@3:c49ea7ad8e91, 2016-03-03 (annotated)
- Committer:
- lilac0112_1
- Date:
- Thu Mar 03 11:47:49 2016 +0000
- Revision:
- 3:c49ea7ad8e91
- Parent:
- 2:635947de1583
- Child:
- 4:52da8da146d4
somehow
Who changed what in which revision?
User | Revision | Line number | New 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 | 3:c49ea7ad8e91 | 20 | #define BUFSIZE 7 |
lilac0112_1 | 0:ea35c18c85fc | 21 | #define STATE_NUM_X 0x04 |
lilac0112_1 | 0:ea35c18c85fc | 22 | #define STATE_NUM_Y 0x10 |
lilac0112_1 | 3:c49ea7ad8e91 | 23 | |
lilac0112_1 | 3:c49ea7ad8e91 | 24 | typedef struct {//for command |
lilac0112_1 | 3:c49ea7ad8e91 | 25 | char LcdStr[STATE_NUM_X][BUFSIZE]; |
lilac0112_1 | 3:c49ea7ad8e91 | 26 | uint8_t str_num; |
lilac0112_1 | 3:c49ea7ad8e91 | 27 | uint8_t (*CommandFunction)(uint8_t x); |
lilac0112_1 | 3:c49ea7ad8e91 | 28 | } CommandItem; |
lilac0112_1 | 3:c49ea7ad8e91 | 29 | |
lilac0112_1 | 0:ea35c18c85fc | 30 | //繰り返し割り込み |
lilac0112_1 | 0:ea35c18c85fc | 31 | #define DUTY_NUM 1 |
lilac0112_1 | 0:ea35c18c85fc | 32 | |
lilac0112_1 | 0:ea35c18c85fc | 33 | #define DUTY_SW 0 |
lilac0112_1 | 0:ea35c18c85fc | 34 | #define DUTY_GYRO 1 |
lilac0112_1 | 0:ea35c18c85fc | 35 | #define DUTY_PING 2 |
lilac0112_1 | 0:ea35c18c85fc | 36 | #define DUTY_COLOR 3 |
lilac0112_1 | 0:ea35c18c85fc | 37 | #define DUTY_MOUSE 4 |
lilac0112_1 | 0:ea35c18c85fc | 38 | |
lilac0112_1 | 0:ea35c18c85fc | 39 | /*PID処理*/ |
lilac0112_1 | 0:ea35c18c85fc | 40 | #define RATE 0.052//52 |
lilac0112_1 | 0:ea35c18c85fc | 41 | #define PID_BIAS 1.0 |
lilac0112_1 | 0:ea35c18c85fc | 42 | #define REFERENCE 180.0 |
lilac0112_1 | 0:ea35c18c85fc | 43 | #define MINIMUM 0.0 |
lilac0112_1 | 0:ea35c18c85fc | 44 | #define MAXIMUM 359.9 |
lilac0112_1 | 0:ea35c18c85fc | 45 | #define P_GAIN 1.3//1.25//0.8 //0.78 |
lilac0112_1 | 0:ea35c18c85fc | 46 | #define I_GAIN 0.0 //0.0 |
lilac0112_1 | 0:ea35c18c85fc | 47 | #define D_GAIN 0.01//0.01 //0.009 |
lilac0112_1 | 0:ea35c18c85fc | 48 | #define OUT_LIMIT 30.0 |
lilac0112_1 | 0:ea35c18c85fc | 49 | #define MAX_POW 100 |
lilac0112_1 | 0:ea35c18c85fc | 50 | #define MIN_POW -100 |
lilac0112_1 | 0:ea35c18c85fc | 51 | #define PID_CYCLE 0.05 //s |
lilac0112_1 | 0:ea35c18c85fc | 52 | |
lilac0112_1 | 0:ea35c18c85fc | 53 | //ir |
lilac0112_1 | 0:ea35c18c85fc | 54 | #define IR_X 0 |
lilac0112_1 | 0:ea35c18c85fc | 55 | #define IR_Y 1 |
lilac0112_1 | 0:ea35c18c85fc | 56 | #define IR_SHORT 0 |
lilac0112_1 | 0:ea35c18c85fc | 57 | #define IR_LONG 1 |
lilac0112_1 | 0:ea35c18c85fc | 58 | |
lilac0112_1 | 0:ea35c18c85fc | 59 | #define X_AXIS 0 |
lilac0112_1 | 0:ea35c18c85fc | 60 | #define Y_AXIS 1 |
lilac0112_1 | 0:ea35c18c85fc | 61 | |
lilac0112_1 | 1:3e013ae7900d | 62 | |
lilac0112_1 | 1:3e013ae7900d | 63 | #define DIS_0 0x0//low_value |
lilac0112_1 | 1:3e013ae7900d | 64 | #define DIS_1 0x1 |
lilac0112_1 | 1:3e013ae7900d | 65 | #define DIS_2 0x2 |
lilac0112_1 | 1:3e013ae7900d | 66 | #define DIS_3 0x3 |
lilac0112_1 | 1:3e013ae7900d | 67 | #define DIS_4 0x4 |
lilac0112_1 | 1:3e013ae7900d | 68 | #define DIS_5 0x5 |
lilac0112_1 | 1:3e013ae7900d | 69 | #define DIS_6 0x6 |
lilac0112_1 | 1:3e013ae7900d | 70 | #define DIS_7 0x7//high_value |
lilac0112_1 | 1:3e013ae7900d | 71 | |
lilac0112_1 | 0:ea35c18c85fc | 72 | //ping |
lilac0112_1 | 0:ea35c18c85fc | 73 | #define L_PING 0 |
lilac0112_1 | 0:ea35c18c85fc | 74 | #define R_PING 1 |
lilac0112_1 | 0:ea35c18c85fc | 75 | #define F_PING 2 |
lilac0112_1 | 0:ea35c18c85fc | 76 | #define B_PING 3 |
lilac0112_1 | 0:ea35c18c85fc | 77 | |
lilac0112_1 | 0:ea35c18c85fc | 78 | //0,1...main |
lilac0112_1 | 0:ea35c18c85fc | 79 | //2,3...debug board |
lilac0112_1 | 0:ea35c18c85fc | 80 | |
lilac0112_1 | 0:ea35c18c85fc | 81 | //line |
lilac0112_1 | 0:ea35c18c85fc | 82 | #define A_SPOT 0 |
lilac0112_1 | 0:ea35c18c85fc | 83 | #define B_SPOT 1 |
lilac0112_1 | 0:ea35c18c85fc | 84 | #define C_SPOT 2 |
lilac0112_1 | 0:ea35c18c85fc | 85 | #define AB_SPOT 3 |
lilac0112_1 | 0:ea35c18c85fc | 86 | |
lilac0112_1 | 0:ea35c18c85fc | 87 | #define LINE_RF 5 |
lilac0112_1 | 0:ea35c18c85fc | 88 | #define LINE_DELAY 0.5 |
lilac0112_1 | 0:ea35c18c85fc | 89 | |
lilac0112_1 | 0:ea35c18c85fc | 90 | //思考パターン |
lilac0112_1 | 0:ea35c18c85fc | 91 | #define STRATEGY_NUM 12 |
lilac0112_1 | 0:ea35c18c85fc | 92 | |
lilac0112_1 | 0:ea35c18c85fc | 93 | //計算 |
lilac0112_1 | 0:ea35c18c85fc | 94 | #define ROUND(x) ((x > 0) ? (x + 0.5) : (x - 0.5))//x...整数 |
lilac0112_1 | 0:ea35c18c85fc | 95 | #define PI 3.14159265358979323846 |
lilac0112_1 | 0:ea35c18c85fc | 96 | #define DEG2RAD(deg) (PI*(deg)/180.0) |
lilac0112_1 | 0:ea35c18c85fc | 97 | #define RAD2DEG(rad) (180.0(rad)/PI) |
lilac0112_1 | 0:ea35c18c85fc | 98 | |
lilac0112_1 | 0:ea35c18c85fc | 99 | //データ |
lilac0112_1 | 1:3e013ae7900d | 100 | /* |
lilac0112_1 | 0:ea35c18c85fc | 101 | typedef struct {//ir,line,gyro,mouse,ping |
lilac0112_1 | 0:ea35c18c85fc | 102 | //ping |
lilac0112_1 | 0:ea35c18c85fc | 103 | uint8_t ping[4]; |
lilac0112_1 | 0:ea35c18c85fc | 104 | //ir |
lilac0112_1 | 0:ea35c18c85fc | 105 | uint8_t irKey; |
lilac0112_1 | 0:ea35c18c85fc | 106 | uint8_t irNotice; |
lilac0112_1 | 0:ea35c18c85fc | 107 | uint8_t irSpot[2]; |
lilac0112_1 | 0:ea35c18c85fc | 108 | uint8_t irPosition; |
lilac0112_1 | 0:ea35c18c85fc | 109 | uint8_t IrFlag; |
lilac0112_1 | 0:ea35c18c85fc | 110 | //line |
lilac0112_1 | 0:ea35c18c85fc | 111 | uint8_t lnFlag[3]; |
lilac0112_1 | 0:ea35c18c85fc | 112 | uint8_t ball; |
lilac0112_1 | 0:ea35c18c85fc | 113 | uint8_t KickOffFlag; |
lilac0112_1 | 0:ea35c18c85fc | 114 | //uint8_t LineBind[4];//宣言すると動かない⇒構造体の限界 |
lilac0112_1 | 0:ea35c18c85fc | 115 | uint8_t KickFlag; |
lilac0112_1 | 0:ea35c18c85fc | 116 | //motor |
lilac0112_1 | 0:ea35c18c85fc | 117 | int32_t motorlog[2]; |
lilac0112_1 | 0:ea35c18c85fc | 118 | uint8_t MotorFlag; |
lilac0112_1 | 0:ea35c18c85fc | 119 | double s_pow; |
lilac0112_1 | 0:ea35c18c85fc | 120 | double l_pow; |
lilac0112_1 | 0:ea35c18c85fc | 121 | //cmps&pid |
lilac0112_1 | 0:ea35c18c85fc | 122 | uint8_t PidFlag; |
lilac0112_1 | 0:ea35c18c85fc | 123 | double cmps, CmpsInitialValue, CmpsDiff, FrontDeg;//0<x<360 |
lilac0112_1 | 0:ea35c18c85fc | 124 | double InputPID;//<<gyrosensor |
lilac0112_1 | 0:ea35c18c85fc | 125 | int16_t OutputPID;//>>motor |
lilac0112_1 | 0:ea35c18c85fc | 126 | uint8_t strategy; |
lilac0112_1 | 0:ea35c18c85fc | 127 | uint8_t init_point_flag; |
lilac0112_1 | 0:ea35c18c85fc | 128 | uint8_t stopflag; |
lilac0112_1 | 0:ea35c18c85fc | 129 | } Record; |
lilac0112_1 | 1:3e013ae7900d | 130 | */ |
lilac0112_1 | 0:ea35c18c85fc | 131 | //NewStruct |
lilac0112_1 | 0:ea35c18c85fc | 132 | typedef struct { |
lilac0112_1 | 0:ea35c18c85fc | 133 | //cmps&pid |
lilac0112_1 | 0:ea35c18c85fc | 134 | double cmps, CmpsInitialValue, CmpsDiff, FrontDeg;//0<x<360 |
lilac0112_1 | 0:ea35c18c85fc | 135 | double InputPID;//<<gyrosensor |
lilac0112_1 | 0:ea35c18c85fc | 136 | int16_t OutputPID;//>>motor |
lilac0112_1 | 0:ea35c18c85fc | 137 | } CompassVal; |
lilac0112_1 | 0:ea35c18c85fc | 138 | typedef struct { |
lilac0112_1 | 0:ea35c18c85fc | 139 | //ping |
lilac0112_1 | 0:ea35c18c85fc | 140 | uint8_t ping[4]; |
lilac0112_1 | 0:ea35c18c85fc | 141 | //line |
lilac0112_1 | 0:ea35c18c85fc | 142 | uint8_t lineSpot[3]; |
lilac0112_1 | 2:635947de1583 | 143 | uint8_t lnFlag[3]; |
lilac0112_1 | 2:635947de1583 | 144 | /*uint8_t LineFlag[3]; |
lilac0112_1 | 2:635947de1583 | 145 | uint8_t LinePriority[3]; |
lilac0112_1 | 2:635947de1583 | 146 | uint8_t LineBind[3];*/ |
lilac0112_1 | 0:ea35c18c85fc | 147 | //ir(spi) |
lilac0112_1 | 0:ea35c18c85fc | 148 | uint8_t irKey;//2bit |
lilac0112_1 | 1:3e013ae7900d | 149 | uint8_t irValPhase[2];//3*2bit |
lilac0112_1 | 2:635947de1583 | 150 | uint8_t irDif[2];//3bit |
lilac0112_1 | 2:635947de1583 | 151 | uint8_t irPosition;//5bit |
lilac0112_1 | 2:635947de1583 | 152 | |
lilac0112_1 | 2:635947de1583 | 153 | uint8_t irSpot[2];//4*2bit//old |
lilac0112_1 | 0:ea35c18c85fc | 154 | //ir(playing) |
lilac0112_1 | 0:ea35c18c85fc | 155 | uint8_t irNotice; |
lilac0112_1 | 0:ea35c18c85fc | 156 | //ball |
lilac0112_1 | 0:ea35c18c85fc | 157 | uint8_t ball; |
lilac0112_1 | 0:ea35c18c85fc | 158 | } SensorVal; |
lilac0112_1 | 0:ea35c18c85fc | 159 | typedef struct { |
lilac0112_1 | 0:ea35c18c85fc | 160 | //system,flag |
lilac0112_1 | 0:ea35c18c85fc | 161 | uint8_t strategy; |
lilac0112_1 | 0:ea35c18c85fc | 162 | uint8_t jump_flag;//0<=x<=STATE_NUM_Y |
lilac0112_1 | 0:ea35c18c85fc | 163 | uint8_t stopflag; |
lilac0112_1 | 0:ea35c18c85fc | 164 | uint8_t KickOffFlag; |
lilac0112_1 | 0:ea35c18c85fc | 165 | uint8_t DribbleFlag; |
lilac0112_1 | 0:ea35c18c85fc | 166 | uint8_t KickFlag; |
lilac0112_1 | 0:ea35c18c85fc | 167 | uint8_t MotorFlag; |
lilac0112_1 | 0:ea35c18c85fc | 168 | uint8_t IrFlag; |
lilac0112_1 | 0:ea35c18c85fc | 169 | uint8_t UswFlag; |
lilac0112_1 | 0:ea35c18c85fc | 170 | uint8_t UswFlag_2; |
lilac0112_1 | 0:ea35c18c85fc | 171 | uint8_t PidFlag; |
lilac0112_1 | 0:ea35c18c85fc | 172 | //motor |
lilac0112_1 | 0:ea35c18c85fc | 173 | double s_pow; |
lilac0112_1 | 0:ea35c18c85fc | 174 | double l_pow; |
lilac0112_1 | 0:ea35c18c85fc | 175 | int8_t dri_pow; |
lilac0112_1 | 2:635947de1583 | 176 | uint8_t ir_pow_table; |
lilac0112_1 | 0:ea35c18c85fc | 177 | } SystemVal; |
lilac0112_1 | 2:635947de1583 | 178 | |
lilac0112_1 | 0:ea35c18c85fc | 179 | #endif |