diff --git a/software/raspberry/superviseur-robot/nbproject/private/configurations.xml b/software/raspberry/superviseur-robot/nbproject/private/configurations.xml index 6eedf50..a17a8c5 100644 --- a/software/raspberry/superviseur-robot/nbproject/private/configurations.xml +++ b/software/raspberry/superviseur-robot/nbproject/private/configurations.xml @@ -41,7 +41,7 @@ - pi@10.105.1.08:22 + pi@10.105.1.7:22 2 diff --git a/software/raspberry/superviseur-robot/nbproject/private/downloads-10.105.1.7-pi-22 b/software/raspberry/superviseur-robot/nbproject/private/downloads-10.105.1.7-pi-22 new file mode 100644 index 0000000..e69de29 diff --git a/software/raspberry/superviseur-robot/nbproject/private/timestamps-10.105.1.7-pi-22 b/software/raspberry/superviseur-robot/nbproject/private/timestamps-10.105.1.7-pi-22 new file mode 100644 index 0000000..49db834 --- /dev/null +++ b/software/raspberry/superviseur-robot/nbproject/private/timestamps-10.105.1.7-pi-22 @@ -0,0 +1,38 @@ +#Fri Feb 26 10:15:15 CET 2021 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/lib/base64/README.md=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/nbproject/project.xml=c1614324902000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/lib/commonitor.h=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/nbproject/Makefile-Debug__RPI_.mk=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/lib/base64/test.cpp=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/nbproject/Makefile-variables.mk=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/lib/messages.h=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/lib/base64/base64.h=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/lib/base64/compile-and-run-test=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/.dep.inc=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/.gitignore=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/lib/.gitignore=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/lib/messages.cpp=c1614324901000 +VERSION=1.3 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/lib/img.cpp=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/lib/img.h=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/tasks.cpp=c1614330913000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/Makefile=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/lib/camera.h=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/nbproject/Makefile-Debug__PC_.mk=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/lib/comrobot.h=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/lib/base64/.gitignore=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/README.md=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/nbproject/Makefile-impl.mk=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/nbproject/project.properties=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/lib/comrobot.cpp=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/main.cpp=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/nbproject/Package-Debug__PC_.bash=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/lib/base64/base64.cpp=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/nbproject/Package-Debug__RPI_.bash=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/lib/commonitor.cpp=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/superviseur.doxygen=c1614324902000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/gdbsudo.sh=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/lib/base64/LICENSE=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/tasks.h=c1614329334000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/nbproject/private/Makefile-variables.mk=c1614324901000 +/home/alartigu/Bureau/Temps_Reel_Robot/software/raspberry/superviseur-robot/lib/camera.cpp=c1614324901000 diff --git a/software/raspberry/superviseur-robot/tasks.cpp b/software/raspberry/superviseur-robot/tasks.cpp index f17ae21..17f0c7d 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 31 /* * 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_getBattery, "th_getBattery", 0, PRIORITY_TBATTERY, 0)) { + cerr << "Error task create: " << strerror(-err) << endl << flush; + exit(EXIT_FAILURE); + } cout << "Tasks created successfully" << endl << flush; /**************************************************************************************/ @@ -167,7 +172,11 @@ void Tasks::Run() { cerr << "Error task start: " << strerror(-err) << endl << flush; exit(EXIT_FAILURE); } - + if (err = rt_task_start(&th_getBattery, (void(*)(void*)) & Tasks::ReadBattery, this)) { + cerr << "Error task start: " << strerror(-err) << endl << flush; + exit(EXIT_FAILURE); + } + cout << "Tasks launched" << endl << flush; } @@ -351,6 +360,7 @@ void Tasks::StartRobotTask(void *arg) { */ void Tasks::MoveTask(void *arg) { int rs; + int previousMove = MESSAGE_ROBOT_GO_FORWARD; int cpMove; cout << "Start " << __PRETTY_FUNCTION__ << endl << flush; @@ -372,12 +382,15 @@ void Tasks::MoveTask(void *arg) { rt_mutex_acquire(&mutex_move, TM_INFINITE); cpMove = move; rt_mutex_release(&mutex_move); - - cout << " move: " << cpMove; - - rt_mutex_acquire(&mutex_robot, TM_INFINITE); - robot.Write(new Message((MessageID)cpMove)); - rt_mutex_release(&mutex_robot); + if (cpMove != previousMove) { + cout << " move: " << cpMove; + + rt_mutex_acquire(&mutex_robot, TM_INFINITE); + robot.Write(new Message((MessageID)cpMove)); + rt_mutex_release(&mutex_robot); + + previousMove = cpMove; + } } cout << endl << flush; } @@ -415,3 +428,34 @@ Message *Tasks::ReadInQueue(RT_QUEUE *queue) { return msg; } +void Tasks::ReadBattery(void *arg){ + 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, 500000000); + + int rs; + + while (1) { + rt_task_wait_period(NULL); + cout << "Periodic battery get lvl \n"; + rt_mutex_acquire(&mutex_robotStarted, TM_INFINITE); + rs = robotStarted; + rt_mutex_release(&mutex_robotStarted); + if (rs == 1) { + rt_mutex_acquire(&mutex_robot, TM_INFINITE); + Message *msg = robot.Write( robot.GetBattery() ) ; + rt_mutex_release(&mutex_robot); + rt_mutex_acquire(&mutex_monitor, TM_INFINITE); + monitor.Write(msg); + rt_mutex_release(&mutex_monitor); + + } + + cout << endl << flush; + } +} diff --git a/software/raspberry/superviseur-robot/tasks.h b/software/raspberry/superviseur-robot/tasks.h index 27fe329..4176b3d 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_getBattery; /**********************************************************************/ /* Mutex */ @@ -148,6 +149,14 @@ private: * @return Message read */ Message *ReadInQueue(RT_QUEUE *queue); + + + /** + * Read the battery level of the robot + * @return Nothing + */ + void ReadBattery(void *arg); + };