|
|
@ -19,17 +19,17 @@
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
|
|
|
|
// Déclaration des priorités des taches
|
|
|
|
// Déclaration des priorités des taches
|
|
|
|
#define PRIORITY_TSERVER 30
|
|
|
|
#define PRIORITY_TSERVER 10
|
|
|
|
#define PRIORITY_TOPENCOMROBOT 20
|
|
|
|
#define PRIORITY_TOPENCOMROBOT 50
|
|
|
|
#define PRIORITY_TMOVE 20
|
|
|
|
#define PRIORITY_TMOVE 20
|
|
|
|
#define PRIORITY_TSENDTOMON 22
|
|
|
|
#define PRIORITY_TSENDTOMON 22
|
|
|
|
#define PRIORITY_TRECEIVEFROMMON 25
|
|
|
|
#define PRIORITY_TRECEIVEFROMMON 50
|
|
|
|
#define PRIORITY_TSTARTROBOTWITHOUTWATCHDOG 22
|
|
|
|
#define PRIORITY_TSTARTROBOTWITHOUTWATCHDOG 22
|
|
|
|
#define PRIORITY_TSTARTROBOTWITHWATCHDOG 22
|
|
|
|
#define PRIORITY_TSTARTROBOTWITHWATCHDOG 22
|
|
|
|
#define PRIORITY_TCAMERA 21
|
|
|
|
#define PRIORITY_TCAMERA 21
|
|
|
|
|
|
|
|
#define PRIORITY_DETECTLOSTSUPROB 21
|
|
|
|
#define PRIORITY_TVISION 26
|
|
|
|
#define PRIORITY_TVISION 26
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Some remarks:
|
|
|
|
* Some remarks:
|
|
|
|
* 1- This program is mostly a template. It shows you how to create tasks, semaphore
|
|
|
|
* 1- This program is mostly a template. It shows you how to create tasks, semaphore
|
|
|
@ -146,21 +146,21 @@ void Tasks::Init() {
|
|
|
|
cerr << "Error semaphore create: " << strerror(-err) << endl << flush;
|
|
|
|
cerr << "Error semaphore create: " << strerror(-err) << endl << flush;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (err = rt_sem_create(&sem_askBattery, NULL, 0, S_FIFO)) {
|
|
|
|
|
|
|
|
cerr << "Error semaphore create: " << strerror(-err) << endl << flush;
|
|
|
|
if (err = rt_sem_create(&sem_detectLostSupRob, NULL, 0, S_FIFO)) {
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err = rt_sem_create(&sem_allowStartReceive, NULL, 0, S_FIFO)) {
|
|
|
|
|
|
|
|
cerr << "Error semaphore create: " << strerror(-err) << endl << flush;
|
|
|
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err = rt_sem_create(&sem_allowStartCapture, NULL, 0, S_FIFO)) {
|
|
|
|
|
|
|
|
cerr << "Error semaphore create: " << strerror(-err) << endl << flush;
|
|
|
|
cerr << "Error semaphore create: " << strerror(-err) << endl << flush;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Initialization for some specific sem: Allow to run the first time
|
|
|
|
if (err = rt_sem_create(&sem_askBattery, NULL, 0, S_FIFO)) {
|
|
|
|
rt_sem_v(&sem_allowStartReceive);
|
|
|
|
cerr << "Error semaphore create: " << strerror(-err) << endl << flush;
|
|
|
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (err = rt_sem_create(&sem_restart, NULL, 0, S_FIFO)) {
|
|
|
|
|
|
|
|
cerr << "Error semaphore create: " << strerror(-err) << endl << flush;
|
|
|
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cout << "Semaphores created successfully" << endl << flush;
|
|
|
|
cout << "Semaphores created successfully" << endl << flush;
|
|
|
|
|
|
|
|
|
|
|
@ -168,31 +168,36 @@ void Tasks::Init() {
|
|
|
|
/* Tasks creation */
|
|
|
|
/* Tasks creation */
|
|
|
|
/**************************************************************************************/
|
|
|
|
/**************************************************************************************/
|
|
|
|
if (err = rt_task_create(&th_server, "th_server", 0, PRIORITY_TSERVER, 0)) {
|
|
|
|
if (err = rt_task_create(&th_server, "th_server", 0, PRIORITY_TSERVER, 0)) {
|
|
|
|
cerr << "Error task create: " << strerror(-err) << endl << flush;
|
|
|
|
cerr << "Error task create server: " << strerror(-err) << endl << flush;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (err = rt_task_create(&th_sendToMon, "th_sendToMon", 0, PRIORITY_TSENDTOMON, 0)) {
|
|
|
|
if (err = rt_task_create(&th_sendToMon, "th_sendToMon", 0, PRIORITY_TSENDTOMON, 0)) {
|
|
|
|
cerr << "Error task create: " << strerror(-err) << endl << flush;
|
|
|
|
cerr << "Error task create sendtoMon: " << strerror(-err) << endl << flush;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (err = rt_task_create(&th_receiveFromMon, "th_receiveFromMon", 0, PRIORITY_TRECEIVEFROMMON, 0)) {
|
|
|
|
if (err = rt_task_create(&th_receiveFromMon, "th_receiveFromMon", 0, PRIORITY_TRECEIVEFROMMON, 0)) {
|
|
|
|
cerr << "Error task create: " << strerror(-err) << endl << flush;
|
|
|
|
cerr << "Error task create receiveFromMon: " << strerror(-err) << endl << flush;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (err = rt_task_create(&th_openComRobot, "th_openComRobot", 0, PRIORITY_TOPENCOMROBOT, 0)) {
|
|
|
|
if (err = rt_task_create(&th_openComRobot, "th_openComRobot", 0, PRIORITY_TOPENCOMROBOT, 0)) {
|
|
|
|
cerr << "Error task create: " << strerror(-err) << endl << flush;
|
|
|
|
cerr << "Error task create openComRobot: " << strerror(-err) << endl << flush;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (err = rt_task_create(&th_startRobotWithoutWatchdog, "th_startRobotWithoutWatchdog", 0, PRIORITY_TSTARTROBOTWITHOUTWATCHDOG, 0)) {
|
|
|
|
if (err = rt_task_create(&th_startRobotWithoutWatchdog, "th_startRobotWithoutWatchdog", 0, PRIORITY_TSTARTROBOTWITHOUTWATCHDOG, 0)) {
|
|
|
|
cerr << "Error task create: " << strerror(-err) << endl << flush;
|
|
|
|
cerr << "Error task create startRobotWithoutWatchdog: " << strerror(-err) << endl << flush;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (err = rt_task_create(&th_startRobotWithWatchdog, "th_startRobotWithWatchdog", 0, PRIORITY_TSTARTROBOTWITHWATCHDOG, 0)) {
|
|
|
|
if (err = rt_task_create(&th_startRobotWithWatchdog, "th_startRobotWithWatchdog", 0, PRIORITY_TSTARTROBOTWITHWATCHDOG, 0)) {
|
|
|
|
cerr << "Error task create: " << strerror(-err) << endl << flush;
|
|
|
|
cerr << "Error task create startRobotWithWatchdog: " << strerror(-err) << endl << flush;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (err = rt_task_create(&th_move, "th_move", 0, PRIORITY_TMOVE, 0)) {
|
|
|
|
if (err = rt_task_create(&th_move, "th_move", 0, PRIORITY_TMOVE, 0)) {
|
|
|
|
cerr << "Error task create: " << strerror(-err) << endl << flush;
|
|
|
|
cerr << "Error task create move: " << strerror(-err) << endl << flush;
|
|
|
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (err = rt_task_create(&th_detectLostSupRob, "th_detectLostSupRob", 0, PRIORITY_DETECTLOSTSUPROB, 0)) {
|
|
|
|
|
|
|
|
cerr << "Error task create detectLostSupRob: " << strerror(-err) << endl << flush;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (err = rt_task_create(&th_askBattery, "th_askBattery", 0, PRIORITY_TMOVE, 0)) {
|
|
|
|
if (err = rt_task_create(&th_askBattery, "th_askBattery", 0, PRIORITY_TMOVE, 0)) {
|
|
|
@ -220,37 +225,46 @@ void Tasks::Init() {
|
|
|
|
* @brief Démarrage des tâches
|
|
|
|
* @brief Démarrage des tâches
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void Tasks::Run() {
|
|
|
|
void Tasks::Run() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cout << "Coucou" << endl << flush;
|
|
|
|
|
|
|
|
|
|
|
|
rt_task_set_priority(NULL, T_LOPRIO);
|
|
|
|
rt_task_set_priority(NULL, T_LOPRIO);
|
|
|
|
int err;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
|
|
if (err = rt_task_start(&th_server, (void(*)(void*)) & Tasks::ServerTask, this)) {
|
|
|
|
if (err = rt_task_start(&th_server, (void(*)(void*)) & Tasks::ServerTask, this)) {
|
|
|
|
cerr << "Error task start: " << strerror(-err) << endl << flush;
|
|
|
|
cerr << "Error task start server: " << strerror(-err) << endl << flush;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (err = rt_task_start(&th_sendToMon, (void(*)(void*)) & Tasks::SendToMonTask, this)) {
|
|
|
|
if (err = rt_task_start(&th_sendToMon, (void(*)(void*)) & Tasks::SendToMonTask, this)) {
|
|
|
|
cerr << "Error task start: " << strerror(-err) << endl << flush;
|
|
|
|
cerr << "Error task start sendToMon: " << strerror(-err) << endl << flush;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (err = rt_task_start(&th_receiveFromMon, (void(*)(void*)) & Tasks::ReceiveFromMonTask, this)) {
|
|
|
|
if (err = rt_task_start(&th_receiveFromMon, (void(*)(void*)) & Tasks::ReceiveFromMonTask, this)) {
|
|
|
|
cerr << "Error task start: " << strerror(-err) << endl << flush;
|
|
|
|
cerr << "Error task start receiveFromMon: " << strerror(-err) << endl << flush;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (err = rt_task_start(&th_openComRobot, (void(*)(void*)) & Tasks::OpenComRobot, this)) {
|
|
|
|
if (err = rt_task_start(&th_openComRobot, (void(*)(void*)) & Tasks::OpenComRobot, this)) {
|
|
|
|
cerr << "Error task start: " << strerror(-err) << endl << flush;
|
|
|
|
cerr << "Error task start openComRobot: " << strerror(-err) << endl << flush;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (err = rt_task_start(&th_startRobotWithoutWatchdog, (void(*)(void*)) & Tasks::StartRobotTaskWithoutWatchdog, this)) {
|
|
|
|
if (err = rt_task_start(&th_startRobotWithoutWatchdog, (void(*)(void*)) & Tasks::StartRobotTaskWithoutWatchdog, this)) {
|
|
|
|
cerr << "Error task start: " << strerror(-err) << endl << flush;
|
|
|
|
cerr << "Error task start startRobotWithoutWatchdog: " << strerror(-err) << endl << flush;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (err = rt_task_start(&th_startRobotWithWatchdog, (void(*)(void*)) & Tasks::StartRobotTaskWithWatchdog, this)) {
|
|
|
|
if (err = rt_task_start(&th_startRobotWithWatchdog, (void(*)(void*)) & Tasks::StartRobotTaskWithWatchdog, this)) {
|
|
|
|
cerr << "Error task start: " << strerror(-err) << endl << flush;
|
|
|
|
cerr << "Error task start startRobotWithWatchdog: " << strerror(-err) << endl << flush;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (err = rt_task_start(&th_move, (void(*)(void*)) & Tasks::MoveTask, this)) {
|
|
|
|
if (err = rt_task_start(&th_move, (void(*)(void*)) & Tasks::MoveTask, this)) {
|
|
|
|
cerr << "Error task start: " << strerror(-err) << endl << flush;
|
|
|
|
cerr << "Error task start move: " << strerror(-err) << endl << flush;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (err = rt_task_start(&th_detectLostSupRob, (void(*)(void*)) & Tasks::DetectLostSupRob, this)) {
|
|
|
|
|
|
|
|
cerr << "Error task start detectLostSupRob: " << strerror(-err) << endl << flush;
|
|
|
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (err = rt_task_start(&th_askBattery, (void(*)(void*)) & Tasks::AskBattery, this)) {
|
|
|
|
if (err = rt_task_start(&th_askBattery, (void(*)(void*)) & Tasks::AskBattery, this)) {
|
|
|
|
cerr << "Error task start: " << strerror(-err) << endl << flush;
|
|
|
|
cerr << "Error task start: " << strerror(-err) << endl << flush;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
@ -275,6 +289,10 @@ void Tasks::Stop() {
|
|
|
|
void Tasks::Join() {
|
|
|
|
void Tasks::Join() {
|
|
|
|
cout << "Tasks synchronized" << endl << flush;
|
|
|
|
cout << "Tasks synchronized" << endl << flush;
|
|
|
|
rt_sem_broadcast(&sem_barrier);
|
|
|
|
rt_sem_broadcast(&sem_barrier);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Initialization for some specific sem: Allow to run the first time
|
|
|
|
|
|
|
|
//rt_sem_broadcast(&sem_restart);
|
|
|
|
|
|
|
|
|
|
|
|
pause();
|
|
|
|
pause();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -285,6 +303,8 @@ void Tasks::ServerTask(void *arg) {
|
|
|
|
int status;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
|
|
|
|
cout << "Start " << __PRETTY_FUNCTION__ << endl << flush;
|
|
|
|
cout << "Start " << __PRETTY_FUNCTION__ << endl << flush;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while(1){
|
|
|
|
// Synchronization barrier (waiting that all tasks are started)
|
|
|
|
// Synchronization barrier (waiting that all tasks are started)
|
|
|
|
rt_sem_p(&sem_barrier, TM_INFINITE);
|
|
|
|
rt_sem_p(&sem_barrier, TM_INFINITE);
|
|
|
|
|
|
|
|
|
|
|
@ -303,6 +323,7 @@ void Tasks::ServerTask(void *arg) {
|
|
|
|
monitor.AcceptClient(); // Wait the monitor client
|
|
|
|
monitor.AcceptClient(); // Wait the monitor client
|
|
|
|
cout << "Rock'n'Roll baby, client accepted!" << endl << flush;
|
|
|
|
cout << "Rock'n'Roll baby, client accepted!" << endl << flush;
|
|
|
|
rt_sem_broadcast(&sem_serverOk);
|
|
|
|
rt_sem_broadcast(&sem_serverOk);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -310,23 +331,41 @@ void Tasks::ServerTask(void *arg) {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void Tasks::SendToMonTask(void* arg) {
|
|
|
|
void Tasks::SendToMonTask(void* arg) {
|
|
|
|
Message *msg;
|
|
|
|
Message *msg;
|
|
|
|
|
|
|
|
bool kill_sendToMonOk=0;
|
|
|
|
|
|
|
|
|
|
|
|
cout << "Start " << __PRETTY_FUNCTION__ << endl << flush;
|
|
|
|
cout << "Start " << __PRETTY_FUNCTION__ << endl << flush;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while(1){
|
|
|
|
// Synchronization barrier (waiting that all tasks are starting)
|
|
|
|
// Synchronization barrier (waiting that all tasks are starting)
|
|
|
|
rt_sem_p(&sem_barrier, TM_INFINITE);
|
|
|
|
rt_sem_p(&sem_barrier, TM_INFINITE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************************/
|
|
|
|
/**************************************************************************************/
|
|
|
|
/* The task sendToMon starts here */
|
|
|
|
/* The task sendToMon starts here */
|
|
|
|
/**************************************************************************************/
|
|
|
|
/**************************************************************************************/
|
|
|
|
rt_sem_p(&sem_serverOk, TM_INFINITE);
|
|
|
|
rt_sem_p(&sem_serverOk, TM_INFINITE);
|
|
|
|
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
//Initialize the loop condition
|
|
|
|
|
|
|
|
kill_sendToMonOk=0;
|
|
|
|
|
|
|
|
rt_mutex_acquire(&mutex_killSendMon, TM_INFINITE);
|
|
|
|
|
|
|
|
killSendMon=0; // The message is deleted with the Write
|
|
|
|
|
|
|
|
rt_mutex_release(&mutex_killSendMon);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (!kill_sendToMonOk) {
|
|
|
|
cout << "wait msg to send" << endl << flush;
|
|
|
|
cout << "wait msg to send" << endl << flush;
|
|
|
|
msg = ReadInQueue(&q_messageToMon);
|
|
|
|
msg = ReadInQueue(&q_messageToMon);
|
|
|
|
cout << "Send msg to mon: " << msg->ToString() << endl << flush;
|
|
|
|
cout << "Send msg to mon: " << msg->ToString() << endl << flush;
|
|
|
|
rt_mutex_acquire(&mutex_monitor, TM_INFINITE);
|
|
|
|
rt_mutex_acquire(&mutex_monitor, TM_INFINITE);
|
|
|
|
monitor.Write(msg); // The message is deleted with the Write
|
|
|
|
monitor.Write(msg); // The message is deleted with the Write
|
|
|
|
rt_mutex_release(&mutex_monitor);
|
|
|
|
rt_mutex_release(&mutex_monitor);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rt_mutex_acquire(&mutex_killSendMon, TM_INFINITE);
|
|
|
|
|
|
|
|
kill_sendToMonOk=killSendMon; // The message is deleted with the Write
|
|
|
|
|
|
|
|
rt_mutex_release(&mutex_killSendMon);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cout << "SendToMon Task dies" << endl << flush;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -336,17 +375,19 @@ void Tasks::SendToMonTask(void* arg) {
|
|
|
|
void Tasks::ReceiveFromMonTask(void *arg) {
|
|
|
|
void Tasks::ReceiveFromMonTask(void *arg) {
|
|
|
|
Message *msgRcv;
|
|
|
|
Message *msgRcv;
|
|
|
|
bool killReceiveFromMonOk=0;
|
|
|
|
bool killReceiveFromMonOk=0;
|
|
|
|
|
|
|
|
int status;
|
|
|
|
|
|
|
|
|
|
|
|
cout << "Start " << __PRETTY_FUNCTION__ << endl << flush;
|
|
|
|
cout << "Start " << __PRETTY_FUNCTION__ << endl << flush;
|
|
|
|
|
|
|
|
|
|
|
|
// Synchronization barrier (waiting that all tasks are starting)
|
|
|
|
// Synchronization barrier (waiting that all tasks are starting)
|
|
|
|
rt_sem_p(&sem_barrier, TM_INFINITE);
|
|
|
|
rt_sem_p(&sem_barrier, TM_INFINITE);
|
|
|
|
|
|
|
|
|
|
|
|
//Wait twin task to die if not first round
|
|
|
|
while(1){
|
|
|
|
rt_sem_p(&sem_allowStartReceive, TM_INFINITE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Reinitialize control boolean
|
|
|
|
//Reinitialize control boolean
|
|
|
|
|
|
|
|
killReceiveFromMonOk = 0;
|
|
|
|
rt_mutex_acquire(&mutex_killReceiveFromMon, TM_INFINITE);
|
|
|
|
rt_mutex_acquire(&mutex_killReceiveFromMon, TM_INFINITE);
|
|
|
|
killReceiveFromMon=0;
|
|
|
|
killReceiveFromMon = 0;
|
|
|
|
rt_mutex_release(&mutex_killReceiveFromMon);
|
|
|
|
rt_mutex_release(&mutex_killReceiveFromMon);
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************************/
|
|
|
|
/**************************************************************************************/
|
|
|
@ -354,14 +395,13 @@ void Tasks::ReceiveFromMonTask(void *arg) {
|
|
|
|
/**************************************************************************************/
|
|
|
|
/**************************************************************************************/
|
|
|
|
rt_sem_p(&sem_serverOk, TM_INFINITE);
|
|
|
|
rt_sem_p(&sem_serverOk, TM_INFINITE);
|
|
|
|
cout << "Received message from monitor activated" << endl << flush;
|
|
|
|
cout << "Received message from monitor activated" << endl << flush;
|
|
|
|
|
|
|
|
|
|
|
|
while (!killReceiveFromMonOk) {
|
|
|
|
while (!killReceiveFromMonOk) {
|
|
|
|
msgRcv = monitor.Read();
|
|
|
|
msgRcv = monitor.Read();
|
|
|
|
cout << "Rcv <= " << msgRcv->ToString() << endl << flush;
|
|
|
|
cout << "Rcv <= " << msgRcv->ToString() << endl << flush;
|
|
|
|
|
|
|
|
|
|
|
|
if (msgRcv->CompareID(MESSAGE_MONITOR_LOST)) {
|
|
|
|
if (msgRcv->CompareID(MESSAGE_MONITOR_LOST)) {
|
|
|
|
delete(msgRcv);
|
|
|
|
|
|
|
|
cout << "Connection to monitor lost" << endl;
|
|
|
|
cout << "Connection to monitor lost" << endl;
|
|
|
|
monitor.Close();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rt_mutex_acquire(&mutex_killReceiveFromMon, TM_INFINITE);
|
|
|
|
rt_mutex_acquire(&mutex_killReceiveFromMon, TM_INFINITE);
|
|
|
|
killReceiveFromMon=1;
|
|
|
|
killReceiveFromMon=1;
|
|
|
@ -374,37 +414,81 @@ void Tasks::ReceiveFromMonTask(void *arg) {
|
|
|
|
rt_mutex_acquire(&mutex_killSendMon, TM_INFINITE);
|
|
|
|
rt_mutex_acquire(&mutex_killSendMon, TM_INFINITE);
|
|
|
|
killSendMon=1;
|
|
|
|
killSendMon=1;
|
|
|
|
rt_mutex_release(&mutex_killSendMon);
|
|
|
|
rt_mutex_release(&mutex_killSendMon);
|
|
|
|
|
|
|
|
//Write fake message in queue to unblock Read function
|
|
|
|
|
|
|
|
WriteInQueue(&q_messageToMon, new Message(MESSAGE_EMPTY));
|
|
|
|
|
|
|
|
|
|
|
|
rt_mutex_acquire(&mutex_killBattery, TM_INFINITE);
|
|
|
|
rt_mutex_acquire(&mutex_killBattery, TM_INFINITE);
|
|
|
|
killBattery=1;
|
|
|
|
killBattery=1;
|
|
|
|
rt_mutex_release(&mutex_killBattery);
|
|
|
|
rt_mutex_release(&mutex_killBattery);
|
|
|
|
|
|
|
|
|
|
|
|
rt_mutex_acquire(&mutex_killDetectLostSupRob, TM_INFINITE);
|
|
|
|
rt_mutex_acquire(&mutex_killDetectLostSupRob, TM_INFINITE);
|
|
|
|
killDetectlostSupRob=1;
|
|
|
|
killDetectLostSupRob=1;
|
|
|
|
rt_mutex_release(&mutex_killDetectLostSupRob);
|
|
|
|
rt_mutex_release(&mutex_killDetectLostSupRob);
|
|
|
|
|
|
|
|
|
|
|
|
rt_mutex_acquire(&mutex_acquireImage, TM_INFINITE);
|
|
|
|
rt_mutex_acquire(&mutex_acquireImage, TM_INFINITE);
|
|
|
|
acquireImage=0;
|
|
|
|
acquireImage=0;
|
|
|
|
rt_mutex_release(&mutex_acquireImage);
|
|
|
|
rt_mutex_release(&mutex_acquireImage);
|
|
|
|
|
|
|
|
|
|
|
|
//exit(-1);
|
|
|
|
rt_mutex_acquire(&mutex_robotStarted, TM_INFINITE);
|
|
|
|
|
|
|
|
robotStarted=0;
|
|
|
|
|
|
|
|
rt_mutex_release(&mutex_robotStarted);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Wait every task to die
|
|
|
|
|
|
|
|
sleep(1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rt_mutex_acquire(&mutex_robot, TM_INFINITE);
|
|
|
|
|
|
|
|
status=robot.Close();
|
|
|
|
|
|
|
|
rt_mutex_release(&mutex_robot);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(status<0){
|
|
|
|
|
|
|
|
cout << "Close Robot Fail" << endl << flush;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
cout << "Close Robot Success" << endl << flush;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//All closes
|
|
|
|
|
|
|
|
rt_mutex_acquire(&mutex_monitor, TM_INFINITE);
|
|
|
|
|
|
|
|
monitor.Close();
|
|
|
|
|
|
|
|
rt_mutex_release(&mutex_monitor);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Release restarted tasks
|
|
|
|
|
|
|
|
rt_sem_broadcast(&sem_barrier);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (msgRcv->CompareID(MESSAGE_CAM_OPEN)) {
|
|
|
|
} else if (msgRcv->CompareID(MESSAGE_CAM_OPEN)) {
|
|
|
|
cout << "Command Open Camera Received" << endl << flush;
|
|
|
|
cout << "Command Open Camera Received" << endl << flush;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//start task Vision
|
|
|
|
//start task Vision
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (msgRcv->CompareID(MESSAGE_CAM_CLOSE)) {
|
|
|
|
|
|
|
|
cout << "Command Close Camera Received" << endl << flush;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Trigger killVision
|
|
|
|
|
|
|
|
rt_mutex_acquire(&mutex_killVision, TM_INFINITE);
|
|
|
|
|
|
|
|
killVision=1;
|
|
|
|
|
|
|
|
rt_mutex_release(&mutex_killVision);
|
|
|
|
|
|
|
|
|
|
|
|
} else if (msgRcv->CompareID(MESSAGE_ROBOT_COM_OPEN)) {
|
|
|
|
} else if (msgRcv->CompareID(MESSAGE_ROBOT_COM_OPEN)) {
|
|
|
|
cout << "Command Open Communication with Robot Received" << endl << flush;
|
|
|
|
cout << "Command Open Communication with Robot Received" << endl << flush;
|
|
|
|
rt_sem_v(&sem_openComRobot);
|
|
|
|
rt_sem_v(&sem_openComRobot);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (msgRcv->CompareID(MESSAGE_ROBOT_COM_CLOSE)) {
|
|
|
|
|
|
|
|
cout << "Command Close Communication with Robot Received" << endl << flush;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rt_mutex_acquire(&mutex_robot, TM_INFINITE);
|
|
|
|
|
|
|
|
status=robot.Close();
|
|
|
|
|
|
|
|
rt_mutex_release(&mutex_robot);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (msgRcv->CompareID(MESSAGE_ROBOT_START_WITHOUT_WD)) {
|
|
|
|
} else if (msgRcv->CompareID(MESSAGE_ROBOT_START_WITHOUT_WD)) {
|
|
|
|
cout << "Command Start Robot without Watchdog Received" << endl << flush;
|
|
|
|
cout << "Command Start Robot without Watchdog Received" << endl << flush;
|
|
|
|
rt_sem_v(&sem_startRobotWithoutWatchdog);
|
|
|
|
rt_sem_v(&sem_startRobotWithoutWatchdog);
|
|
|
|
|
|
|
|
|
|
|
|
} else if (msgRcv->CompareID(MESSAGE_ROBOT_START_WITH_WD)) {
|
|
|
|
} else if (msgRcv->CompareID(MESSAGE_ROBOT_START_WITH_WD)) {
|
|
|
|
cout << "Command Start Robot with Watchdog Received" << endl << flush;
|
|
|
|
cout << "Command Start Robot with Watchdog Received" << endl << flush;
|
|
|
|
rt_sem_v(&sem_startRobotWithWatchdog);
|
|
|
|
//start task robot with watchdog
|
|
|
|
|
|
|
|
|
|
|
|
} else if (msgRcv->CompareID(MESSAGE_CAM_ASK_ARENA)) {
|
|
|
|
} else if (msgRcv->CompareID(MESSAGE_CAM_ASK_ARENA)) {
|
|
|
|
cout << "Command Search Arena Received" << endl << flush;
|
|
|
|
cout << "Command Search Arena Received" << endl << flush;
|
|
|
@ -413,7 +497,7 @@ void Tasks::ReceiveFromMonTask(void *arg) {
|
|
|
|
rt_mutex_release(&mutex_searchArena);
|
|
|
|
rt_mutex_release(&mutex_searchArena);
|
|
|
|
|
|
|
|
|
|
|
|
} else if (msgRcv->CompareID(MESSAGE_CAM_POSITION_COMPUTE_START)) {
|
|
|
|
} else if (msgRcv->CompareID(MESSAGE_CAM_POSITION_COMPUTE_START)) {
|
|
|
|
cout << "Command Get Root Position Received" << endl << flush;
|
|
|
|
cout << "Command Get Robot Position Received" << endl << flush;
|
|
|
|
rt_mutex_acquire(&mutex_getPosition, TM_INFINITE);
|
|
|
|
rt_mutex_acquire(&mutex_getPosition, TM_INFINITE);
|
|
|
|
getPosition=1;
|
|
|
|
getPosition=1;
|
|
|
|
rt_mutex_release(&mutex_getPosition);
|
|
|
|
rt_mutex_release(&mutex_getPosition);
|
|
|
@ -447,6 +531,7 @@ void Tasks::ReceiveFromMonTask(void *arg) {
|
|
|
|
rt_mutex_acquire(&mutex_acquireImage, TM_INFINITE);
|
|
|
|
rt_mutex_acquire(&mutex_acquireImage, TM_INFINITE);
|
|
|
|
acquireImage=1;
|
|
|
|
acquireImage=1;
|
|
|
|
rt_mutex_release(&mutex_acquireImage);
|
|
|
|
rt_mutex_release(&mutex_acquireImage);
|
|
|
|
|
|
|
|
|
|
|
|
} else if (msgRcv->CompareID(MESSAGE_ROBOT_GO_FORWARD) ||
|
|
|
|
} else if (msgRcv->CompareID(MESSAGE_ROBOT_GO_FORWARD) ||
|
|
|
|
msgRcv->CompareID(MESSAGE_ROBOT_GO_BACKWARD) ||
|
|
|
|
msgRcv->CompareID(MESSAGE_ROBOT_GO_BACKWARD) ||
|
|
|
|
msgRcv->CompareID(MESSAGE_ROBOT_GO_LEFT) ||
|
|
|
|
msgRcv->CompareID(MESSAGE_ROBOT_GO_LEFT) ||
|
|
|
@ -460,13 +545,14 @@ void Tasks::ReceiveFromMonTask(void *arg) {
|
|
|
|
delete(msgRcv); // must be deleted manually, no consumer
|
|
|
|
delete(msgRcv); // must be deleted manually, no consumer
|
|
|
|
|
|
|
|
|
|
|
|
//Update loop condition
|
|
|
|
//Update loop condition
|
|
|
|
rt_mutex_acquire(&mutex_killReceiveFromMon, TM_INFINITE);
|
|
|
|
|
|
|
|
killReceiveFromMonOk=killReceiveFromMon;
|
|
|
|
|
|
|
|
rt_mutex_release(&mutex_killReceiveFromMon);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rt_mutex_acquire(&mutex_killReceiveFromMon, TM_INFINITE);
|
|
|
|
|
|
|
|
killReceiveFromMonOk = killReceiveFromMon;
|
|
|
|
|
|
|
|
rt_mutex_release(&mutex_killReceiveFromMon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
rt_sem_v(&sem_allowStartReceive);
|
|
|
|
cout << "ReceiveFromMon dies" << endl << flush;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -475,9 +561,10 @@ void Tasks::ReceiveFromMonTask(void *arg) {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @brief Thread opening communication with the robot.
|
|
|
|
* @brief Thread opening communication with the robot.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void Tasks::OpenComRobot(void *arg) {
|
|
|
|
void Tasks::OpenComRobot(void *arg) { //PAS DE SOUCIS AU REDEMARAGE
|
|
|
|
int status;
|
|
|
|
int status;
|
|
|
|
int err;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
//bool killOpenComRobotOk = 0;
|
|
|
|
|
|
|
|
|
|
|
|
cout << "Start " << __PRETTY_FUNCTION__ << endl << flush;
|
|
|
|
cout << "Start " << __PRETTY_FUNCTION__ << endl << flush;
|
|
|
|
// Synchronization barrier (waiting that all tasks are starting)
|
|
|
|
// Synchronization barrier (waiting that all tasks are starting)
|
|
|
@ -502,6 +589,10 @@ void Tasks::OpenComRobot(void *arg) {
|
|
|
|
msgSend = new Message(MESSAGE_ANSWER_ACK);
|
|
|
|
msgSend = new Message(MESSAGE_ANSWER_ACK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WriteInQueue(&q_messageToMon, msgSend); // msgSend will be deleted by sendToMon
|
|
|
|
WriteInQueue(&q_messageToMon, msgSend); // msgSend will be deleted by sendToMon
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Trigger Detection of Communication Loss with Robot
|
|
|
|
|
|
|
|
rt_sem_v(&sem_detectLostSupRob);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -516,14 +607,16 @@ void Tasks::OpenComRobot(void *arg) {
|
|
|
|
* @brief Thread starting the communication with the robot.
|
|
|
|
* @brief Thread starting the communication with the robot.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void Tasks::StartRobotTaskWithoutWatchdog(void *arg) {
|
|
|
|
void Tasks::StartRobotTaskWithoutWatchdog(void *arg) {
|
|
|
|
cout << "Start " << __PRETTY_FUNCTION__ << endl << flush;
|
|
|
|
|
|
|
|
// Synchronization barrier (waiting that all tasks are starting)
|
|
|
|
|
|
|
|
rt_sem_p(&sem_barrier, TM_INFINITE);
|
|
|
|
|
|
|
|
int killBatteryOk=0;
|
|
|
|
int killBatteryOk=0;
|
|
|
|
Message * msgSend;
|
|
|
|
Message * msgSend;
|
|
|
|
/**************************************************************************************/
|
|
|
|
/**************************************************************************************/
|
|
|
|
/* The task startRobot starts here */
|
|
|
|
/* The task startRobot starts here */
|
|
|
|
/**************************************************************************************/
|
|
|
|
/**************************************************************************************/
|
|
|
|
|
|
|
|
while(1){
|
|
|
|
|
|
|
|
cout << "Start " << __PRETTY_FUNCTION__ << endl << flush;
|
|
|
|
|
|
|
|
// Synchronization barrier (waiting that all tasks are starting)
|
|
|
|
|
|
|
|
rt_sem_p(&sem_barrier, TM_INFINITE);
|
|
|
|
//Boolean to get the battery
|
|
|
|
//Boolean to get the battery
|
|
|
|
rt_mutex_acquire(&mutex_killBattery, TM_INFINITE);
|
|
|
|
rt_mutex_acquire(&mutex_killBattery, TM_INFINITE);
|
|
|
|
killBatteryOk=0;
|
|
|
|
killBatteryOk=0;
|
|
|
@ -551,6 +644,7 @@ void Tasks::StartRobotTaskWithoutWatchdog(void *arg) {
|
|
|
|
rt_mutex_release(&mutex_killBattery);
|
|
|
|
rt_mutex_release(&mutex_killBattery);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -560,24 +654,34 @@ void Tasks::StartRobotTaskWithoutWatchdog(void *arg) {
|
|
|
|
* @brief Thread starting the communication with the robot.
|
|
|
|
* @brief Thread starting the communication with the robot.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void Tasks::StartRobotTaskWithWatchdog(void *arg) {
|
|
|
|
void Tasks::StartRobotTaskWithWatchdog(void *arg) {
|
|
|
|
cout << "Start " << __PRETTY_FUNCTION__ << endl << flush;
|
|
|
|
|
|
|
|
// Synchronization barrier (waiting that all tasks are starting)
|
|
|
|
|
|
|
|
rt_sem_p(&sem_barrier, TM_INFINITE);
|
|
|
|
|
|
|
|
int killBatteryOk=0;
|
|
|
|
int killBatteryOk=0;
|
|
|
|
int cpt=1;
|
|
|
|
int cpt=1;
|
|
|
|
Message * msgSend;
|
|
|
|
Message * msgSend;
|
|
|
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while(1){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cout << "Start " << __PRETTY_FUNCTION__ << endl << flush;
|
|
|
|
|
|
|
|
// Synchronization barrier (waiting that all tasks are starting)
|
|
|
|
|
|
|
|
rt_sem_p(&sem_barrier, TM_INFINITE);
|
|
|
|
/**************************************************************************************/
|
|
|
|
/**************************************************************************************/
|
|
|
|
/* The task startRobot starts here */
|
|
|
|
/* The task startRobot starts here */
|
|
|
|
/**************************************************************************************/
|
|
|
|
/**************************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Boolean to get the battery
|
|
|
|
//Boolean to get the battery
|
|
|
|
rt_mutex_acquire(&mutex_killBattery, TM_INFINITE);
|
|
|
|
rt_mutex_acquire(&mutex_killBattery, TM_INFINITE);
|
|
|
|
killBattery=0;
|
|
|
|
killBattery=0;
|
|
|
|
rt_mutex_release(&mutex_killBattery);
|
|
|
|
rt_mutex_release(&mutex_killBattery);
|
|
|
|
|
|
|
|
|
|
|
|
rt_sem_p(&sem_startRobotWithWatchdog, TM_INFINITE);
|
|
|
|
rt_sem_p(&sem_startRobotWithWatchdog, TM_INFINITE);
|
|
|
|
cout << "Start robot with watchdog (";
|
|
|
|
cout << "Start robot with watchdog (";
|
|
|
|
|
|
|
|
|
|
|
|
rt_mutex_acquire(&mutex_robot, TM_INFINITE);
|
|
|
|
rt_mutex_acquire(&mutex_robot, TM_INFINITE);
|
|
|
|
msgSend = robot.Write(robot.StartWithWD());
|
|
|
|
msgSend = robot.Write(robot.StartWithWD());
|
|
|
|
rt_mutex_release(&mutex_robot);
|
|
|
|
rt_mutex_release(&mutex_robot);
|
|
|
|
|
|
|
|
|
|
|
|
cout << msgSend->GetID();
|
|
|
|
cout << msgSend->GetID();
|
|
|
|
cout << ")" << endl;
|
|
|
|
cout << ")" << endl;
|
|
|
|
cout << "Movement answer: " << msgSend->ToString() << endl << flush;
|
|
|
|
cout << "Movement answer: " << msgSend->ToString() << endl << flush;
|
|
|
@ -587,22 +691,23 @@ void Tasks::StartRobotTaskWithWatchdog(void *arg) {
|
|
|
|
rt_mutex_acquire(&mutex_robotStarted, TM_INFINITE);
|
|
|
|
rt_mutex_acquire(&mutex_robotStarted, TM_INFINITE);
|
|
|
|
robotStarted = 1;
|
|
|
|
robotStarted = 1;
|
|
|
|
rt_mutex_release(&mutex_robotStarted);
|
|
|
|
rt_mutex_release(&mutex_robotStarted);
|
|
|
|
|
|
|
|
|
|
|
|
rt_task_set_periodic(NULL, TM_NOW, 500000000);
|
|
|
|
rt_task_set_periodic(NULL, TM_NOW, 500000000);
|
|
|
|
|
|
|
|
|
|
|
|
while (killBatteryOk==0) {
|
|
|
|
while (killBatteryOk==0) {
|
|
|
|
cpt++;
|
|
|
|
cpt++;
|
|
|
|
if(cpt==2){
|
|
|
|
if(cpt==2){
|
|
|
|
rt_mutex_acquire(&mutex_robot, TM_INFINITE);
|
|
|
|
|
|
|
|
robot.Write(robot.ReloadWD());
|
|
|
|
|
|
|
|
rt_mutex_release(&mutex_robot);
|
|
|
|
|
|
|
|
cpt=0;
|
|
|
|
cpt=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rt_task_wait_period(NULL);
|
|
|
|
rt_task_wait_period(NULL);
|
|
|
|
rt_sem_v(&sem_askBattery);
|
|
|
|
rt_sem_v(&sem_askBattery);
|
|
|
|
|
|
|
|
|
|
|
|
rt_mutex_acquire(&mutex_killBattery, TM_INFINITE);
|
|
|
|
rt_mutex_acquire(&mutex_killBattery, TM_INFINITE);
|
|
|
|
killBatteryOk=killBattery;
|
|
|
|
killBatteryOk=killBattery;
|
|
|
|
rt_mutex_release(&mutex_killBattery);
|
|
|
|
rt_mutex_release(&mutex_killBattery);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -644,6 +749,86 @@ void Tasks::MoveTask(void *arg) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Tasks::DetectLostSupRob(void *arg){
|
|
|
|
|
|
|
|
//counter to detect loss of communication
|
|
|
|
|
|
|
|
int cpt=0;
|
|
|
|
|
|
|
|
bool kill_detectLostSupRobOk=0;
|
|
|
|
|
|
|
|
Message* msgSend;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Period = 1s
|
|
|
|
|
|
|
|
rt_task_set_periodic(NULL, TM_NOW, 1000000000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while(1){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Wait the Communication with the Robot to be Set
|
|
|
|
|
|
|
|
rt_sem_p(&sem_detectLostSupRob, TM_INFINITE);
|
|
|
|
|
|
|
|
cout << "Start DetectLostSupRob" << endl << flush;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Initialize counter to detect loss
|
|
|
|
|
|
|
|
cpt = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Initialize the variable for the loop condition
|
|
|
|
|
|
|
|
kill_detectLostSupRobOk = 0;
|
|
|
|
|
|
|
|
rt_mutex_acquire(&mutex_killDetectLostSupRob, TM_INFINITE);
|
|
|
|
|
|
|
|
killDetectLostSupRob = 0;
|
|
|
|
|
|
|
|
rt_mutex_release(&mutex_killDetectLostSupRob);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while(!kill_detectLostSupRobOk){
|
|
|
|
|
|
|
|
rt_task_wait_period(NULL);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Test Communication with Robot
|
|
|
|
|
|
|
|
rt_mutex_acquire(&mutex_robot, TM_INFINITE);
|
|
|
|
|
|
|
|
msgSend = robot.Write(robot.Ping());
|
|
|
|
|
|
|
|
rt_mutex_release(&mutex_robot);
|
|
|
|
|
|
|
|
cout << "J'écris un message" << endl << flush;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(msgSend->GetID() == MESSAGE_ANSWER_COM_ERROR || msgSend->GetID() == MESSAGE_ANSWER_ROBOT_TIMEOUT){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cout << "Didn't Get Any Answer from Robot" << endl << flush;
|
|
|
|
|
|
|
|
cpt++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(cpt==3){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//acknowledge loss communication with robot
|
|
|
|
|
|
|
|
//WriteInQueue(&q_messageToMon, new Message(MESSAGE_MONITOR_LOST));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cout << "Restart Communication with Robot" << endl << flush;
|
|
|
|
|
|
|
|
//Trigger Kill of DetectLostSupRob
|
|
|
|
|
|
|
|
rt_mutex_acquire(&mutex_killDetectLostSupRob, TM_INFINITE);
|
|
|
|
|
|
|
|
killDetectLostSupRob=1;
|
|
|
|
|
|
|
|
rt_mutex_release(&mutex_killDetectLostSupRob);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Trigger Kill of the Battery acquisition and therefore Robot with or without WD
|
|
|
|
|
|
|
|
rt_mutex_acquire(&mutex_killBattery, TM_INFINITE);
|
|
|
|
|
|
|
|
killBattery=1;
|
|
|
|
|
|
|
|
rt_mutex_release(&mutex_killBattery);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rt_mutex_acquire(&mutex_robotStarted, TM_INFINITE);
|
|
|
|
|
|
|
|
robotStarted=0;
|
|
|
|
|
|
|
|
rt_mutex_release(&mutex_robotStarted);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rt_sem_v(&sem_openComRobot);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
cout << "I got an Answer from Robot" << endl << flush;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rt_mutex_acquire(&mutex_killDetectLostSupRob, TM_INFINITE);
|
|
|
|
|
|
|
|
kill_detectLostSupRobOk=killDetectLostSupRob;
|
|
|
|
|
|
|
|
rt_mutex_release(&mutex_killDetectLostSupRob);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cout << "DetectLostSupRob dies";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Tasks::AskBattery(void *arg){
|
|
|
|
void Tasks::AskBattery(void *arg){
|
|
|
|
Message* p_mess_answer_battery;
|
|
|
|
Message* p_mess_answer_battery;
|
|
|
|
cout << "Start " << __PRETTY_FUNCTION__ << endl << flush;
|
|
|
|
cout << "Start " << __PRETTY_FUNCTION__ << endl << flush;
|
|
|
|