teamALI / Mbed 2 deprecated HB2018

Dependencies:   mbed FreeRTOS

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