teamALI / Mbed 2 deprecated HB2018

Dependencies:   mbed FreeRTOS

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