Octopus!!
Dependencies: 2017NHKpin_config FEP HMC6352 PID QEI R1307 ikarashiMDC omni_wheel
Fork of KANIv3 by
bot/controller/controller.h@1:845af5425eec, 2017-09-05 (annotated)
- Committer:
- uchitake
- Date:
- Tue Sep 05 16:11:20 2017 +0900
- Revision:
- 1:845af5425eec
- Child:
- 49:69a7235d837a
mbed-os5
Who changed what in which revision?
User | Revision | Line number | New 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; |
uchitake |
1:845af5425eec | 37 | const int ADDR = 203; |
uchitake |
1:845af5425eec | 38 | const bool FEP_SUCCESS =0; |
uchitake |
1:845af5425eec | 39 | const int DATA_SIZE = 6; |
uchitake |
1:845af5425eec | 40 | const float STICK_DIVIDE = 255.0; |
uchitake |
1:845af5425eec | 41 | const float STICK_NEWTRAL = 0.1; |
uchitake |
1:845af5425eec | 42 | const float STICK_NORM_MAX =1.0; |
uchitake |
1:845af5425eec | 43 | |
uchitake |
1:845af5425eec | 44 | /** |
uchitake |
1:845af5425eec | 45 | * @brief FEPを使ったコントローラのクラス |
uchitake |
1:845af5425eec | 46 | */ |
uchitake |
1:845af5425eec | 47 | class Controller : public FEP |
uchitake |
1:845af5425eec | 48 | { |
uchitake |
1:845af5425eec | 49 | public : |
uchitake |
1:845af5425eec | 50 | |
uchitake |
1:845af5425eec | 51 | /** |
uchitake |
1:845af5425eec | 52 | * @brief コンストラクタ |
uchitake |
1:845af5425eec | 53 | */ |
uchitake |
1:845af5425eec | 54 | Controller(); |
uchitake |
1:845af5425eec | 55 | |
uchitake |
1:845af5425eec | 56 | /** |
uchitake |
1:845af5425eec | 57 | * @brief コンストラクタ |
uchitake |
1:845af5425eec | 58 | * @param FEPtx FEPtx |
uchitake |
1:845af5425eec | 59 | * @param FEPrx FEPrx |
uchitake |
1:845af5425eec | 60 | * @param addr address |
uchitake |
1:845af5425eec | 61 | */ |
uchitake |
1:845af5425eec | 62 | Controller(PinName FEPtx, PinName FEPrx,int addr); |
uchitake |
1:845af5425eec | 63 | |
uchitake |
1:845af5425eec | 64 | /** |
uchitake |
1:845af5425eec | 65 | * @brief メンバ変数にボタンのステートを格納 |
uchitake |
1:845af5425eec | 66 | */ |
uchitake |
1:845af5425eec | 67 | bool receiveState(); |
uchitake |
1:845af5425eec | 68 | |
uchitake |
1:845af5425eec | 69 | /** |
uchitake |
1:845af5425eec | 70 | * ボタン1の状態を取得 |
uchitake |
1:845af5425eec | 71 | * @param number button number |
uchitake |
1:845af5425eec | 72 | * @return status |
uchitake |
1:845af5425eec | 73 | */ |
uchitake |
1:845af5425eec | 74 | bool getButton1(int number) const; |
uchitake |
1:845af5425eec | 75 | |
uchitake |
1:845af5425eec | 76 | /** |
uchitake |
1:845af5425eec | 77 | * ボタン2の状態を取得 |
uchitake |
1:845af5425eec | 78 | * @param number button number |
uchitake |
1:845af5425eec | 79 | * @return status |
uchitake |
1:845af5425eec | 80 | */ |
uchitake |
1:845af5425eec | 81 | bool getButton2(int number) const; |
uchitake |
1:845af5425eec | 82 | |
uchitake |
1:845af5425eec | 83 | /** |
uchitake |
1:845af5425eec | 84 | * スティックの値を取得 |
uchitake |
1:845af5425eec | 85 | * @param number sticknumber(x, y, x, y) |
uchitake |
1:845af5425eec | 86 | * @return stick value |
uchitake |
1:845af5425eec | 87 | */ |
uchitake |
1:845af5425eec | 88 | float getStick(int number) const; |
uchitake |
1:845af5425eec | 89 | |
uchitake |
1:845af5425eec | 90 | /** |
uchitake |
1:845af5425eec | 91 | * スチィックの角度を取得 |
uchitake |
1:845af5425eec | 92 | * @param number left...0 right...1 |
uchitake |
1:845af5425eec | 93 | * @return radian |
uchitake |
1:845af5425eec | 94 | */ |
uchitake |
1:845af5425eec | 95 | float getRadian(int number) const; |
uchitake |
1:845af5425eec | 96 | |
uchitake |
1:845af5425eec | 97 | /** |
uchitake |
1:845af5425eec | 98 | * スティックの距離を取得 |
uchitake |
1:845af5425eec | 99 | * @param number left..0 right..1 |
uchitake |
1:845af5425eec | 100 | * @return norm |
uchitake |
1:845af5425eec | 101 | */ |
uchitake |
1:845af5425eec | 102 | float getNorm(int number) const; |
uchitake |
1:845af5425eec | 103 | |
uchitake |
1:845af5425eec | 104 | private : |
uchitake |
1:845af5425eec | 105 | void setStick(); |
uchitake |
1:845af5425eec | 106 | |
uchitake |
1:845af5425eec | 107 | char data[6]; |
uchitake |
1:845af5425eec | 108 | uint8_t fepTemp; |
uchitake |
1:845af5425eec | 109 | |
uchitake |
1:845af5425eec | 110 | protected : |
uchitake |
1:845af5425eec | 111 | bool button1[7]; |
uchitake |
1:845af5425eec | 112 | bool button2[6]; |
uchitake |
1:845af5425eec | 113 | double stick[4]; |
uchitake |
1:845af5425eec | 114 | double radian[2]; |
uchitake |
1:845af5425eec | 115 | double norm[2]; |
uchitake |
1:845af5425eec | 116 | }; |
uchitake |
1:845af5425eec | 117 | |
uchitake |
1:845af5425eec | 118 | #endif//CONTROLLER_H |