kani

Dependencies:   2017NHKpin_config FEP omni_wheel PID R1307 ikarashiMDC

classDiagram

    \ ̄\                   / ̄/ 
/l     \  \             /  / lヽ  
| ヽ  ヽ   |           |  /  / | 
\ ` ‐ヽ  ヽ  ●        ●         /  / ‐  / 
  \ __ l  |  ||___|| /  l __ / 
     \  \ /      \/ 
      /\|   人__人  |/\    <ズワイガニ  
    //\|             |/\\     
    //\|   ケガニ            |/\\     
    /     . \_____/         \ 

                               ┏┓        ┏━┓┏┓              
     ┏┓         ┏┓┏┓   ┏┓    ┏┓┗┛     ┏┓ ┗┓┃┗┛              
┏┛┗━┓  ┃┃┃┃    ┃┃┏━┛┗┓┏┓┏┛┗━┓┃┃┏┓┏┓┏━━━┓ 
┗┓┏━┛  ┃┃┗┛    ┃┃┗━┓┏┛┗┛┗┓┏┓┃┗┛┗┛┃┃┗━━━┛    
┏┛┃┏━┓┃┗━━┓┃┃┏━┛┗┓      ┏┛┃┃┃        ┃┃              
┃┏┛┗━┛┗━━┓┃┃┃┃┏┓┏┛      ┗━┛┃┃        ┃┃┏┓          
┃┃┏━━┓┏━━┛┃┃┃┃┗┛┃         ┏┛┃        ┃┃┃┗━━┓    
┗┛┗━━┛┗━━━┛┗┛┗━━┛         ┗━┛        ┗┛┗━━━┛  
Committer:
takeuchi
Date:
Fri Oct 27 16:14:50 2017 +0900
Revision:
45:a3ff2bc0574b
Parent:
43:c659cd5baa14
Child:
47:43f55ff8916b
add slow mode

Who changed what in which revision?

UserRevisionLine numberNew contents of line
uchitake 1:845af5425eec 1 /**
uchitake 1:845af5425eec 2 * @file PID_controller.h
uchitake 1:845af5425eec 3 * @brief コンパスセンサを使ったPIDコントローラ
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 "PID_controller.h"
uchitake 1:845af5425eec 9 *
uchitake 1:845af5425eec 10 * PIDC pidc;
uchitake 1:845af5425eec 11 *
uchitake 1:845af5425eec 12 * int main()
uchitake 1:845af5425eec 13 * {
uchitake 1:845af5425eec 14 * while(1) {
uchitake 1:845af5425eec 15 * pidc.confirm();
uchitake 1:845af5425eec 16 * pc.printf("Hi, %f\r\n", pid.getCo());
uchitake 1:845af5425eec 17 * }
uchitake 1:845af5425eec 18 * }
uchitake 1:845af5425eec 19 * @endcode
uchitake 1:845af5425eec 20 */
uchitake 1:845af5425eec 21 #ifndef PID_CONTROLLER_H
uchitake 1:845af5425eec 22 #define PID_CONTROLLER_H
uchitake 1:845af5425eec 23
uchitake 1:845af5425eec 24 #include "mbed.h"
uchitake 1:845af5425eec 25 #include "pin_config.h"
uchitake 1:845af5425eec 26
uchitake 1:845af5425eec 27 #include "PID.h"
uchitake 1:845af5425eec 28 #include "HMC6352.h"
uchitake 1:845af5425eec 29
takeuchi 45:a3ff2bc0574b 30 const double KC = 8.2;
uchitake 1:845af5425eec 31 const double TI = 0.0;
takeuchi 43:c659cd5baa14 32 const double TD = 0.0000;
uchitake 3:369d9ee17e84 33 const float INTERVAL = 0.01;
uchitake 29:41f6fc4c8962 34 const float INPUT_LIMIT = 360.0;
uchitake 1:845af5425eec 35 const float OUTPUT_LIMIT = 0.4;
uchitake 1:845af5425eec 36 const float BIAS = 0.0;
uchitake 6:fe9767a50891 37 const int SENSED_THRESHOLD = 1800;
uchitake 1:845af5425eec 38
uchitake 1:845af5425eec 39 /**
uchitake 1:845af5425eec 40 * @brief コンパスセンサを使ったPIDコントローラ
uchitake 1:845af5425eec 41 */
uchitake 1:845af5425eec 42 class PIDC : public PID, HMC6352, Ticker
uchitake 1:845af5425eec 43 {
uchitake 1:845af5425eec 44 public :
uchitake 1:845af5425eec 45 /**
uchitake 1:845af5425eec 46 * @brief defaultコンストラクタ,タイマ割り込みでの計算開始
uchitake 1:845af5425eec 47 */
uchitake 1:845af5425eec 48 PIDC();
uchitake 1:845af5425eec 49
uchitake 1:845af5425eec 50 /**
uchitake 1:845af5425eec 51 * @brief コンストラクタ
uchitake 1:845af5425eec 52 * @param sda sda HMC6352
uchitake 1:845af5425eec 53 * @param scl scl HMC6352
uchitake 1:845af5425eec 54 * @param kc KC
uchitake 1:845af5425eec 55 * @param ti TI
uchitake 1:845af5425eec 56 * @param td TD
uchitake 1:845af5425eec 57 * @param interval interval
uchitake 1:845af5425eec 58 */
uchitake 1:845af5425eec 59 PIDC(PinName sda, PinName scl, float kc, float ti, float td, float interval);
uchitake 1:845af5425eec 60
uchitake 7:c6acf63088b0 61 /**
uchitake 7:c6acf63088b0 62 * @brief センサの値とPIDの値をアップデート
uchitake 7:c6acf63088b0 63 */
uchitake 7:c6acf63088b0 64 void confirm();
uchitake 4:1073deb368df 65
uchitake 7:c6acf63088b0 66 /**
uchitake 7:c6acf63088b0 67 * @brief 回転用座標系リセット
uchitake 7:c6acf63088b0 68 */
takeuchi 32:b619c7787dc3 69 void resetOffset();
uchitake 7:c6acf63088b0 70
uchitake 7:c6acf63088b0 71 /**
uchitake 7:c6acf63088b0 72 * @brief PIDの計算結果を取得
uchitake 7:c6acf63088b0 73 * @return PIDの計算結果
uchitake 7:c6acf63088b0 74 */
uchitake 6:fe9767a50891 75 float getCalculationResult() const;
uchitake 7:c6acf63088b0 76
uchitake 7:c6acf63088b0 77 /**
uchitake 7:c6acf63088b0 78 * 現在の角度を取得
uchitake 7:c6acf63088b0 79 * @return 現在の角度(degree)
uchitake 7:c6acf63088b0 80 */
uchitake 6:fe9767a50891 81 int getCurrentDegree() const;
uchitake 7:c6acf63088b0 82
uchitake 18:78df87e20590 83 /**
uchitake 18:78df87e20590 84 * センサの生値を取得
uchitake 18:78df87e20590 85 * @return コンパスセンサの生値
uchitake 18:78df87e20590 86 */
uchitake 17:79fa65706f92 87 int getRawDegree();
uchitake 17:79fa65706f92 88
takeuchi 32:b619c7787dc3 89 void setPoint(float point);
takeuchi 32:b619c7787dc3 90
uchitake 7:c6acf63088b0 91 /**
uchitake 7:c6acf63088b0 92 * @brief キャリブレーションする
uchitake 7:c6acf63088b0 93 * @param mode ENTER OR EXIT
uchitake 7:c6acf63088b0 94 */
uchitake 1:845af5425eec 95 void calibration(int mode);
uchitake 1:845af5425eec 96 private :
uchitake 1:845af5425eec 97
uchitake 1:845af5425eec 98 void updateOutput();
uchitake 1:845af5425eec 99
takeuchi 32:b619c7787dc3 100 int offSetDegree;
uchitake 1:845af5425eec 101 int turnOverNumber;
uchitake 1:845af5425eec 102 int beforeDegree;
uchitake 1:845af5425eec 103
uchitake 1:845af5425eec 104 protected :
uchitake 17:79fa65706f92 105
uchitake 5:16ea97725085 106 int rawDegree;
uchitake 6:fe9767a50891 107 float calculationResult;
takeuchi 32:b619c7787dc3 108 int currentDegree;
uchitake 1:845af5425eec 109 };
uchitake 1:845af5425eec 110
uchitake 1:845af5425eec 111 #endif//PID_CONTROLLER_H