added comments

This commit is contained in:
ishak jmilou.ishak
2024-10-08 13:44:08 +02:00
parent 5d11d4866b
commit c062ad30f4

View File

@@ -5,60 +5,60 @@
#include <thread>
using namespace std;
CKobuki robot;
int command();
// Globale instantie van de CKobuki-klasse
CKobuki robot;
// Functieprototypes
int command();
int checkCenterCliff();
int checkWheelDrop();
// Constante karakters voor invoeropties
const char FORWARD = '1';
const char ROTATE = '2';
int main() {
// Start communicatie met de robot
unsigned char *null_ptr(0);
robot.startCommunication("/dev/ttyUSB0", true, null_ptr);
usleep(1 * 1000 * 1000);
// Start een nieuwe thread voor de command-functie
thread mv(command);
usleep(30 * 1000 * 1000);
mv.join(); // only exit once thread one is done running
}
int checkCenterCliff() {
while (true) {
std::cout << "cliffsensordata:" << robot.parser.data.CliffSensorCenter
<< std::endl;
}
}
int checkWheelDrop() {
while (true) {
std::cout << "wheeldropdata:" << robot.parser.data.WheelDropLeft
<< std::endl;
}
mv.join(); // Wacht tot de command-thread klaar is
}
// Functie om commando's van de gebruiker te verwerken
int command() {
char input;
while (true) {
// Vraag de gebruiker om een commando
std::cout << "choose between forward = 1 or rotate = 2" << endl;
std::cout << "What must the robot do?";
std::cin >> input;
// Verwerk de invoer van de gebruiker
switch (input) {
case FORWARD: {
int distance;
std::cout << "Enter distance to move forward: ";
std::cin >> distance;
robot.goStraight(distance);
robot.goStraight(distance); // Beweeg de robot naar voren
} break;
case ROTATE: {
int angle;
std::cout << "Enter angle to rotate in degrees: ";
std::cin >> angle;
robot.doRotation(angle);
robot.doRotation(angle); // Draai de robot
} break;
default:
cout << "Invalid input" << endl;
cout << "Invalid input" << endl; // Ongeldige invoer
break;
}
}