teamALI / Mbed 2 deprecated HB2018

Dependencies:   mbed FreeRTOS

Committer:
MasashiNomura
Date:
Mon Jan 21 11:57:35 2019 +0000
Revision:
41:45c982b1c5b6
Parent:
40:debe99e228d3
Child:
42:cc8501b824ba
20190121 Modify for 45inc. HbMotor,HbManager,GF etc

Who changed what in which revision?

UserRevisionLine numberNew contents of line
takeru0x1103 8:1ca49cb18290 1 #ifndef __GLOBALFLAGS_H__
takeru0x1103 8:1ca49cb18290 2 #define __GLOBALFLAGS_H__
takeru0x1103 8:1ca49cb18290 3
takeru0x1103 16:05b9e44889f1 4 #include "mbed.h"
takeru0x1103 17:f9610f3cfa1b 5 #include "typedef.h"
takeru0x1103 17:f9610f3cfa1b 6
takeru0x1103 19:4b0fe9a5ec38 7 #define G_CMD_BUF_SIZ 32
takeru0x1103 19:4b0fe9a5ec38 8 #define STATE_QUE_SIZ 8
takeru0x1103 19:4b0fe9a5ec38 9
MasashiNomura 22:24c9c2dedca9 10 #define STATE_BUF_SIZ 8
MasashiNomura 22:24c9c2dedca9 11
MasashiNomura 25:f3a6e7eec9c3 12 #define LIM_MOT_INP_MIN -2000
MasashiNomura 25:f3a6e7eec9c3 13 #define LIM_MOT_INP_MAX 2000
MasashiNomura 25:f3a6e7eec9c3 14
MasashiNomura 35:3779201b4c73 15 #define MAX_VAL_12BIT 4095
MasashiNomura 36:2cc739c7e4cb 16 #define BRK_RPM 4000
MasashiNomura 35:3779201b4c73 17
MasashiNomura 39:1b76f7df8804 18 typedef struct {
MasashiNomura 39:1b76f7df8804 19 union{
MasashiNomura 40:debe99e228d3 20 UINT16 flg;
MasashiNomura 39:1b76f7df8804 21 struct{
MasashiNomura 39:1b76f7df8804 22 bool e1 : 1;//前エンジン回転数
MasashiNomura 39:1b76f7df8804 23 bool e2 : 1;//後ろエンジン回転数
MasashiNomura 39:1b76f7df8804 24 bool m1 : 1;//サブモーター回転数
MasashiNomura 39:1b76f7df8804 25 bool m2 : 1;//サブモーター回転数
MasashiNomura 39:1b76f7df8804 26 bool m3 : 1;//サブモーター回転数
MasashiNomura 39:1b76f7df8804 27 bool m4 : 1;//サブモーター回転数
MasashiNomura 39:1b76f7df8804 28 bool gy : 1;//ジャイロ
MasashiNomura 39:1b76f7df8804 29 bool yaw : 1;//ヨー角
MasashiNomura 39:1b76f7df8804 30 bool fb : 1;//PID制御feedback結果
MasashiNomura 39:1b76f7df8804 31 bool pp : 1;//P制御ゲイン(アウターループ)
MasashiNomura 39:1b76f7df8804 32 bool p : 1;//P制御ゲイン
MasashiNomura 39:1b76f7df8804 33 bool i : 1;//I制御ゲイン
MasashiNomura 39:1b76f7df8804 34 bool d : 1;//D制御ゲイン
MasashiNomura 39:1b76f7df8804 35 bool v : 1;//PID2(torgue)角速度feedback制御用ゲイン
MasashiNomura 40:debe99e228d3 36 bool stat : 1;//ステート表示
MasashiNomura 40:debe99e228d3 37 }bf;
MasashiNomura 40:debe99e228d3 38 }d1;
MasashiNomura 40:debe99e228d3 39 union{
MasashiNomura 40:debe99e228d3 40 UINT32 flg;
MasashiNomura 40:debe99e228d3 41 struct{
MasashiNomura 41:45c982b1c5b6 42 bool ain : 1;//アナログ入力値
MasashiNomura 41:45c982b1c5b6 43 bool sw : 1;//User Ope Switch
MasashiNomura 39:1b76f7df8804 44 bool mo1 : 1;//Motor1 Offset val
MasashiNomura 39:1b76f7df8804 45 bool mo2 : 1;//Motor2 Offset val
MasashiNomura 39:1b76f7df8804 46 bool mo3 : 1;//Motor3 Offset val
MasashiNomura 39:1b76f7df8804 47 bool mo4 : 1;//Motor4 Offset val
MasashiNomura 40:debe99e228d3 48 bool rsv_01 : 1;
MasashiNomura 40:debe99e228d3 49 bool rsv_02 : 1;
MasashiNomura 40:debe99e228d3 50 bool rsv_03 : 1;
MasashiNomura 40:debe99e228d3 51 bool rsv_04 : 1;
MasashiNomura 40:debe99e228d3 52 bool rsv_05 : 1;
MasashiNomura 40:debe99e228d3 53 bool rsv_06 : 1;
MasashiNomura 40:debe99e228d3 54 bool rsv_07 : 1;
MasashiNomura 40:debe99e228d3 55 bool rsv_08 : 1;
MasashiNomura 40:debe99e228d3 56 bool rsv_09 : 1;
MasashiNomura 40:debe99e228d3 57 bool rsv_10 : 1;
MasashiNomura 39:1b76f7df8804 58 }bf;
MasashiNomura 39:1b76f7df8804 59 }d2;
MasashiNomura 39:1b76f7df8804 60 }typPrintFlg;
MasashiNomura 39:1b76f7df8804 61
MasashiNomura 41:45c982b1c5b6 62 // typedef union{
MasashiNomura 41:45c982b1c5b6 63 // UINT16 flg;
MasashiNomura 41:45c982b1c5b6 64 // struct{
MasashiNomura 41:45c982b1c5b6 65 // bool e1 : 1;//前エンジン回転数
MasashiNomura 41:45c982b1c5b6 66 // bool e2 : 1;//後ろエンジン回転数
MasashiNomura 41:45c982b1c5b6 67 // bool m1 : 1;//サブモーター回転数
MasashiNomura 41:45c982b1c5b6 68 // bool m2 : 1;//サブモーター回転数
MasashiNomura 41:45c982b1c5b6 69 // bool m3 : 1;//サブモーター回転数
MasashiNomura 41:45c982b1c5b6 70 // bool m4 : 1;//サブモーター回転数
MasashiNomura 41:45c982b1c5b6 71 // bool gy : 1;//ジャイロ
MasashiNomura 41:45c982b1c5b6 72 // bool yaw : 1;//ヨー角
MasashiNomura 41:45c982b1c5b6 73 // bool fb : 1;//PID制御feedback結果
MasashiNomura 41:45c982b1c5b6 74 // bool pp : 1;//P制御ゲイン(アウターループ)
MasashiNomura 41:45c982b1c5b6 75 // bool p : 1;//P制御ゲイン
MasashiNomura 41:45c982b1c5b6 76 // bool i : 1;//I制御ゲイン
MasashiNomura 41:45c982b1c5b6 77 // bool d : 1;//D制御ゲイン
MasashiNomura 41:45c982b1c5b6 78 // bool v : 1;//PID2(torgue)角速度feedback制御用ゲイン
MasashiNomura 41:45c982b1c5b6 79 // bool stat : 1;//ステート表示
MasashiNomura 41:45c982b1c5b6 80 // bool ain : 1;//アナログ入力値
MasashiNomura 41:45c982b1c5b6 81 // }bf;
MasashiNomura 41:45c982b1c5b6 82 // }typPrintFlag;
takeru0x1103 17:f9610f3cfa1b 83
takeru0x1103 17:f9610f3cfa1b 84 typedef union{
takeru0x1103 17:f9610f3cfa1b 85 UINT16 flg;
takeru0x1103 17:f9610f3cfa1b 86 struct{
takeru0x1103 17:f9610f3cfa1b 87 bool e1 : 1;//
takeru0x1103 17:f9610f3cfa1b 88 bool e2 : 1;//
takeru0x1103 17:f9610f3cfa1b 89 bool m1 : 1;//
takeru0x1103 17:f9610f3cfa1b 90 bool m2 : 1;//
takeru0x1103 17:f9610f3cfa1b 91 bool m3 : 1;//
takeru0x1103 17:f9610f3cfa1b 92 bool m4 : 1;//
takeru0x1103 17:f9610f3cfa1b 93 bool gy : 1;//
takeru0x1103 17:f9610f3cfa1b 94 bool yaw : 1;//
takeru0x1103 18:5aa48aec9cae 95 bool fb : 1;//PID制御feedback結果
takeru0x1103 18:5aa48aec9cae 96 bool pp : 1;//P制御ゲイン(アウターループ)
takeru0x1103 18:5aa48aec9cae 97 bool p : 1;//P制御ゲイン
takeru0x1103 18:5aa48aec9cae 98 bool i : 1;//I制御ゲイン
takeru0x1103 18:5aa48aec9cae 99 bool d : 1;//D制御ゲイン
takeru0x1103 17:f9610f3cfa1b 100 }bf;
takeru0x1103 17:f9610f3cfa1b 101 }typCalFlag;
takeru0x1103 17:f9610f3cfa1b 102
takeru0x1103 19:4b0fe9a5ec38 103 //
takeru0x1103 17:f9610f3cfa1b 104 typedef union{
takeru0x1103 17:f9610f3cfa1b 105 UINT16 dt;
takeru0x1103 17:f9610f3cfa1b 106 struct{
takeru0x1103 18:5aa48aec9cae 107 UINT16 val : 12;//アクセル設定値
takeru0x1103 17:f9610f3cfa1b 108 bool req : 1;//アクセル更新要求
takeru0x1103 17:f9610f3cfa1b 109 }bf;
takeru0x1103 17:f9610f3cfa1b 110 }typAccel;
takeru0x1103 17:f9610f3cfa1b 111
MasashiNomura 32:7f4145cc3551 112 typedef struct{
MasashiNomura 32:7f4145cc3551 113 INT16 val;//アクセル設定値
MasashiNomura 32:7f4145cc3551 114 bool req;//アクセル更新要求
MasashiNomura 29:eb3d72dd94aa 115 }typAxlRpm;
MasashiNomura 29:eb3d72dd94aa 116
MasashiNomura 32:7f4145cc3551 117
MasashiNomura 41:45c982b1c5b6 118 // typedef union{
MasashiNomura 41:45c982b1c5b6 119 // UINT16 flg;
MasashiNomura 41:45c982b1c5b6 120 // struct{
MasashiNomura 41:45c982b1c5b6 121 // bool mo1 : 1;//Motor1 Offset val
MasashiNomura 41:45c982b1c5b6 122 // bool mo2 : 1;//Motor2 Offset val
MasashiNomura 41:45c982b1c5b6 123 // bool mo3 : 1;//Motor3 Offset val
MasashiNomura 41:45c982b1c5b6 124 // bool mo4 : 1;//Motor4 Offset val
MasashiNomura 41:45c982b1c5b6 125 // bool ana1 : 1;//AnalogRead for Motor Accel
MasashiNomura 41:45c982b1c5b6 126 // bool ana2 : 1;
MasashiNomura 41:45c982b1c5b6 127 // }bf;
MasashiNomura 41:45c982b1c5b6 128 // }typDbgPrintFlg;
MasashiNomura 25:f3a6e7eec9c3 129
MasashiNomura 29:eb3d72dd94aa 130 typedef union {
MasashiNomura 29:eb3d72dd94aa 131 UINT16 dt;
MasashiNomura 29:eb3d72dd94aa 132 struct{
MasashiNomura 29:eb3d72dd94aa 133 UINT16 num :6;
MasashiNomura 29:eb3d72dd94aa 134 UINT16 counter :6;
MasashiNomura 29:eb3d72dd94aa 135 //UINT16 pos :3;
MasashiNomura 29:eb3d72dd94aa 136 bool add_end :1;
MasashiNomura 29:eb3d72dd94aa 137 bool req :1;
MasashiNomura 29:eb3d72dd94aa 138 }bf;
MasashiNomura 29:eb3d72dd94aa 139 }typOnePushFlg;
MasashiNomura 24:c5945aaae777 140
takeru0x1103 19:4b0fe9a5ec38 141 //ステート定義
takeru0x1103 19:4b0fe9a5ec38 142 enum enmHbState
MasashiNomura 22:24c9c2dedca9 143 {NONE = 0 //何もなし
takeru0x1103 21:78302ecdb661 144 ,SLEEP //スリープモード(最初ここ)
takeru0x1103 20:0394e15412c3 145 ,WAKEUP //起動処理
takeru0x1103 20:0394e15412c3 146 ,STANDBY //スタンバイ(エンジンかかるの待ち)
takeru0x1103 21:78302ecdb661 147 ,IDLE //アイドル(エンジンがかかったけどなにもしない)
MasashiNomura 35:3779201b4c73 148 ,TAKE_OFF //離陸(エンジン回転数上昇 規定値まで)
takeru0x1103 20:0394e15412c3 149 ,HOVER //ホバリング
takeru0x1103 21:78302ecdb661 150 ,DRIVE //運転
takeru0x1103 21:78302ecdb661 151 ,GROUND //着陸(エンジン同時下げ)
takeru0x1103 21:78302ecdb661 152 ,EMGGND //緊急着陸(後ろエンジンを先に下げる)
MasashiNomura 36:2cc739c7e4cb 153 ,CHK_EG_ENT //SLEEPからエンジン調整モードへ(フラグリセット、アナログ入力が下がっていること、ボタンが押されいないことの確認State)
MasashiNomura 36:2cc739c7e4cb 154 ,CHK_EG_F //フロントエンジン調整
MasashiNomura 36:2cc739c7e4cb 155 ,CHK_EG_MID //アナログ入力が下がっていること、ボタンが押されていないことを確認するState
MasashiNomura 36:2cc739c7e4cb 156 ,CHK_EG_R //リアエンジン調整
MasashiNomura 36:2cc739c7e4cb 157 ,CHK_EG_EXIT//アナログ入力が下がっていること、他のボタンが押されていないことを確認してSLEEPへ
takeru0x1103 20:0394e15412c3 158 ,CHK_ENT //チェックエンター
takeru0x1103 20:0394e15412c3 159 ,CHK_MOT //モーターチェック
takeru0x1103 20:0394e15412c3 160 ,CHK_AXL //アクセルサーボチェック
takeru0x1103 20:0394e15412c3 161 ,CHK_ATT //姿勢制御チェック
takeru0x1103 20:0394e15412c3 162 ,CHK_EXIT //チェックステート脱出
MasashiNomura 25:f3a6e7eec9c3 163 ,MOT_STOP //モーター停止用
MasashiNomura 41:45c982b1c5b6 164 };
MasashiNomura 41:45c982b1c5b6 165
MasashiNomura 41:45c982b1c5b6 166 // 状態表示用LEDカラー
MasashiNomura 41:45c982b1c5b6 167 enum eLedCol{
MasashiNomura 41:45c982b1c5b6 168 OFF = 0,
MasashiNomura 41:45c982b1c5b6 169 WHITE,
MasashiNomura 41:45c982b1c5b6 170 RED,
MasashiNomura 41:45c982b1c5b6 171 GREEN,
MasashiNomura 41:45c982b1c5b6 172 BLUE,
MasashiNomura 41:45c982b1c5b6 173 YELLOW,
MasashiNomura 41:45c982b1c5b6 174 PURPLE,
MasashiNomura 41:45c982b1c5b6 175 LIGHT_BLUE,
MasashiNomura 41:45c982b1c5b6 176 };
takeru0x1103 19:4b0fe9a5ec38 177
MasashiNomura 28:fdb3b144e342 178 enum eMotPos{
MasashiNomura 28:fdb3b144e342 179 F_L = 0, // 前 左
MasashiNomura 28:fdb3b144e342 180 F_R, // 前 右
MasashiNomura 28:fdb3b144e342 181 R_L, // 後 左
MasashiNomura 28:fdb3b144e342 182 R_R, // 後 右
MasashiNomura 28:fdb3b144e342 183 };
MasashiNomura 28:fdb3b144e342 184 enum eMotType{
MasashiNomura 28:fdb3b144e342 185 IN = 0,
MasashiNomura 28:fdb3b144e342 186 OUT,
MasashiNomura 28:fdb3b144e342 187 };
MasashiNomura 32:7f4145cc3551 188 enum eMotInType{
MasashiNomura 32:7f4145cc3551 189 OFS = 0,
MasashiNomura 32:7f4145cc3551 190 ATT,
MasashiNomura 32:7f4145cc3551 191 USER,
MasashiNomura 32:7f4145cc3551 192 };
MasashiNomura 36:2cc739c7e4cb 193 enum eEgPos{
MasashiNomura 36:2cc739c7e4cb 194 FRONT = 0,
MasashiNomura 36:2cc739c7e4cb 195 REAR,
MasashiNomura 36:2cc739c7e4cb 196 };
takeru0x1103 17:f9610f3cfa1b 197 /////////////////////////////////////////////////
takeru0x1103 21:78302ecdb661 198
MasashiNomura 35:3779201b4c73 199 //void init1PushStruct(typ1Push& item);
MasashiNomura 29:eb3d72dd94aa 200
MasashiNomura 22:24c9c2dedca9 201 void initFlags();
MasashiNomura 22:24c9c2dedca9 202
MasashiNomura 41:45c982b1c5b6 203 void setDOCol(eLedCol col);
MasashiNomura 41:45c982b1c5b6 204 void setDO4LED(enmHbState stat);
MasashiNomura 22:24c9c2dedca9 205 void setState(enmHbState stat);
MasashiNomura 23:79e20be4bc5b 206 void setStateF(enmHbState stat);
MasashiNomura 22:24c9c2dedca9 207
MasashiNomura 37:d51dacb4c30f 208 bool isActiveState();
MasashiNomura 22:24c9c2dedca9 209
takeru0x1103 21:78302ecdb661 210 /*
takeru0x1103 19:4b0fe9a5ec38 211 class GlobalFlags{
takeru0x1103 19:4b0fe9a5ec38 212 private:
takeru0x1103 19:4b0fe9a5ec38 213 enmHbState stateQueue[STATE_QUE_SIZ];//ステート予約用のキューバッファ
takeru0x1103 19:4b0fe9a5ec38 214 int wp; //ライトポインタ
takeru0x1103 19:4b0fe9a5ec38 215 int rp; //リードポインタ
takeru0x1103 19:4b0fe9a5ec38 216 bool full; //フルフラグ
takeru0x1103 19:4b0fe9a5ec38 217 bool empty; //エンプティフラグ
takeru0x1103 19:4b0fe9a5ec38 218 public:
takeru0x1103 21:78302ecdb661 219 //プロパティ
takeru0x1103 20:0394e15412c3 220 enmHbState state;//現在のステート
takeru0x1103 21:78302ecdb661 221 //メソッド
takeru0x1103 20:0394e15412c3 222 GlobalFlags();//コンストラクタ
takeru0x1103 19:4b0fe9a5ec38 223 bool push(enmHbState iState);
takeru0x1103 19:4b0fe9a5ec38 224 bool pull();
takeru0x1103 19:4b0fe9a5ec38 225 };
takeru0x1103 16:05b9e44889f1 226
takeru0x1103 21:78302ecdb661 227 */
takeru0x1103 21:78302ecdb661 228
takeru0x1103 21:78302ecdb661 229
takeru0x1103 17:f9610f3cfa1b 230 //モニタ用LED
takeru0x1103 16:05b9e44889f1 231 extern DigitalOut led1;
takeru0x1103 16:05b9e44889f1 232 extern DigitalOut led2;
takeru0x1103 16:05b9e44889f1 233 extern DigitalOut led3;
takeru0x1103 16:05b9e44889f1 234 extern DigitalOut led4;
takeru0x1103 8:1ca49cb18290 235
MasashiNomura 40:debe99e228d3 236 //状態表示用
MasashiNomura 40:debe99e228d3 237 extern DigitalOut DO_01;
MasashiNomura 40:debe99e228d3 238 extern DigitalOut DO_02;
MasashiNomura 40:debe99e228d3 239 extern DigitalOut DO_03;
MasashiNomura 40:debe99e228d3 240
MasashiNomura 33:eb260dbfc22a 241 //モーターアクセル用アナログ入力
MasashiNomura 33:eb260dbfc22a 242 extern AnalogIn AinAxl;
MasashiNomura 33:eb260dbfc22a 243
MasashiNomura 38:24ee50452755 244 // //エンジンスロットル用アナログ入力
MasashiNomura 38:24ee50452755 245 // extern AnalogIn AinThrottle;
MasashiNomura 36:2cc739c7e4cb 246
MasashiNomura 22:24c9c2dedca9 247 //////////////////////////////////////////////////
MasashiNomura 22:24c9c2dedca9 248 // フラグ
takeru0x1103 21:78302ecdb661 249 //extern GlobalFlags gf;
takeru0x1103 19:4b0fe9a5ec38 250
takeru0x1103 19:4b0fe9a5ec38 251 extern char g_CmdBuf[G_CMD_BUF_SIZ] ;// コマンド受け渡しバッファ
MasashiNomura 22:24c9c2dedca9 252 extern bool gf_CmdPrs; //コマンドパーサー実行要求フラグ
takeru0x1103 19:4b0fe9a5ec38 253
takeru0x1103 21:78302ecdb661 254 extern bool gf_Armed; //アーミングフラグ
MasashiNomura 22:24c9c2dedca9 255 extern bool gf_Dbg; //デバッグフラグ
MasashiNomura 37:d51dacb4c30f 256 extern bool gf_StopMot; //モーターの強制停止 サーボ全閉
MasashiNomura 37:d51dacb4c30f 257 extern bool gf_FromActiveStat ;//モーターの強制停止 サーボ全閉が動作時に発生したかどうか
MasashiNomura 25:f3a6e7eec9c3 258
MasashiNomura 41:45c982b1c5b6 259 //extern typPrintFlag gf_Print; //デバッグプリントフラグ(1回表示)
MasashiNomura 41:45c982b1c5b6 260 //extern typPrintFlag gf_Mon; //デバッグモニタフラグ(繰り返し表示)
MasashiNomura 41:45c982b1c5b6 261 extern typPrintFlg gf_Print; //デバッグプリントフラグ(1回表示)
MasashiNomura 41:45c982b1c5b6 262 extern typPrintFlg gf_Mon; //デバッグモニタフラグ(繰り返し表示)
MasashiNomura 22:24c9c2dedca9 263 extern typCalFlag gf_Cal; //キャリブレーションフラグ
MasashiNomura 26:732bc37fbefd 264
MasashiNomura 41:45c982b1c5b6 265 //extern typDbgPrintFlg gf_DbgPrint ;//デバッグ用
MasashiNomura 26:732bc37fbefd 266
MasashiNomura 22:24c9c2dedca9 267 extern typAccel gf_AxReq[2]; //アクセル更新
MasashiNomura 32:7f4145cc3551 268 extern typAxlRpm gf_MtReq[4]; //モーター姿勢制御更新
MasashiNomura 29:eb3d72dd94aa 269 extern typAxlRpm gf_MtReqOfs[4]; //モーターオフセット更新
MasashiNomura 32:7f4145cc3551 270 extern typAxlRpm gf_MtReqU[4]; //モーターユーザー更新
MasashiNomura 29:eb3d72dd94aa 271 extern typAxlRpm gf_MtReqDct[8] ;//ダイレクト(FPGA関数直接呼び出し)モーター更新フラグ
MasashiNomura 22:24c9c2dedca9 272
MasashiNomura 22:24c9c2dedca9 273 extern enmHbState gf_State; //現在のステート
MasashiNomura 36:2cc739c7e4cb 274 extern bool gf_StateEnt ;//状態遷移後、最初であることを示す
takeru0x1103 19:4b0fe9a5ec38 275
MasashiNomura 24:c5945aaae777 276 extern bool gf_PidParaUpdate ;//PID Pp,P,I,Dの係数アップデートフラグ
MasashiNomura 24:c5945aaae777 277 extern typPidPara g_PidPara; //PID Pp,P,I,Dの係数の外部設定用
takeru0x1103 19:4b0fe9a5ec38 278
MasashiNomura 36:2cc739c7e4cb 279 // extern bool gf_MotParaUpdate[4] ;//モーターのパラメータ値更新フラグ
MasashiNomura 36:2cc739c7e4cb 280 // extern typMotPara g_MotPara[4]; //モーターのパラメータ値
MasashiNomura 25:f3a6e7eec9c3 281
takeru0x1103 18:5aa48aec9cae 282 #endif