下载编号:94611
##机器人转圈圈## 这个C语言小程序能够控制机器人转圈圈哦,代码很简单,就是几个个左转控制而已。
#define TRACK_1 //1?????
#define TRACK_2 //...
#define TRACK_3
#define TRACK_4
/*PID?????*/
float kp = 0,
ki = 0,
kd = 0;
/*???????PID??*/
float PID_Output(void)
{
float error,last_error; //????????
static float integral; //?????
float output; //PID??
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;
结语:上面这个小程序是不是很有趣嘞?还有更多的小程序供你探索哦!