diff --git a/software/raspberry/superviseur-robot/nbproject/private/configurations.xml b/software/raspberry/superviseur-robot/nbproject/private/configurations.xml index 21a5072..7d18332 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.1.7:22 + xenomai@10.105.1.10:22 2 diff --git a/software/raspberry/superviseur-robot/nbproject/private/downloads-10.105.1.10-xenomai-22 b/software/raspberry/superviseur-robot/nbproject/private/downloads-10.105.1.10-xenomai-22 new file mode 100644 index 0000000..e69de29 diff --git a/software/raspberry/superviseur-robot/nbproject/private/timestamps-10.105.1.10-xenomai-22 b/software/raspberry/superviseur-robot/nbproject/private/timestamps-10.105.1.10-xenomai-22 new file mode 100644 index 0000000..0e13424 --- /dev/null +++ b/software/raspberry/superviseur-robot/nbproject/private/timestamps-10.105.1.10-xenomai-22 @@ -0,0 +1,39 @@ +#Tue Mar 21 15:11:16 CET 2023 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/lib/messages.cpp=c1679401432892 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/nbproject/Package-Debug__RPI_.bash=c1679401432930 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/lib/commonitor.cpp=c1679401432864 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/gdbsudo.sh=c1679401432813 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/lib/base64/LICENSE=c1679401432832 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/lib/comrobot.cpp=c1679401457314 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/tasks.cpp=c1679407831774 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/.dep.inc=c1679401432701 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/nbproject/Makefile-variables.mk=c1679401432922 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/lib/img.cpp=c1679401457320 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/lib/camera.h=c1679401457309 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/README.md=c1679401432714 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/nbproject/Makefile-Debug__PC_.mk=c1679401457337 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/Makefile=c1679401432709 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/lib/.gitignore=c1679401432820 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/tasks.h=c1679406345632 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/wrapper.c=c1679401457381 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/main.cpp=c1679404095224 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/nbproject/project.properties=c1679401432983 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/lib/camera.cpp=c1679401457304 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/lib/base64/test.cpp=c1679401432851 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/lib/base64/base64.h=c1679401432844 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/nbproject/Makefile-Debug__RPI_.mk=c1679401457346 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/nbproject/Package-Debug__PC_.bash=c1679401432926 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/nbproject/project.xml=c1679401457377 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/lib/base64/.gitignore=c1679401432827 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/nbproject/Makefile-impl.mk=c1679401432918 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/nbproject/private/Makefile-variables.mk=c1679401432944 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/superviseur.doxygen=c1679401432993 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/lib/messages.h=c1679401432897 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/lib/base64/base64.cpp=c1679401432840 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/lib/comrobot.h=c1679401432877 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/lib/img.h=c1679401457331 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/.gitignore=c1679401432706 +VERSION=1.3 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/lib/commonitor.h=c1679401432868 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/lib/base64/README.md=c1679401432836 +/home/alejeune/Documents/4ir/S2/dumber/software/raspberry/superviseur-robot/lib/base64/compile-and-run-test=c1679401432848 diff --git a/software/raspberry/superviseur-robot/tasks.cpp b/software/raspberry/superviseur-robot/tasks.cpp index f17ae21..3e77ada 100644 --- a/software/raspberry/superviseur-robot/tasks.cpp +++ b/software/raspberry/superviseur-robot/tasks.cpp @@ -26,6 +26,7 @@ #define PRIORITY_TRECEIVEFROMMON 25 #define PRIORITY_TSTARTROBOT 20 #define PRIORITY_TCAMERA 21 +#define PRIORITY_TBATTERY 25 /* * Some remarks: @@ -39,7 +40,7 @@ * 4- Take into account that ComRobot::Write will block your task when serial buffer is full, * time for internal buffer to flush * - * 5- Same behavior existe for ComMonitor::Write ! + * 5- Same behavior exists for ComMonitor::Write ! * * 6- When you want to write something in terminal, use cout and terminate with endl and flush * @@ -123,6 +124,10 @@ void Tasks::Init() { cerr << "Error task create: " << strerror(-err) << endl << flush; exit(EXIT_FAILURE); } + if (err = rt_task_create(&th_battery, "th_battery", 0, PRIORITY_TBATTERY, 0)) { + cerr << "Error task create: " << strerror(-err) << endl << flush; + exit(EXIT_FAILURE); + } cout << "Tasks created successfully" << endl << flush; /**************************************************************************************/ @@ -167,6 +172,10 @@ void Tasks::Run() { cerr << "Error task start: " << strerror(-err) << endl << flush; exit(EXIT_FAILURE); } + if (err = rt_task_start(&th_battery, (void(*)(void*)) & Tasks::BatteryTask, this)) { + cerr << "Error task start: " << strerror(-err) << endl << flush; + exit(EXIT_FAILURE); + } cout << "Tasks launched" << endl << flush; } @@ -276,7 +285,7 @@ void Tasks::ReceiveFromMonTask(void *arg) { move = msgRcv->GetID(); rt_mutex_release(&mutex_move); } - delete(msgRcv); // mus be deleted manually, no consumer + delete(msgRcv); // must be deleted manually, no consumer } } @@ -367,7 +376,6 @@ void Tasks::MoveTask(void *arg) { cout << "Periodic movement update"; rt_mutex_acquire(&mutex_robotStarted, TM_INFINITE); rs = robotStarted; - rt_mutex_release(&mutex_robotStarted); if (rs == 1) { rt_mutex_acquire(&mutex_move, TM_INFINITE); cpMove = move; @@ -379,10 +387,46 @@ void Tasks::MoveTask(void *arg) { robot.Write(new Message((MessageID)cpMove)); rt_mutex_release(&mutex_robot); } + rt_mutex_release(&mutex_robotStarted); cout << endl << flush; } } +/** + * @brief task in charge of the battery status. + */ +void Tasks::BatteryTask(void *arg) { + int rs; + int cpMove; + + 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, 500*1000*1000); + + while (1) { + rt_task_wait_period(NULL); + rt_mutex_acquire(&mutex_robotStarted, TM_INFINITE); + rs = robotStarted; + if (rs == 1) { + rt_mutex_acquire(&mutex_robot, TM_INFINITE); + Message* batteryReply = robot.Write(robot.GetBattery()); + string batteryLevel = batteryReply->ToString(); + rt_mutex_release(&mutex_robot); + + string msg = " Battery level : " << batteryLevel << endl << flush; + WriteInQueue(&q_messageToMon, BatteryReply); // a tester + + } + rt_mutex_release(&mutex_robotStarted); + + } +} + /** * Write a message in a given queue * @param queue Queue identifier diff --git a/software/raspberry/superviseur-robot/tasks.h b/software/raspberry/superviseur-robot/tasks.h index 27fe329..5af6ae5 100644 --- a/software/raspberry/superviseur-robot/tasks.h +++ b/software/raspberry/superviseur-robot/tasks.h @@ -76,6 +76,7 @@ private: RT_TASK th_openComRobot; RT_TASK th_startRobot; RT_TASK th_move; + RT_TASK th_battery; /**********************************************************************/ /* Mutex */ @@ -132,6 +133,12 @@ private: */ void MoveTask(void *arg); + + /** + * @brief task in charge of the battery status. + */ + void BatteryTask(void *arg); + /**********************************************************************/ /* Queue services */ /**********************************************************************/