##PID## #define TRACK_1 // #define TRACK_2 //… #define TRACK_3 #define TRACK_4 /PID?????/ float kp = 0, ki = 0, kd = 0; float PID_Output(void) { float error,last_error; static float integral; float output; if( (TRACK_1 == 0) && (TRACK_2 == 1) && (TRACK_3 == 0) && (TRACK_4 == 0) ) //0 1 0 0 error = -1; else if( (TRACK_1 == 1) && (TRACK_2 == 1) && (TRACK_3 == 0) && (TRACK_4 == 0) ) //1 1 0 0 error = -2; else if( (TRACK_1 == 1) && (TRACK_2 == 0) && (TRACK_3 == 0) && (TRACK_4 == 0) ) //1 0 0 0 error = -3; else if( (TRACK_1 == 0) && (TRACK_2 == 0) && (TRACK_3 == 1) && (TRACK_4 == 0) ) //0 0 1 0 error = 1; else if( (TRACK_1 == 0) && (TRACK_2 == 0) && (TRACK_3 == 1) && (TRACK_4 == 1) ) //0 0 1 1 error = 2; else if( (TRACK_1 == 0) && (TRACK_2 == 0) && (TRACK_3 == 0) && (TRACK_4 == 1) ) //0 0 0 1 error = 3; else error = 0; integral += error; output = kp * error + ki * integral + kd * (error - last_error); last_error = error; return output;
结语:上面这个小程序是不是很有趣嘞?还有更多的小程序供你探索哦!
©2015 - 2024 优唯思编程   |   Copyright 2015 All Rights 成都优威骐骥教育科技有限公司  |  网站备案号:蜀ICP备16015136号