以下は、ロボットをシミュレーター内で動かすための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値に新しいバッファーを設定するにはどうすればよいですか?