2022NHKAチーム(射出、紙飛行機折り、昇降)

Dependencies:   OmniPosition PID R1370 SerialMultiByte Servo ikarashiMDC_2byte_ver mbed omni_wheel

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FEP_RX22.h Source File

FEP_RX22.h

Go to the documentation of this file.
00001 /**
00002  *  @file   FEP_RX22.h
00003  *  @brief  FEP受信用ライブラリ
00004  *  @author 安澤瑠
00005  *  @date   22/10/6
00006  */
00007 #ifndef FEP_RX22_H
00008 #define FEP_RX22_H
00009 
00010 #define TIMEOUT_COUNT 5
00011 #define ControllerMode 0 // 1にするとコントローラー専用受信。0にすると汎用受信。
00012 
00013 #include "mbed.h"
00014 
00015 /**
00016  *  @class con 
00017  *  @brief class for FEP
00018  *  @note  RawSerialクラスを使用しているため mbed-os 6 では使えません。  Not compatible with mbed-os 6
00019  */
00020 class FEP_RX22 : public RawSerial {
00021 public :
00022     /** constructor
00023      *  @param tx   FEPと接続するSerialTX pin
00024      *  @param rx   FEPと接続するSerialRX pin
00025      *  @param addr コントローラーについてるFEPのアドレス
00026      *  @param baud 通信速度(デフォルト115200)
00027      */
00028     FEP_RX22(PinName tx, PinName rx, uint8_t addr_, int baud=115200);
00029 
00030     /** Start receiving
00031      */
00032     void StartReceive();
00033     
00034     /** Check timeout
00035      *  @brief 0.1秒毎のループで受信のタイムアウトをチェック
00036      */
00037     void TimeoutLoop();
00038 
00039     /** Interrupt input
00040      */
00041     void ReceiveBytes();
00042 
00043     /** extract the message
00044      */
00045     void CheckData();
00046 
00047     /** Write the received message
00048      *  @param data 受信メッセージを格納する配列
00049      */
00050     uint8_t getData(uint8_t *data);
00051     
00052     /** Set controller data
00053      */
00054     void getControllerState();
00055     
00056     bool getButton(uint8_t n); //! ボタンの値を返す。
00057     int16_t getStick(uint8_t n); //! スティックの値を返す。中心を0,範囲は-128 ~ 128とする。
00058     int16_t getTrigger(uint8_t n); //! トリガーの値を返す。
00059     uint8_t getTimeout();
00060     bool getStatus();
00061     
00062 
00063 private :
00064     
00065     Ticker timeoutTimer;
00066     uint8_t addr;         //! 通信相手のアドレス
00067     uint8_t buffer[256];  //! 全受信データを格納するリングバッファ配列
00068     uint8_t msgdata[128]; //! メッセージのみを格納する配列
00069     uint8_t bufindex;     //! buffer の添え字変数
00070     uint8_t timeout;      //! 0.1秒間通信が成功していないと1増える
00071     uint8_t indexofR;     //! RBNの先頭文字の位置
00072     bool status;          //! (TIMEOUT_COUNT * 0.1)秒間通信が成り立っていない場合、false
00073     uint8_t datalen;      //! データバイトの長さ
00074     // コントローラ用
00075     uint8_t button[2];    //! ボタンの値を格納
00076     uint8_t stick[4];     //! スティックの値を格納
00077     uint8_t trigger[4];   //! トリガーの値を格納
00078 };
00079 
00080 #endif