首页 » 机器人 » C小程序 » MIC
admin
聪明的教授 Lv143    
课程作者
MIC
已学习:1443   提交:0   发表于2022-01-05 19:12:47
下载编号:94613

##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;

/****************** 填写MIC咪头初始化代码 ***************************/
Mic_Adc_Init();
XFTTS_Ctrl_GPIO_Init();
XFTTS_USART3_Init(115200);
Get_XFTTS_Conn_Status();

/**********************************************************************/
while(1)
{
/******************** 填写MIC咪头任务处理代码 *****************/
u16 GetData = GetMicSensorValue();
char chinese[30] = "adc读取的数据为";
char data[5];

data[0] = GetData/1000 + 48;
GetData = GetData-(GetData/1000)*1000;
data[1] = GetData/100 + 48;
GetData = GetData-(GetData/100)*100;
data[2] = GetData/10 + 48;
GetData = GetData-(GetData/10)*10;
data[3] = GetData + 48;
data[4] = '\0';

strcat(chinese, data);

if(GetXFTTSStatus() == 0)
SendTextToXFTTS(chinese, 0);




OSTimeDlyHMSM(0, 0, 10, 0);
/*******************************************************************/
} }

结语:上面这个小程序是不是很有趣嘞?还有更多的小程序供你探索哦!

优唯思教育机器人,你所有的问题在我这儿都能得到解决! 
学习列表
默认   热门   正序   倒序
暂无班级信息
等级:0级
优币:
好奇少年:
最新作业
左邻右舍
{"竞赛编程":"http://www.uwis.cn/uide/","课程编辑":"http://www.135editor.com/","成信大":"http://www.cuit.edu.cn","老版优唯思":"http://old.uwis.cn","图文发帖":"http://yz.uwis.cn/index.php?c=edit&type=read&pyteditorload=no"}

©2015 - 2024 优唯思编程   |   Copyright 2015 All Rights 成都优威骐骥教育科技有限公司  |  网站备案号:蜀ICP备16015136号

已有0次打赏