#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#pragma warning(suppress : 4996).
int main()
{
char str[] = "$P=1.11 $I=1.12 $D=1.13";
char* token;
float P = 0, I = 0, D = 0;
token = strtok(str, "$");
while (token != NULL)
{
if (*token == 'P')
{
P = atof(token+2);
}
if (*token == 'I')
{
I = atof(token+2);
}
if (*token == 'D')
{
D = atof(token+2);
}
token = strtok(NULL, "$");
}
printf("%2f\n", P);
printf("%2f\n", I);
printf("%2f\n", D);
return (0);
}
通过串口给单片机发送PID参数供单片机解析
最新推荐文章于 2024-08-21 22:20:51 发布