Commit d5ba197e authored by Ian McInerney's avatar Ian McInerney

Redid program exit to close thread faster

parent 56f70e4e
......@@ -35,4 +35,9 @@ extern Bridge *bridge;
void query_vrpn();
/**
* This function is registered as the handler for when Ctrl-C is pressed
*/
void ctrlc_handler(int sig);
#endif
......@@ -36,7 +36,6 @@ void sendMulticast();
void readMulticast();
void closeoutProgram();
static void ctrlc_handler(int sig) ;
double startTime = 0;
......@@ -335,7 +334,7 @@ int main(int argc, char **argv) {
/**
* This function is registered as the handler for when Ctrl-C is pressed
*/
static void ctrlc_handler(int sig) {
void ctrlc_handler(int sig) {
// Send up a flag for the threads to end
for (int i = 0; i < NUM_RADIOS; i++) {
radios[i].radio->stopThread();
......@@ -350,15 +349,13 @@ static void ctrlc_handler(int sig) {
void closeoutProgram() {
for (int i = 0; i < NUM_QUADS; i++) {
// Turn off the crazyflies
if ( crazyflie_info[i].cflieCopter->copterInRange() ) {
// Only do this if the Crazyflies are in range and responding
crazyflie_info[i].cflieCopter->setBaseThrust( 0 );
crazyflie_info[i].cflieCopter->cycle();
cout << "Battery" << i << ": " << crazyflie_info[i].cflieCopter->batteryLevel() << endl;
crazyflie_info[i].cflieCopter->cycle();
} else {
cout << "Crazyflie " << i << " Out of range" << endl;
}
cout << "Stopping crazyflie " << (i+1) << endl;
crazyflie_info[i].cflieCopter->setBaseThrust( 0 );
crazyflie_info[i].cflieCopter->cycle();
cout << "\tBattery" << ": " << crazyflie_info[i].cflieCopter->batteryLevel() << endl;
crazyflie_info[i].cflieCopter->cycle();
delete crazyflie_info[i].cflieCopter;
}
......
......@@ -42,7 +42,7 @@ void* UIThread(void *threadID) {
// Get a character from the terminal
tempbuf[counter] = getchar();
// If the characteris a newline, the command is entered
// If the character is a newline, the command is entered
if (tempbuf[counter] == '\n') {
// Add a null terminator to the buffer
tempbuf[counter] = 0;
......@@ -55,9 +55,15 @@ void* UIThread(void *threadID) {
uint8_t commandLength = strlen(tempbuf);
if ( commandLength < 2) {
// Invalid command
counter = 0;
continue;
if (tempbuf[0] == 'q') {
// Exit the program
ctrlc_handler(1);
break;
} else {
// Invalid command
counter = 0;
continue;
}
}
// Get the quadcopter number
......@@ -89,5 +95,7 @@ void* UIThread(void *threadID) {
}
usleep(1000);
}
std::cout << "Stopping thread for user input" << endl;
return NULL;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment