teamALI / Mbed 2 deprecated HB2018

Dependencies:   mbed FreeRTOS

Committer:
MasashiNomura
Date:
Thu Dec 13 12:15:35 2018 +0000
Revision:
26:732bc37fbefd
Parent:
25:f3a6e7eec9c3
Child:
27:ff63c23bc689
2018/12/13 Add MotorOfs Function

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 23:79e20be4bc5b 31 bool stat : 1;//ステート表示
takeru0x1103 17:f9610f3cfa1b 32 }bf;
takeru0x1103 17:f9610f3cfa1b 33 }typPrintFlag;
takeru0x1103 17:f9610f3cfa1b 34
takeru0x1103 17:f9610f3cfa1b 35 typedef union{
takeru0x1103 17:f9610f3cfa1b 36 UINT16 flg;
takeru0x1103 17:f9610f3cfa1b 37 struct{
takeru0x1103 17:f9610f3cfa1b 38 bool e1 : 1;//
takeru0x1103 17:f9610f3cfa1b 39 bool e2 : 1;//
takeru0x1103 17:f9610f3cfa1b 40 bool m1 : 1;//
takeru0x1103 17:f9610f3cfa1b 41 bool m2 : 1;//
takeru0x1103 17:f9610f3cfa1b 42 bool m3 : 1;//
takeru0x1103 17:f9610f3cfa1b 43 bool m4 : 1;//
takeru0x1103 17:f9610f3cfa1b 44 bool gy : 1;//
takeru0x1103 17:f9610f3cfa1b 45 bool yaw : 1;//
takeru0x1103 18:5aa48aec9cae 46 bool fb : 1;//PID制御feedback結果
takeru0x1103 18:5aa48aec9cae 47 bool pp : 1;//P制御ゲイン(アウターループ)
takeru0x1103 18:5aa48aec9cae 48 bool p : 1;//P制御ゲイン
takeru0x1103 18:5aa48aec9cae 49 bool i : 1;//I制御ゲイン
takeru0x1103 18:5aa48aec9cae 50 bool d : 1;//D制御ゲイン
takeru0x1103 17:f9610f3cfa1b 51 }bf;
takeru0x1103 17:f9610f3cfa1b 52 }typCalFlag;
takeru0x1103 17:f9610f3cfa1b 53
takeru0x1103 19:4b0fe9a5ec38 54 //
takeru0x1103 17:f9610f3cfa1b 55 typedef union{
takeru0x1103 17:f9610f3cfa1b 56 UINT16 dt;
takeru0x1103 17:f9610f3cfa1b 57 struct{
takeru0x1103 18:5aa48aec9cae 58 UINT16 val : 12;//アクセル設定値
takeru0x1103 17:f9610f3cfa1b 59 bool req : 1;//アクセル更新要求
takeru0x1103 17:f9610f3cfa1b 60 }bf;
takeru0x1103 17:f9610f3cfa1b 61 }typAccel;
takeru0x1103 17:f9610f3cfa1b 62
MasashiNomura 26:732bc37fbefd 63 typedef union{
MasashiNomura 26:732bc37fbefd 64 UINT16 flg;
MasashiNomura 26:732bc37fbefd 65 struct{
MasashiNomura 26:732bc37fbefd 66 bool mo1 : 1;//Motor1 Offset val
MasashiNomura 26:732bc37fbefd 67 bool mo2 : 1;//Motor2 Offset val
MasashiNomura 26:732bc37fbefd 68 bool mo3 : 1;//Motor3 Offset val
MasashiNomura 26:732bc37fbefd 69 bool mo4 : 1;//Motor4 Offset val
MasashiNomura 26:732bc37fbefd 70 }bf;
MasashiNomura 26:732bc37fbefd 71 }typDbgPrintFlg;
MasashiNomura 25:f3a6e7eec9c3 72
MasashiNomura 24:c5945aaae777 73
takeru0x1103 19:4b0fe9a5ec38 74 //ステート定義
takeru0x1103 19:4b0fe9a5ec38 75 enum enmHbState
MasashiNomura 22:24c9c2dedca9 76 {NONE = 0 //何もなし
takeru0x1103 21:78302ecdb661 77 ,SLEEP //スリープモード(最初ここ)
takeru0x1103 20:0394e15412c3 78 ,WAKEUP //起動処理
takeru0x1103 20:0394e15412c3 79 ,STANDBY //スタンバイ(エンジンかかるの待ち)
takeru0x1103 21:78302ecdb661 80 ,IDLE //アイドル(エンジンがかかったけどなにもしない)
takeru0x1103 20:0394e15412c3 81 ,TAKE_OFF //離陸
takeru0x1103 20:0394e15412c3 82 ,HOVER //ホバリング
takeru0x1103 21:78302ecdb661 83 ,DRIVE //運転
takeru0x1103 21:78302ecdb661 84 ,GROUND //着陸(エンジン同時下げ)
takeru0x1103 21:78302ecdb661 85 ,EMGGND //緊急着陸(後ろエンジンを先に下げる)
takeru0x1103 20:0394e15412c3 86 ,CHK_ENT //チェックエンター
takeru0x1103 20:0394e15412c3 87 ,CHK_MOT //モーターチェック
takeru0x1103 20:0394e15412c3 88 ,CHK_AXL //アクセルサーボチェック
takeru0x1103 20:0394e15412c3 89 ,CHK_ATT //姿勢制御チェック
takeru0x1103 20:0394e15412c3 90 ,CHK_EXIT //チェックステート脱出
MasashiNomura 25:f3a6e7eec9c3 91 ,MOT_STOP //モーター停止用
takeru0x1103 19:4b0fe9a5ec38 92 };
takeru0x1103 19:4b0fe9a5ec38 93
takeru0x1103 17:f9610f3cfa1b 94 /////////////////////////////////////////////////
takeru0x1103 21:78302ecdb661 95
MasashiNomura 22:24c9c2dedca9 96 void initFlags();
MasashiNomura 22:24c9c2dedca9 97
MasashiNomura 22:24c9c2dedca9 98 void setState(enmHbState stat);
MasashiNomura 23:79e20be4bc5b 99 void setStateF(enmHbState stat);
MasashiNomura 22:24c9c2dedca9 100
MasashiNomura 22:24c9c2dedca9 101
takeru0x1103 21:78302ecdb661 102 /*
takeru0x1103 19:4b0fe9a5ec38 103 class GlobalFlags{
takeru0x1103 19:4b0fe9a5ec38 104 private:
takeru0x1103 19:4b0fe9a5ec38 105 enmHbState stateQueue[STATE_QUE_SIZ];//ステート予約用のキューバッファ
takeru0x1103 19:4b0fe9a5ec38 106 int wp; //ライトポインタ
takeru0x1103 19:4b0fe9a5ec38 107 int rp; //リードポインタ
takeru0x1103 19:4b0fe9a5ec38 108 bool full; //フルフラグ
takeru0x1103 19:4b0fe9a5ec38 109 bool empty; //エンプティフラグ
takeru0x1103 19:4b0fe9a5ec38 110 public:
takeru0x1103 21:78302ecdb661 111 //プロパティ
takeru0x1103 20:0394e15412c3 112 enmHbState state;//現在のステート
takeru0x1103 21:78302ecdb661 113 //メソッド
takeru0x1103 20:0394e15412c3 114 GlobalFlags();//コンストラクタ
takeru0x1103 19:4b0fe9a5ec38 115 bool push(enmHbState iState);
takeru0x1103 19:4b0fe9a5ec38 116 bool pull();
takeru0x1103 19:4b0fe9a5ec38 117 };
takeru0x1103 16:05b9e44889f1 118
takeru0x1103 21:78302ecdb661 119 */
takeru0x1103 21:78302ecdb661 120
takeru0x1103 21:78302ecdb661 121
takeru0x1103 17:f9610f3cfa1b 122 //モニタ用LED
takeru0x1103 16:05b9e44889f1 123 extern DigitalOut led1;
takeru0x1103 16:05b9e44889f1 124 extern DigitalOut led2;
takeru0x1103 16:05b9e44889f1 125 extern DigitalOut led3;
takeru0x1103 16:05b9e44889f1 126 extern DigitalOut led4;
takeru0x1103 8:1ca49cb18290 127
MasashiNomura 22:24c9c2dedca9 128 //////////////////////////////////////////////////
MasashiNomura 22:24c9c2dedca9 129 // フラグ
takeru0x1103 21:78302ecdb661 130 //extern GlobalFlags gf;
takeru0x1103 19:4b0fe9a5ec38 131
takeru0x1103 19:4b0fe9a5ec38 132 extern char g_CmdBuf[G_CMD_BUF_SIZ] ;// コマンド受け渡しバッファ
MasashiNomura 22:24c9c2dedca9 133 extern bool gf_CmdPrs; //コマンドパーサー実行要求フラグ
takeru0x1103 19:4b0fe9a5ec38 134
takeru0x1103 21:78302ecdb661 135 extern bool gf_Armed; //アーミングフラグ
MasashiNomura 22:24c9c2dedca9 136 extern bool gf_Dbg; //デバッグフラグ
MasashiNomura 25:f3a6e7eec9c3 137 extern bool gf_StopMot; //モーターの強制停止
MasashiNomura 25:f3a6e7eec9c3 138
MasashiNomura 22:24c9c2dedca9 139 extern typPrintFlag gf_Print; //デバッグプリントフラグ(1回表示)
MasashiNomura 22:24c9c2dedca9 140 extern typPrintFlag gf_Mon; //デバッグモニタフラグ(繰り返し表示)
MasashiNomura 22:24c9c2dedca9 141 extern typCalFlag gf_Cal; //キャリブレーションフラグ
MasashiNomura 26:732bc37fbefd 142
MasashiNomura 26:732bc37fbefd 143 extern typDbgPrintFlg gf_DbgPrint ;//デバッグ用
MasashiNomura 26:732bc37fbefd 144
MasashiNomura 22:24c9c2dedca9 145 extern typAccel gf_AxReq[2]; //アクセル更新
MasashiNomura 22:24c9c2dedca9 146 extern typAccel gf_MtReq[4]; //モーター更新
MasashiNomura 22:24c9c2dedca9 147
MasashiNomura 22:24c9c2dedca9 148 extern enmHbState gf_State; //現在のステート
takeru0x1103 19:4b0fe9a5ec38 149
MasashiNomura 24:c5945aaae777 150 extern bool gf_PidParaUpdate ;//PID Pp,P,I,Dの係数アップデートフラグ
MasashiNomura 24:c5945aaae777 151 extern typPidPara g_PidPara; //PID Pp,P,I,Dの係数の外部設定用
takeru0x1103 19:4b0fe9a5ec38 152
MasashiNomura 25:f3a6e7eec9c3 153 extern bool gf_MotParaUpdate[4] ;//モーターのパラメータ値更新フラグ
MasashiNomura 25:f3a6e7eec9c3 154 extern typMotPara g_MotPara[4]; //モーターのパラメータ値
MasashiNomura 25:f3a6e7eec9c3 155
takeru0x1103 18:5aa48aec9cae 156 #endif