making a loop so it doesnt stop

This commit is contained in:
ishak jmilou.ishak
2024-10-08 13:10:03 +02:00
parent b5874dbf9e
commit 45bd2196ef

View File

@@ -15,52 +15,51 @@ int main() {
unsigned char *null_ptr(0); unsigned char *null_ptr(0);
robot.startCommunication("/dev/ttyUSB0", true, null_ptr); robot.startCommunication("/dev/ttyUSB0", true, null_ptr);
usleep(1 * 1000 * 1000); usleep(1 * 1000 * 1000);
std::cout << "choose between forward and rotate" << endl;
thread mv(command); thread mv(command);
usleep(30 * 1000 * 1000); usleep(30 * 1000 * 1000);
mv.join(); // only exit once thread one is done running mv.join(); // only exit once thread one is done running
while (true) {
command();
}
return 0;
} }
int checkCenterCliff() { int checkCenterCliff() {
while (true) { while (true) {
std::cout << "cliffsensordata:" << robot.parser.data.CliffSensorCenter << std::endl; std::cout << "cliffsensordata:" << robot.parser.data.CliffSensorCenter
<< std::endl;
} }
} }
int checkWheelDrop() { int checkWheelDrop() {
while (true) { while (true) {
std::cout << "wheeldropdata:" << robot.parser.data.WheelDropLeft << std::endl; std::cout << "wheeldropdata:" << robot.parser.data.WheelDropLeft
<< std::endl;
} }
} }
int command() { int command() {
char input; char input;
std::cout << "What must the robot do?";
std::cin >> input;
switch (input) { while (true) {
case FORWARD: { std::cout << "choose between forward and rotate" << endl;
int distance; std::cout << "What must the robot do?";
std::cout << "Enter distance to move forward: "; std::cin >> input;
std::cin >> distance;
robot.goStraight(distance);
} break;
case ROTATE: { switch (input) {
int angle; case FORWARD: {
std::cout << "Enter angle to rotate: "; int distance;
std::cin >> angle; std::cout << "Enter distance to move forward: ";
robot.doRotation(angle); std::cin >> distance;
} break; robot.goStraight(distance);
} break;
default: case ROTATE: {
cout << "Invalid input" << endl; int angle;
break; std::cout << "Enter angle to rotate: ";
std::cin >> angle;
robot.doRotation(angle);
} break;
default:
cout << "Invalid input" << endl;
break;
}
} }
} }