kani

Dependencies:   2017NHKpin_config FEP omni_wheel PID R1307 ikarashiMDC

classDiagram

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

                               ┏┓        ┏━┓┏┓              
     ┏┓         ┏┓┏┓   ┏┓    ┏┓┗┛     ┏┓ ┗┓┃┗┛              
┏┛┗━┓  ┃┃┃┃    ┃┃┏━┛┗┓┏┓┏┛┗━┓┃┃┏┓┏┓┏━━━┓ 
┗┓┏━┛  ┃┃┗┛    ┃┃┗━┓┏┛┗┛┗┓┏┓┃┗┛┗┛┃┃┗━━━┛    
┏┛┃┏━┓┃┗━━┓┃┃┏━┛┗┓      ┏┛┃┃┃        ┃┃              
┃┏┛┗━┛┗━━┓┃┃┃┃┏┓┏┛      ┗━┛┃┃        ┃┃┏┓          
┃┃┏━━┓┏━━┛┃┃┃┃┗┛┃         ┏┛┃        ┃┃┃┗━━┓    
┗┛┗━━┛┗━━━┛┗┛┗━━┛         ┗━┛        ┗┛┗━━━┛  
Committer:
takeuchi
Date:
Fri Dec 22 17:34:28 2017 +0900
Revision:
55:f9e13797024f
Parent:
53:701d5c4571e3
reflesh code

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"
takeuchi 47:43f55ff8916b 28 #include "R1307.h"
uchitake 1:845af5425eec 29
takeuchi 53:701d5c4571e3 30 const double KC = 7.0;
takeuchi 53:701d5c4571e3 31 const double TI = 50.0;
takeuchi 49:703cc56d4858 32 const double TD = 0.000002;
takeuchi 47:43f55ff8916b 33 const float INTERVAL = 0.001;
uchitake 29:41f6fc4c8962 34 const float INPUT_LIMIT = 360.0;
takeuchi 53:701d5c4571e3 35 const float OUTPUT_LIMIT = 1.0;
uchitake 1:845af5425eec 36 const float BIAS = 0.0;
takeuchi 47:43f55ff8916b 37 const float SENSED_THRESHOLD = 180.0;
uchitake 1:845af5425eec 38
uchitake 1:845af5425eec 39 /**
uchitake 1:845af5425eec 40 * @brief コンパスセンサを使ったPIDコントローラ
uchitake 1:845af5425eec 41 */
takeuchi 47:43f55ff8916b 42 class PIDC
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 */
takeuchi 47:43f55ff8916b 59 PIDC(PinName tx, 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 */
takeuchi 47:43f55ff8916b 81 float getCurrentDegree() const;
uchitake 7:c6acf63088b0 82
uchitake 18:78df87e20590 83 /**
uchitake 18:78df87e20590 84 * センサの生値を取得
uchitake 18:78df87e20590 85 * @return コンパスセンサの生値
uchitake 18:78df87e20590 86 */
takeuchi 47:43f55ff8916b 87 float getRawDegree();
uchitake 17:79fa65706f92 88
takeuchi 32:b619c7787dc3 89 void setPoint(float point);
takeuchi 32:b619c7787dc3 90
uchitake 1:845af5425eec 91 private :
takeuchi 47:43f55ff8916b 92 float offSetDegree;
takeuchi 47:43f55ff8916b 93 int turnOverNumber;
takeuchi 47:43f55ff8916b 94 float beforeDegree;
uchitake 1:845af5425eec 95
takeuchi 47:43f55ff8916b 96 PID pid;
takeuchi 47:43f55ff8916b 97 R1307 r1370;
takeuchi 47:43f55ff8916b 98 Serial pidcSerial;
uchitake 1:845af5425eec 99
uchitake 1:845af5425eec 100 protected :
uchitake 17:79fa65706f92 101
takeuchi 47:43f55ff8916b 102 float rawDegree;
uchitake 6:fe9767a50891 103 float calculationResult;
takeuchi 47:43f55ff8916b 104 float currentDegree;
uchitake 1:845af5425eec 105 };
uchitake 1:845af5425eec 106
uchitake 1:845af5425eec 107 #endif//PID_CONTROLLER_H