Octopus!!

Dependencies:   2017NHKpin_config FEP HMC6352 PID QEI R1307 ikarashiMDC omni_wheel

Fork of KANIv3 by NagaokaRoboticsClub_mbedTeam

Committer:
number_key
Date:
Thu Nov 23 11:49:39 2017 +0900
Revision:
52:320f910ca6ca
Parent:
49:69a7235d837a
dirty

Who changed what in which revision?

UserRevisionLine numberNew contents of line
uchitake 1:845af5425eec 1 /**
uchitake 1:845af5425eec 2 * @file controller.h
uchitake 1:845af5425eec 3 * @brief FEPを使ったコントローラ受信部
uchitake 1:845af5425eec 4 *
uchitake 1:845af5425eec 5 * Example :
uchitake 1:845af5425eec 6 * @code
uchitake 1:845af5425eec 7 * #include "mbed.h"
uchitake 1:845af5425eec 8 * #include "controller.h"
uchitake 1:845af5425eec 9 *
uchitake 1:845af5425eec 10 * Controller pad(PA_9, PA_10, 200);
uchitake 1:845af5425eec 11 * Serial pc(USBTX, USBRX, 115200);
uchitake 1:845af5425eec 12 *
uchitake 1:845af5425eec 13 * int main()
uchitake 1:845af5425eec 14 * {
uchitake 1:845af5425eec 15 * while(1) {
uchitake 1:845af5425eec 16 * if(pad.receiveState()) {
uchitake 1:845af5425eec 17 * for(int i = 0; i < 7; i++) pc.printf("%d, ", pad.getButton1(i));
uchitake 1:845af5425eec 18 * for(int i = 0; i < 6; i++) pc.printf("%d, ", pad.getButton2(i));
uchitake 1:845af5425eec 19 * pc.printf("\r\n");
uchitake 1:845af5425eec 20 * } else {
uchitake 1:845af5425eec 21 * pc.printf("ERROR\n\r");
uchitake 1:845af5425eec 22 * }
uchitake 1:845af5425eec 23 * }
uchitake 1:845af5425eec 24 * }
uchitake 1:845af5425eec 25 * @endcode
uchitake 1:845af5425eec 26 */
uchitake 1:845af5425eec 27 #ifndef CONTROLLER_H
uchitake 1:845af5425eec 28 #define CONTROLLER_H
uchitake 1:845af5425eec 29
uchitake 1:845af5425eec 30 #include "mbed.h"
uchitake 1:845af5425eec 31 #include "pin_config.h"
uchitake 1:845af5425eec 32 #include <math.h>
uchitake 1:845af5425eec 33
uchitake 1:845af5425eec 34 #include "FEP.h"
uchitake 1:845af5425eec 35
uchitake 1:845af5425eec 36 // const double M_PI = 3.141592653589793;
number_key 49:69a7235d837a 37 const int ADDR1 = 211;
number_key 49:69a7235d837a 38 const int ADDR2 = 209;
uchitake 1:845af5425eec 39 const bool FEP_SUCCESS =0;
uchitake 1:845af5425eec 40 const int DATA_SIZE = 6;
uchitake 1:845af5425eec 41 const float STICK_DIVIDE = 255.0;
uchitake 1:845af5425eec 42 const float STICK_NEWTRAL = 0.1;
uchitake 1:845af5425eec 43 const float STICK_NORM_MAX =1.0;
uchitake 1:845af5425eec 44
uchitake 1:845af5425eec 45 /**
uchitake 1:845af5425eec 46 * @brief FEPを使ったコントローラのクラス
uchitake 1:845af5425eec 47 */
uchitake 1:845af5425eec 48 class Controller : public FEP
uchitake 1:845af5425eec 49 {
uchitake 1:845af5425eec 50 public :
uchitake 1:845af5425eec 51
uchitake 1:845af5425eec 52 /**
uchitake 1:845af5425eec 53 * @brief コンストラクタ
uchitake 1:845af5425eec 54 */
uchitake 1:845af5425eec 55 Controller();
uchitake 1:845af5425eec 56
uchitake 1:845af5425eec 57 /**
uchitake 1:845af5425eec 58 * @brief コンストラクタ
uchitake 1:845af5425eec 59 * @param FEPtx FEPtx
uchitake 1:845af5425eec 60 * @param FEPrx FEPrx
uchitake 1:845af5425eec 61 * @param addr address
uchitake 1:845af5425eec 62 */
uchitake 1:845af5425eec 63 Controller(PinName FEPtx, PinName FEPrx,int addr);
uchitake 1:845af5425eec 64
uchitake 1:845af5425eec 65 /**
uchitake 1:845af5425eec 66 * @brief メンバ変数にボタンのステートを格納
uchitake 1:845af5425eec 67 */
number_key 52:320f910ca6ca 68 int receiveState();
uchitake 1:845af5425eec 69
uchitake 1:845af5425eec 70 /**
uchitake 1:845af5425eec 71 * ボタン1の状態を取得
uchitake 1:845af5425eec 72 * @param number button number
uchitake 1:845af5425eec 73 * @return status
uchitake 1:845af5425eec 74 */
uchitake 1:845af5425eec 75 bool getButton1(int number) const;
uchitake 1:845af5425eec 76
uchitake 1:845af5425eec 77 /**
uchitake 1:845af5425eec 78 * ボタン2の状態を取得
uchitake 1:845af5425eec 79 * @param number button number
uchitake 1:845af5425eec 80 * @return status
uchitake 1:845af5425eec 81 */
uchitake 1:845af5425eec 82 bool getButton2(int number) const;
uchitake 1:845af5425eec 83
uchitake 1:845af5425eec 84 /**
uchitake 1:845af5425eec 85 * スティックの値を取得
uchitake 1:845af5425eec 86 * @param number sticknumber(x, y, x, y)
uchitake 1:845af5425eec 87 * @return stick value
uchitake 1:845af5425eec 88 */
uchitake 1:845af5425eec 89 float getStick(int number) const;
uchitake 1:845af5425eec 90
uchitake 1:845af5425eec 91 /**
uchitake 1:845af5425eec 92 * スチィックの角度を取得
uchitake 1:845af5425eec 93 * @param number left...0 right...1
uchitake 1:845af5425eec 94 * @return radian
uchitake 1:845af5425eec 95 */
uchitake 1:845af5425eec 96 float getRadian(int number) const;
uchitake 1:845af5425eec 97
uchitake 1:845af5425eec 98 /**
uchitake 1:845af5425eec 99 * スティックの距離を取得
uchitake 1:845af5425eec 100 * @param number left..0 right..1
uchitake 1:845af5425eec 101 * @return norm
uchitake 1:845af5425eec 102 */
uchitake 1:845af5425eec 103 float getNorm(int number) const;
uchitake 1:845af5425eec 104
uchitake 1:845af5425eec 105 private :
uchitake 1:845af5425eec 106 void setStick();
uchitake 1:845af5425eec 107
uchitake 1:845af5425eec 108 char data[6];
uchitake 1:845af5425eec 109 uint8_t fepTemp;
uchitake 1:845af5425eec 110
uchitake 1:845af5425eec 111 protected :
uchitake 1:845af5425eec 112 bool button1[7];
uchitake 1:845af5425eec 113 bool button2[6];
uchitake 1:845af5425eec 114 double stick[4];
uchitake 1:845af5425eec 115 double radian[2];
uchitake 1:845af5425eec 116 double norm[2];
uchitake 1:845af5425eec 117 };
uchitake 1:845af5425eec 118
uchitake 1:845af5425eec 119 #endif//CONTROLLER_H