From 9df1899580f02ff1104611fa4fef822fac0659dc Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Tue, 14 May 2024 13:55:27 +0200 Subject: [PATCH] Added semaphore for Arena --- .../nbproject/private/configurations.xml | 2 +- .../nbproject/private/private.xml | 5 ++++- .../private/timestamps-10.105.0.146-xenomai-22 | 0 .../nbproject/project.properties | 2 +- software/raspberry/superviseur-robot/tasks.cpp | 15 +++++++-------- software/raspberry/superviseur-robot/tasks.h | 1 + 6 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 software/raspberry/superviseur-robot/nbproject/private/timestamps-10.105.0.146-xenomai-22 diff --git a/software/raspberry/superviseur-robot/nbproject/private/configurations.xml b/software/raspberry/superviseur-robot/nbproject/private/configurations.xml index 13b46b9..17ba976 100644 --- a/software/raspberry/superviseur-robot/nbproject/private/configurations.xml +++ b/software/raspberry/superviseur-robot/nbproject/private/configurations.xml @@ -41,7 +41,7 @@ - xenomai@10.105.0.145:22 + xenomai@10.105.0.146:22 2 diff --git a/software/raspberry/superviseur-robot/nbproject/private/private.xml b/software/raspberry/superviseur-robot/nbproject/private/private.xml index ab84910..8f74769 100644 --- a/software/raspberry/superviseur-robot/nbproject/private/private.xml +++ b/software/raspberry/superviseur-robot/nbproject/private/private.xml @@ -6,6 +6,9 @@ - + + file:/home/boujon/Documents/dumber/software/raspberry/superviseur-robot/tasks.cpp + file:/home/boujon/Documents/dumber/software/raspberry/superviseur-robot/tasks.h + diff --git a/software/raspberry/superviseur-robot/nbproject/private/timestamps-10.105.0.146-xenomai-22 b/software/raspberry/superviseur-robot/nbproject/private/timestamps-10.105.0.146-xenomai-22 new file mode 100644 index 0000000..e69de29 diff --git a/software/raspberry/superviseur-robot/nbproject/project.properties b/software/raspberry/superviseur-robot/nbproject/project.properties index 973e009..b81c3c1 100644 --- a/software/raspberry/superviseur-robot/nbproject/project.properties +++ b/software/raspberry/superviseur-robot/nbproject/project.properties @@ -1,2 +1,2 @@ -#Tue Nov 13 11:04:27 CET 2018 +#Tue May 14 13:44:12 CEST 2024 project.license=gpl30 diff --git a/software/raspberry/superviseur-robot/tasks.cpp b/software/raspberry/superviseur-robot/tasks.cpp index d357a9e..2b6e7ae 100644 --- a/software/raspberry/superviseur-robot/tasks.cpp +++ b/software/raspberry/superviseur-robot/tasks.cpp @@ -358,6 +358,7 @@ void Tasks::ReceiveFromMonTask(void *arg) { if(arenaStatus == ArenaStatusEnum::NONE) arenaStatus = ArenaStatusEnum::SEARCHING; rt_mutex_release(&mutex_arenaStatus); + rt_sem_v(&sem_arenaChoice, TM_INFINITE); } else if (msgRcv->CompareID(MESSAGE_CAM_ARENA_CONFIRM)) { std::cout << "\n\n\nArena Confirm asked !!!\n\n\n" << std::endl; @@ -365,6 +366,7 @@ void Tasks::ReceiveFromMonTask(void *arg) { if(arenaStatus == ArenaStatusEnum::SEARCHED) arenaStatus = ArenaStatusEnum::CONFIRM; rt_mutex_release(&mutex_arenaStatus); + rt_sem_v(&sem_arenaChoice, TM_INFINITE); } else if (msgRcv->CompareID(MESSAGE_CAM_ARENA_INFIRM)) { std::cout << "\n\n\nArena Infirm asked !!!\n\n\n" << std::endl; @@ -372,6 +374,7 @@ void Tasks::ReceiveFromMonTask(void *arg) { if(arenaStatus == ArenaStatusEnum::SEARCHED) arenaStatus = ArenaStatusEnum::INFIRM; rt_mutex_release(&mutex_arenaStatus); + rt_sem_v(&sem_arenaChoice, TM_INFINITE); } else if (msgRcv->CompareID(MESSAGE_CAM_IMAGE)) { //? @@ -666,15 +669,12 @@ void Tasks::ArenaChoiceTask(void * arg) ArenaStatusEnum as(ArenaStatusEnum::NONE); cout << "Start " << __PRETTY_FUNCTION__ << endl << flush; - // Synchronization barrier (waiting that all tasks are starting) rt_sem_p(&sem_barrier, TM_INFINITE); - /* The task starts here */ - rt_task_set_periodic(NULL, TM_NOW, 490000000); - while(1) { - rt_task_wait_period(NULL); + // Get semaphore + rt_sem_p(&sem_arenaChoice, TM_INFINITE); // Check the status of the arena rt_mutex_acquire(&mutex_arenaStatus, TM_INFINITE); as = arenaStatus; @@ -736,11 +736,10 @@ void Tasks::ArenaChoiceTask(void * arg) rt_mutex_acquire(&mutex_cameraStatus, TM_INFINITE); cameraStatus = CameraStatusEnum::OPENING; rt_mutex_release(&mutex_cameraStatus); - const MessageID tempMessage = this->OpenCamera(); - WriteInQueue(&q_messageToMon, new Message(tempMessage)); + this->OpenCamera(); rt_mutex_acquire(&mutex_arenaStatus, TM_INFINITE); - arenaStatus = ArenaStatusEnum::CONFIRMED; + arenaStatus = ArenaStatusEnum::NONE; rt_mutex_release(&mutex_arenaStatus); } } diff --git a/software/raspberry/superviseur-robot/tasks.h b/software/raspberry/superviseur-robot/tasks.h index a2a5af3..d5535ca 100644 --- a/software/raspberry/superviseur-robot/tasks.h +++ b/software/raspberry/superviseur-robot/tasks.h @@ -122,6 +122,7 @@ private: RT_SEM sem_openComRobot; RT_SEM sem_serverOk; RT_SEM sem_startRobot; + RT_SEM sem_arenaChoice; /**********************************************************************/ /* Message queues */