teamALI / Mbed 2 deprecated HB2018

Dependencies:   mbed FreeRTOS

Committer:
MasashiNomura
Date:
Fri Jan 18 11:52:00 2019 +0000
Revision:
38:24ee50452755
Parent:
37:d51dacb4c30f
Child:
39:1b76f7df8804
20190118 Modify for 45inc. check User SW (include analogIn)

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