teamALI / Mbed 2 deprecated HB2018

Dependencies:   mbed FreeRTOS

Committer:
MasashiNomura
Date:
Sat Jan 19 12:35:23 2019 +0000
Revision:
39:1b76f7df8804
Parent:
38:24ee50452755
Child:
40:debe99e228d3
20190119 Modify for 45inc; Checking User SW and sequence

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