This code is for making a robot in a simulator move in specific paths using C. The code of the while loop is where I need to make changes, I was wondering how to change the code so that the robot moves in a straight line and stop, and how to use 'timed distance' to make it move in a triangle.
while (1) {
sprintf(buf, "M LR 60 -60\n");
write(sock, buf, strlen(buf));
memset(buf, 0, 80);
read(sock, buf, 80);
}
M LR
is the name for the Left and Right motors in the robot(the robot has two motors that make it move) and 60 and -60 are their speeds. This code makes the robot spin.
The full code is in this link: [C Robot]
How to make this code work?
int k = 1;
for (k = 1; k < 3 ; k++){
sprintf(buf, "M LR 20 10\n");
write(sock, buf, strlen(buf));
memset(buf, 0, 80);
read(sock, buf, 80);
}
for (k=3; k > 3; k++) {
sprintf(buf, "M LR 0 0\n");
write(sock, buf, strlen(buf));
memset(buf, 0, 80);
read(sock, buf, 80);
}