以下是使机器人在其模拟器中移动的 C 代码的一部分。
while (1)
{
sprintf(buf, "M LR 100 100\n"); //motor left and right moves with speed 100 each.
write(sock, buf, strlen(buf)); //sends the buffer to the socket (simulator)
int lme, rme; //lme and rme are right and left motor encoder values, the other value I need to send to buffer.
sprintf(buf, "S MELR\n"); //sensor command to find ME values
sscanf(buf, "S MELR %i %i\n", &lme, &rme); //sending the actual ME values, that need to be sent to a(nother?) buffer.
printf(buf, "lme , rme"); //the values of MEncoders.
memset(buf, 0, 80); //clear the buffer, set buffer value to 0
read(sock, buf, 80); //read from socket to get results.
}
这不起作用,因为虽然机器人以速度 100 移动,终端只显示 S MELR 并且没有电机编码器值,但它显示了 M LR 命令被移除时的值,所以我认为它与 MELR 值有关没有被发送到缓冲区。如何改进或如何为 MELR 值设置新缓冲区?