// Bakalarska prace 2017 // Sledování cloveka robotem // Frantisek Brandstyl // brandfra@fel.cvut.cz // Tento program slouzi k propojeni lokalizacniho a ridiciho programu. Vytvari dva procesy propojene pres pipe. Jeden proces ma na pipe presmerovany vstup a druhy vystup. V prvnim procesu se spousti WhyCon, ve druhem sledovaci algoritmus. Vsechny programy se ukoncuji stiskem Enter. #include #include #include #include #include #include int main(int argc, const char* argv[]) { fputs("Program has started.\n", stderr); int pipefd[2]; pid_t whyConChild; pid_t controlChild; if (pipe(pipefd) == -1) { fputs("Creating pipe failed!\n", stderr); exit(EXIT_FAILURE); } whyConChild = fork(); if (whyConChild == -1) { fputs("Creating whyConChild failed!\n", stderr); exit(EXIT_FAILURE); } if (whyConChild == 0) { // WhyCon zapisuje do pipe close(pipefd[0]); if (dup2(pipefd[1], STDOUT_FILENO) == -1) { fputs("Redirecting whyConChild output failed!\n", stderr); exit(EXIT_FAILURE); } // spusteni programu WhyCon if (execl("../whycon-master/build/whycon", "whycon", "-c", "1", "-o", "vystup1", "-x", "../whycon-master/build/calibration.xml", "-t", "1", "-n", "--no-video", "--width", "1280", "--height", "720", NULL) == -1) { fputs("Executing the WhyCon failed!\n", stderr); exit(EXIT_FAILURE); } } else { // vytvari se dalsi proces controlChild = fork(); if (controlChild == -1) { fputs("Creating controlChild failed!\n", stderr); exit(EXIT_FAILURE); } if (controlChild == 0) { // rizeni cte z pipe close(pipefd[1]); if (dup2(pipefd[0], STDIN_FILENO) == -1) { fputs("Redirecting controlChild input failed!\n", stderr); exit(EXIT_FAILURE); } // spusteni programu control if (execl("../Aria/examples/controlV2", "controlV2", "-robotPort", "/dev/ttyUSB0", NULL) == -1) { fputs("Executing the control failed!\n", stderr); exit(EXIT_FAILURE); } } else { // ukonceni programu close(pipefd[0]); close(pipefd[1]); while (getchar() != '\n'); kill(whyConChild, SIGTERM); kill(controlChild, SIGTERM); wait(NULL); } } return 0; }