Sub programs of serial_transport, PID and motor contrl.

Dependents:   tracking_ball_0516 tracking_ball_0516

Committer:
helenh
Date:
Sun May 30 01:39:35 2021 +0000
Revision:
7:fd405402ff8c
Parent:
2:a668eb71516b
e

Who changed what in which revision?

UserRevisionLine numberNew contents of line
helenh 2:a668eb71516b 1 #include "PID_Controller.h"
helenh 2:a668eb71516b 2
helenh 2:a668eb71516b 3
helenh 2:a668eb71516b 4 Ball_PID::Ball_PID(int p,int i,int d,int k)
helenh 2:a668eb71516b 5 {
helenh 2:a668eb71516b 6 this->m_PID_P=p;
helenh 2:a668eb71516b 7 this->m_PID_I=i;
helenh 2:a668eb71516b 8 this->m_PID_D=d;
helenh 2:a668eb71516b 9 this->m_K=k;
helenh 2:a668eb71516b 10 //创建环形存储对象
helenh 2:a668eb71516b 11
helenh 2:a668eb71516b 12 this->m_history_value=new Circle_Buffer_Class(WINDOWS_TIME);
helenh 2:a668eb71516b 13 }
helenh 2:a668eb71516b 14
helenh 2:a668eb71516b 15 Ball_PID::~Ball_PID()
helenh 2:a668eb71516b 16 {
helenh 2:a668eb71516b 17 delete this->m_history_value;
helenh 2:a668eb71516b 18 this->m_history_value=NULL;
helenh 2:a668eb71516b 19 }
helenh 2:a668eb71516b 20
helenh 2:a668eb71516b 21 //计算输出量,需补充算法
helenh 2:a668eb71516b 22 int Ball_PID::PID_Calculation(int preset_value,int actual_value)
helenh 2:a668eb71516b 23 {
helenh 2:a668eb71516b 24 int result=0;
helenh 2:a668eb71516b 25 //int velocity = (input_distance[WINDOWS_TIME] - input_distance[0]) / WINDOWS_TIME;
helenh 2:a668eb71516b 26
helenh 2:a668eb71516b 27 return result;
helenh 2:a668eb71516b 28 }
helenh 2:a668eb71516b 29
helenh 2:a668eb71516b 30 void Ball_PID::Set_Balance_Value(int value)
helenh 2:a668eb71516b 31 {
helenh 2:a668eb71516b 32
helenh 2:a668eb71516b 33 }
helenh 2:a668eb71516b 34
helenh 1:09e2d1034894 35
helenh 0:7f16c88e4047 36 //int kp = 100;
helenh 0:7f16c88e4047 37 //int kd = 0.6;
helenh 0:7f16c88e4047 38 //
helenh 0:7f16c88e4047 39 //int balance_distance = 0;
helenh 0:7f16c88e4047 40 //
helenh 0:7f16c88e4047 41 //int output_angle = 0;
helenh 0:7f16c88e4047 42 //int input_distance[WINDOWS_TIME]={0};
helenh 0:7f16c88e4047 43 //
helenh 0:7f16c88e4047 44 //
helenh 0:7f16c88e4047 45 //
helenh 0:7f16c88e4047 46 //int PID_Calculation(){
helenh 0:7f16c88e4047 47 // int velocity = (input_distance[WINDOWS_TIME] - input_distance[0]) / WINDOWS_TIME;
helenh 0:7f16c88e4047 48 //
helenh 0:7f16c88e4047 49 // int sum_distance=0;
helenh 0:7f16c88e4047 50 // for(int i = 0;i <= WINDOWS_TIME;i++){
helenh 0:7f16c88e4047 51 // sum_distance + = input_distance[i];
helenh 0:7f16c88e4047 52 // }
helenh 0:7f16c88e4047 53 //
helenh 0:7f16c88e4047 54 // int avg_distance = sum_distance / WINDOWS_TIME;
helenh 0:7f16c88e4047 55 //
helenh 0:7f16c88e4047 56 // int diff_angle = velocity * kp + avg_distance * kd;
helenh 0:7f16c88e4047 57 //
helenh 0:7f16c88e4047 58 // output_angle = diff_angle + BALANCE_ANGLE;
helenh 0:7f16c88e4047 59 //}
helenh 0:7f16c88e4047 60
helenh 2:a668eb71516b 61 //int PID_Calculation(int preset_value,int actual_value){
helenh 2:a668eb71516b 62 // int velocity = (input_distance[WINDOWS_TIME] - input_distance[0]) / WINDOWS_TIME;
helenh 2:a668eb71516b 63 //
helenh 2:a668eb71516b 64 // int sum_distance=0;
helenh 2:a668eb71516b 65 // for(int i = 0;i <= WINDOWS_TIME;i++){
helenh 2:a668eb71516b 66 // sum_distance + = input_distance[i];
helenh 2:a668eb71516b 67 // }
helenh 2:a668eb71516b 68 //
helenh 2:a668eb71516b 69 // int avg_distance = sum_distance / WINDOWS_TIME;
helenh 2:a668eb71516b 70 //
helenh 2:a668eb71516b 71 // int diff_angle = velocity * kp + avg_distance * kd;
helenh 2:a668eb71516b 72 //
helenh 2:a668eb71516b 73 // output_angle = diff_angle + BALANCE_ANGLE;
helenh 2:a668eb71516b 74 //}
helenh 2:a668eb71516b 75
helenh 2:a668eb71516b 76 /*
helenh 0:7f16c88e4047 77 float PWM_Convertion(int input_angle){
helenh 0:7f16c88e4047 78 return 2.5 + (float)input_angle/18;
helenh 2:a668eb71516b 79 }
helenh 2:a668eb71516b 80 */