From 9a88a66cc17db55cd55b43f0e80f722e40b35e66 Mon Sep 17 00:00:00 2001 From: Marin-Muller Robin Date: Tue, 26 Mar 2024 15:27:20 +0100 Subject: [PATCH] Added battery monitoring task --- .vscode/c_cpp_properties.json | 18 ++++++ .vscode/settings.json | 59 +++++++++++++++++++ README.md | 3 + .../nbproject/configurations.xml | 12 ++++ .../nbproject/private/configurations.xml | 2 +- .../private/downloads-10.105.0.138-xenomai-22 | 0 .../private/downloads-10.105.0.144-xenomai-22 | 0 .../timestamps-10.105.0.138-xenomai-22 | 39 ++++++++++++ .../timestamps-10.105.0.144-xenomai-22 | 39 ++++++++++++ .../superviseur-robot/nbproject/project.xml | 1 + .../raspberry/superviseur-robot/tasks.cpp | 44 ++++++++++++++ software/raspberry/superviseur-robot/tasks.h | 33 +++++++---- 12 files changed, 238 insertions(+), 12 deletions(-) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/settings.json create mode 100644 software/raspberry/superviseur-robot/nbproject/private/downloads-10.105.0.138-xenomai-22 create mode 100644 software/raspberry/superviseur-robot/nbproject/private/downloads-10.105.0.144-xenomai-22 create mode 100644 software/raspberry/superviseur-robot/nbproject/private/timestamps-10.105.0.138-xenomai-22 create mode 100644 software/raspberry/superviseur-robot/nbproject/private/timestamps-10.105.0.144-xenomai-22 diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..c2098a2 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "linux-gcc-x64", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "/usr/bin/gcc", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "linux-gcc-x64", + "compilerArgs": [ + "" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3e5eb95 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,59 @@ +{ + "C_Cpp_Runner.cCompilerPath": "gcc", + "C_Cpp_Runner.cppCompilerPath": "g++", + "C_Cpp_Runner.debuggerPath": "gdb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wcast-align", + "-Wconversion", + "-Wsign-conversion", + "-Wnull-dereference" + ], + "C_Cpp_Runner.msvcWarnings": [ + "/W4", + "/permissive-", + "/w14242", + "/w14287", + "/w14296", + "/w14311", + "/w14826", + "/w44062", + "/w44242", + "/w14905", + "/w14906", + "/w14263", + "/w44265", + "/w14928" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ], + "C_Cpp_Runner.useAddressSanitizer": false, + "C_Cpp_Runner.useUndefinedSanitizer": false, + "C_Cpp_Runner.useLeakSanitizer": false, + "C_Cpp_Runner.showCompilationTime": false, + "C_Cpp_Runner.useLinkTimeOptimization": false, + "C_Cpp_Runner.msvcSecureNoWarnings": false +} \ No newline at end of file diff --git a/README.md b/README.md index 7a9fe63..0f4a9bd 100644 --- a/README.md +++ b/README.md @@ -8,3 +8,6 @@ Depot du projet de temps reel 4eme année au departement GEI de l'INSA Toulouse. - doc: contient les sujets de TD et TP - aruco_markers: Script de generation des tags (aruco) utilisés sur les robots + +/home/xenomai/.netbeans/remote/10.105.0.144/insa-10577-Linux-x86_64/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/dist/Debug__RPI_/GNU-Linux + diff --git a/software/raspberry/superviseur-robot/nbproject/configurations.xml b/software/raspberry/superviseur-robot/nbproject/configurations.xml index 48dba36..6461a2d 100644 --- a/software/raspberry/superviseur-robot/nbproject/configurations.xml +++ b/software/raspberry/superviseur-robot/nbproject/configurations.xml @@ -41,9 +41,21 @@ kind="IMPORTANT_FILES_FOLDER"> ./Makefile + + + + ./Makefile + lib + lib ./Makefile diff --git a/software/raspberry/superviseur-robot/nbproject/private/configurations.xml b/software/raspberry/superviseur-robot/nbproject/private/configurations.xml index 21a5072..de996c9 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.0.144:22 2 diff --git a/software/raspberry/superviseur-robot/nbproject/private/downloads-10.105.0.138-xenomai-22 b/software/raspberry/superviseur-robot/nbproject/private/downloads-10.105.0.138-xenomai-22 new file mode 100644 index 0000000..e69de29 diff --git a/software/raspberry/superviseur-robot/nbproject/private/downloads-10.105.0.144-xenomai-22 b/software/raspberry/superviseur-robot/nbproject/private/downloads-10.105.0.144-xenomai-22 new file mode 100644 index 0000000..e69de29 diff --git a/software/raspberry/superviseur-robot/nbproject/private/timestamps-10.105.0.138-xenomai-22 b/software/raspberry/superviseur-robot/nbproject/private/timestamps-10.105.0.138-xenomai-22 new file mode 100644 index 0000000..10cc8b3 --- /dev/null +++ b/software/raspberry/superviseur-robot/nbproject/private/timestamps-10.105.0.138-xenomai-22 @@ -0,0 +1,39 @@ +#Tue Mar 26 14:16:07 CET 2024 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/main.cpp=c1711457904172 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/private/Makefile-variables.mk=c1711457904197 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/Makefile-Debug__PC_.mk=c1711458297850 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/Makefile=c1711457904018 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/comrobot.h=c1711457904155 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/messages.h=c1711457904169 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/Makefile-Debug__RPI_.mk=c1711458297867 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/.gitignore=c1711457904114 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/Package-Debug__PC_.bash=c1711457904187 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/tasks.h=c1711457904245 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/README.md=c1711457904021 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/project.xml=c1711458720366 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/Makefile-impl.mk=c1711457904182 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/superviseur.doxygen=c1711457904238 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/base64/README.md=c1711457904124 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/tasks.cpp=c1711457904242 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/comrobot.cpp=c1711457904151 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/.dep.inc=c1711458948692 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/img.h=c1711457904162 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/camera.h=c1711457904141 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/base64/test.cpp=c1711457904135 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/img.cpp=c1711457904159 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/base64/base64.h=c1711457904130 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/base64/compile-and-run-test=c1711457904132 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/commonitor.h=c1711457904148 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/wrapper.c=c1711457904248 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/camera.cpp=c1711457904138 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/messages.cpp=c1711457904165 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/gdbsudo.sh=c1711457904109 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/base64/base64.cpp=c1711457904127 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/base64/LICENSE=c1711457904121 +VERSION=1.3 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/commonitor.cpp=c1711457904144 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/Makefile-variables.mk=c1711457904185 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/Package-Debug__RPI_.bash=c1711457904190 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/.gitignore=c1711457904015 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/project.properties=c1711457904230 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/base64/.gitignore=c1711457904118 diff --git a/software/raspberry/superviseur-robot/nbproject/private/timestamps-10.105.0.144-xenomai-22 b/software/raspberry/superviseur-robot/nbproject/private/timestamps-10.105.0.144-xenomai-22 new file mode 100644 index 0000000..0816957 --- /dev/null +++ b/software/raspberry/superviseur-robot/nbproject/private/timestamps-10.105.0.144-xenomai-22 @@ -0,0 +1,39 @@ +#Tue Mar 26 15:23:55 CET 2024 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/main.cpp=c1711457904172 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/private/Makefile-variables.mk=c1711457904197 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/Makefile-Debug__PC_.mk=c1711458297850 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/Makefile=c1711457904018 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/comrobot.h=c1711457904155 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/messages.h=c1711457904169 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/Makefile-Debug__RPI_.mk=c1711458297867 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/.gitignore=c1711457904114 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/Package-Debug__PC_.bash=c1711457904187 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/tasks.h=c1711461453052 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/README.md=c1711457904021 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/project.xml=c1711458720366 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/Makefile-impl.mk=c1711457904182 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/superviseur.doxygen=c1711457904238 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/base64/README.md=c1711457904124 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/tasks.cpp=c1711463022931 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/comrobot.cpp=c1711457904151 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/img.h=c1711457904162 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/.dep.inc=c1711458948692 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/camera.h=c1711457904141 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/base64/test.cpp=c1711457904135 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/img.cpp=c1711457904159 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/base64/base64.h=c1711457904130 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/base64/compile-and-run-test=c1711457904132 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/commonitor.h=c1711457904148 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/wrapper.c=c1711457904248 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/camera.cpp=c1711457904138 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/messages.cpp=c1711457904165 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/gdbsudo.sh=c1711457904109 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/base64/base64.cpp=c1711457904127 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/base64/LICENSE=c1711457904121 +VERSION=1.3 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/commonitor.cpp=c1711457904144 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/Makefile-variables.mk=c1711457904185 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/Package-Debug__RPI_.bash=c1711457904190 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/.gitignore=c1711457904015 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/project.properties=c1711457904230 +/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/base64/.gitignore=c1711457904118 diff --git a/software/raspberry/superviseur-robot/nbproject/project.xml b/software/raspberry/superviseur-robot/nbproject/project.xml index 62dd3f1..511da71 100644 --- a/software/raspberry/superviseur-robot/nbproject/project.xml +++ b/software/raspberry/superviseur-robot/nbproject/project.xml @@ -11,6 +11,7 @@ lib + lib diff --git a/software/raspberry/superviseur-robot/tasks.cpp b/software/raspberry/superviseur-robot/tasks.cpp index f17ae21..7b2a4eb 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 19 /* * Some remarks: @@ -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::BatteryStatusTask, this)) { + cerr << "Error task start: " << strerror(-err) << endl << flush; + exit(EXIT_FAILURE); + } cout << "Tasks launched" << endl << flush; } @@ -264,6 +273,8 @@ void Tasks::ReceiveFromMonTask(void *arg) { exit(-1); } else if (msgRcv->CompareID(MESSAGE_ROBOT_COM_OPEN)) { rt_sem_v(&sem_openComRobot); + } else if (msgRcv->CompareID(MESSAGE_ROBOT_BATTERY_GET)) { + printf("Battery handler\n\r"); } else if (msgRcv->CompareID(MESSAGE_ROBOT_START_WITHOUT_WD)) { rt_sem_v(&sem_startRobot); } else if (msgRcv->CompareID(MESSAGE_ROBOT_GO_FORWARD) || @@ -415,3 +426,36 @@ Message *Tasks::ReadInQueue(RT_QUEUE *queue) { return msg; } + + +/* OUR CODE */ + +void Tasks::BatteryStatusTask(void * arg) { + // Variables + int rs(0); + + 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, 50000000); + + while (1) { + rt_task_wait_period(NULL); + std::cout << "Periodic battery level update\n\r" << std::flush; + rt_mutex_acquire(&mutex_robotStarted, TM_INFINITE); + rs = robotStarted; + rt_mutex_release(&mutex_robotStarted); + if (rs =! 1) + continue; + + rt_mutex_acquire(&mutex_robot, TM_INFINITE); + Message* msg = robot.Write(new Message(MESSAGE_ROBOT_BATTERY_GET)); + std::cout << "Message Received: " << msg->ToString() << std::endl; + + rt_mutex_release(&mutex_robot); + cout << endl << flush; + } +} diff --git a/software/raspberry/superviseur-robot/tasks.h b/software/raspberry/superviseur-robot/tasks.h index 27fe329..b1768d2 100644 --- a/software/raspberry/superviseur-robot/tasks.h +++ b/software/raspberry/superviseur-robot/tasks.h @@ -52,12 +52,12 @@ public: * @brief Stops tasks */ void Stop(); - + /** * @brief Suspends main thread */ void Join(); - + private: /**********************************************************************/ /* Shared data */ @@ -66,7 +66,8 @@ private: ComRobot robot; int robotStarted = 0; int move = MESSAGE_ROBOT_STOP; - + int robotBattery = 0; + /**********************************************************************/ /* Tasks */ /**********************************************************************/ @@ -76,7 +77,8 @@ private: RT_TASK th_openComRobot; RT_TASK th_startRobot; RT_TASK th_move; - + RT_TASK th_battery; + /**********************************************************************/ /* Mutex */ /**********************************************************************/ @@ -98,7 +100,7 @@ private: /**********************************************************************/ int MSG_QUEUE_SIZE; RT_QUEUE q_messageToMon; - + /**********************************************************************/ /* Tasks' functions */ /**********************************************************************/ @@ -106,17 +108,17 @@ private: * @brief Thread handling server communication with the monitor. */ void ServerTask(void *arg); - + /** * @brief Thread sending data to monitor. */ void SendToMonTask(void *arg); - + /** * @brief Thread receiving data from monitor. */ void ReceiveFromMonTask(void *arg); - + /** * @brief Thread opening communication with the robot. */ @@ -126,12 +128,18 @@ private: * @brief Thread starting the communication with the robot. */ void StartRobotTask(void *arg); - + /** * @brief Thread handling control of the robot. */ void MoveTask(void *arg); - + + + /* OUR CODE */ + + void BatteryStatusTask(void * arg); + + /**********************************************************************/ /* Queue services */ /**********************************************************************/ @@ -141,7 +149,7 @@ private: * @param msg Message to be stored */ void WriteInQueue(RT_QUEUE *queue, Message *msg); - + /** * Read a message from a given queue, block if empty * @param queue Queue identifier @@ -149,7 +157,10 @@ private: */ Message *ReadInQueue(RT_QUEUE *queue); + + }; + #endif // __TASKS_H__