From db9216cd7f2c1832f0ec782c6b612867a9f2cc9f Mon Sep 17 00:00:00 2001 From: vitrat Date: Thu, 26 Mar 2020 16:47:36 +0100 Subject: [PATCH] =?UTF-8?q?M=C3=A0j=20batterie=20et=20d=C3=A9marrage=20rob?= =?UTF-8?q?ot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../superviseur-robot/lib/comrobot.cpp | 1 + .../nbproject/private/private.xml | 7 +- .../raspberry/superviseur-robot/tasks.cpp | 64 ++++++++----------- software/simulateur/main.cpp | 3 +- .../simulateur/nbproject/private/private.xml | 4 +- 5 files changed, 32 insertions(+), 47 deletions(-) diff --git a/software/raspberry/superviseur-robot/lib/comrobot.cpp b/software/raspberry/superviseur-robot/lib/comrobot.cpp index cbc618a..3faf608 100644 --- a/software/raspberry/superviseur-robot/lib/comrobot.cpp +++ b/software/raspberry/superviseur-robot/lib/comrobot.cpp @@ -327,6 +327,7 @@ string ComRobot::MessageToString(Message *msg) { break; case MESSAGE_ROBOT_RELOAD_WD: s += LABEL_ROBOT_RELOAD_WD; + cout << "watchdog" << endl; break; case MESSAGE_ROBOT_BATTERY_GET: s += LABEL_ROBOT_GET_BATTERY; diff --git a/software/raspberry/superviseur-robot/nbproject/private/private.xml b/software/raspberry/superviseur-robot/nbproject/private/private.xml index 60c0e4e..39a10ef 100644 --- a/software/raspberry/superviseur-robot/nbproject/private/private.xml +++ b/software/raspberry/superviseur-robot/nbproject/private/private.xml @@ -7,12 +7,7 @@ - file:/home/romainv/Documents/temps_reel/dumber/software/raspberry/superviseur-robot/lib/comrobot.h - file:/home/romainv/Documents/temps_reel/dumber/software/raspberry/superviseur-robot/lib/commonitor.cpp - file:/home/romainv/Documents/temps_reel/dumber/software/raspberry/superviseur-robot/lib/commonitor.h - file:/home/romainv/Documents/temps_reel/dumber/software/raspberry/superviseur-robot/lib/messages.h - file:/home/romainv/Documents/temps_reel/dumber/software/raspberry/superviseur-robot/tasks.h - file:/home/romainv/Documents/temps_reel/dumber/software/raspberry/superviseur-robot/tasks.cpp + file:/home/romainv/Documents/temps_reel/dumber1/software/raspberry/superviseur-robot/tasks.h diff --git a/software/raspberry/superviseur-robot/tasks.cpp b/software/raspberry/superviseur-robot/tasks.cpp index aa72b9f..3a5d7ed 100644 --- a/software/raspberry/superviseur-robot/tasks.cpp +++ b/software/raspberry/superviseur-robot/tasks.cpp @@ -355,34 +355,28 @@ 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); - + Message * msgSend; /**************************************************************************************/ /* The task startRobot starts here */ /**************************************************************************************/ - while (1) { - int err; - Message * msgSend; - rt_sem_p(&sem_startRobotWithoutWatchdog, TM_INFINITE); - cout << "Start robot without watchdog ("; - rt_mutex_acquire(&mutex_robot, TM_INFINITE); - msgSend = robot.Write(robot.StartWithoutWD()); - rt_mutex_release(&mutex_robot); - cout << msgSend->GetID(); - cout << ")" << endl; - - cout << "Movement answer: " << msgSend->ToString() << endl << flush; - WriteInQueue(&q_messageToMon, msgSend); // msgSend will be deleted by sendToMon - - if (msgSend->GetID() == MESSAGE_ANSWER_ACK) { - rt_mutex_acquire(&mutex_robotStarted, TM_INFINITE); - robotStarted = 1; - rt_mutex_release(&mutex_robotStarted); - rt_task_set_periodic(NULL, TM_NOW, 5000000000); - while (1) { - rt_task_wait_period(NULL); - rt_sem_v(&sem_askBattery); - - } + rt_sem_p(&sem_startRobotWithoutWatchdog, TM_INFINITE); + cout << "Start robot without watchdog ("; + rt_mutex_acquire(&mutex_robot, TM_INFINITE); + msgSend = robot.Write(robot.StartWithoutWD()); + rt_mutex_release(&mutex_robot); + cout << msgSend->GetID(); + cout << ")" << endl; + cout << "Movement answer: " << msgSend->ToString() << endl << flush; + + WriteInQueue(&q_messageToMon, msgSend); // msgSend will be deleted by sendToMon + if (msgSend->GetID() == MESSAGE_ANSWER_ACK) { + rt_mutex_acquire(&mutex_robotStarted, TM_INFINITE); + robotStarted = 1; + rt_mutex_release(&mutex_robotStarted); + rt_task_set_periodic(NULL, TM_NOW, 500000000); + while (1) { + rt_task_wait_period(NULL); + rt_sem_v(&sem_askBattery); } } } @@ -402,10 +396,8 @@ void Tasks::StartRobotTaskWithWatchdog(void *arg) { /**************************************************************************************/ /* The task startRobot starts here */ /**************************************************************************************/ - while (1) { Message * msgSend; - int cpt=1; - int err; + int cpt=0; rt_sem_p(&sem_startRobotWithWatchdog, TM_INFINITE); cout << "Start robot with watchdog ("; rt_mutex_acquire(&mutex_robot, TM_INFINITE); @@ -422,17 +414,17 @@ void Tasks::StartRobotTaskWithWatchdog(void *arg) { rt_mutex_acquire(&mutex_robotStarted, TM_INFINITE); robotStarted = 1; rt_mutex_release(&mutex_robotStarted); - rt_task_set_periodic(NULL, TM_NOW, 5000000000); + rt_task_set_periodic(NULL, TM_NOW, 500000000); while (1) { - cpt++; rt_task_wait_period(NULL); - robot.Write(robot.ReloadWD()); - if(cpt%10==0){ - rt_sem_v(&sem_askBattery); + cpt++; + if(cpt==2){ + robot.Write(robot.ReloadWD()); + cpt=0; } + rt_sem_v(&sem_askBattery); } } - } } @@ -490,9 +482,7 @@ void Tasks::Ask_Battery(void *arg){ rt_mutex_acquire(&mutex_robot, TM_INFINITE); p_mess_answer_battery = robot.Write(robot.GetBattery()); rt_mutex_release(&mutex_robot); - rt_mutex_acquire(&mutex_monitor, TM_INFINITE); - monitor.Write(p_mess_answer_battery); - rt_mutex_release(&mutex_monitor); + WriteInQueue(&q_messageToMon, p_mess_answer_battery); cout << endl << flush; } } diff --git a/software/simulateur/main.cpp b/software/simulateur/main.cpp index 969c35f..71906df 100644 --- a/software/simulateur/main.cpp +++ b/software/simulateur/main.cpp @@ -123,7 +123,8 @@ int main(int argc, char const *argv[]) { print_time(start_time); printf(" >>> I received a message : %s\n", buffer); string s = ""; - int error = simulate_error(); + //int error = simulate_error(); + int error = 0; if (error == 0) { struct timespec t; long int e; diff --git a/software/simulateur/nbproject/private/private.xml b/software/simulateur/nbproject/private/private.xml index 2193e08..aef7ea3 100644 --- a/software/simulateur/nbproject/private/private.xml +++ b/software/simulateur/nbproject/private/private.xml @@ -6,8 +6,6 @@ - - file:/home/romainv/Documents/temps_reel/dumber/software/simulateur/main.cpp - +