changement reload toutes les 1 seconde

This commit is contained in:
Romain Vitrat 2020-03-26 08:54:59 +01:00
parent cb30b572c7
commit 23fa284ea6
2 changed files with 79 additions and 62 deletions

View file

@ -75,7 +75,10 @@ void Tasks::Init() {
cerr << "Error mutex create: " << strerror(-err) << endl << flush;
exit(EXIT_FAILURE);
}
/*if (err = rt_mutex_create(&mutex_robot_on, NULL)) {
cerr << "Error mutex create: " << strerror(-err) << endl << flush;
exit(EXIT_FAILURE);
}*/
cout << "Mutexes created successfully" << endl << flush;
@ -279,6 +282,8 @@ void Tasks::ReceiveFromMonTask(void *arg) {
if (msgRcv->CompareID(MESSAGE_MONITOR_LOST)) {
delete(msgRcv);
cout << "Connection to monitor lost" << endl;
monitor.Close();
//exit(-1);
} else if (msgRcv->CompareID(MESSAGE_ROBOT_COM_OPEN)) {
@ -344,21 +349,24 @@ 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);
int killBattery=0;
/**************************************************************************************/
/* The task startRobot starts here */
/**************************************************************************************/
while (1) {
Message* p_mess_answer_battery;
Message * msgSend;
rt_sem_p(&sem_startRobotWithoutWatchdog, TM_INFINITE);
cout << "Start robot without watchdog (";
//Boolean to get the battery
rt_mutex_acquire(&mutex_kill_battery, TM_INFINITE);
killBatteryBool=0;
rt_mutex_release(&mutex_kill_battery);
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
@ -366,8 +374,8 @@ void Tasks::StartRobotTaskWithoutWatchdog(void *arg) {
rt_mutex_acquire(&mutex_robotStarted, TM_INFINITE);
robotStarted = 1;
rt_mutex_release(&mutex_robotStarted);
rt_task_set_periodic(NULL, TM_NOW, 3000000000);
while (1) {
rt_task_set_periodic(NULL, TM_NOW, 500000000);
while (killBattery==0) {
rt_task_wait_period(NULL);
rt_mutex_acquire(&mutex_robot, TM_INFINITE);
p_mess_answer_battery = robot.Write(robot.GetBattery());
@ -375,8 +383,10 @@ void Tasks::StartRobotTaskWithoutWatchdog(void *arg) {
rt_mutex_acquire(&mutex_monitor, TM_INFINITE);
monitor.Write(p_mess_answer_battery);
rt_mutex_release(&mutex_monitor);
cout << endl << flush;
}
//cout << endl << flush;
rt_mutex_acquire(&mutex_kill_battery, TM_INFINITE);
killBattery=killBatteryBool;
rt_mutex_release(&mutex_kill_battery);
}
}
}
@ -396,7 +406,6 @@ void Tasks::StartRobotTaskWithWatchdog(void *arg) {
/**************************************************************************************/
/* The task startRobot starts here */
/**************************************************************************************/
while (1) {
Message* p_mess_answer_battery;
Message * msgSend;
int cpt=1;
@ -406,6 +415,12 @@ void Tasks::StartRobotTaskWithWatchdog(void *arg) {
rt_mutex_acquire(&mutex_robot, TM_INFINITE);
msgSend = robot.Write(robot.StartWithWD());
rt_mutex_release(&mutex_robot);
//boolean to ask battery
rt_mutex_acquire(&mutex_kill_battery, TM_INFINITE);
killBatteryBool=0;
rt_mutex_release(&mutex_kill_battery);
cout << msgSend->GetID();
cout << ")" << endl;
@ -417,14 +432,15 @@ 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, 300000000);
rt_task_set_periodic(NULL, TM_NOW, 500000000);
while (1) {
cpt++;
rt_task_wait_period(NULL);
if(cpt%2==0){
rt_mutex_acquire(&mutex_robot, TM_INFINITE);
robot.Write(robot.ReloadWD());
rt_mutex_release(&mutex_robot);
if(cpt%10==0){
}
rt_task_wait_period(NULL);
rt_mutex_acquire(&mutex_robot, TM_INFINITE);
p_mess_answer_battery = robot.Write(robot.GetBattery());
rt_mutex_release(&mutex_robot);
@ -434,8 +450,6 @@ void Tasks::StartRobotTaskWithWatchdog(void *arg) {
cout << endl << flush;
}
}
}
}
}

View file

@ -65,6 +65,8 @@ private:
ComMonitor monitor;
ComRobot robot;
int robotStarted = 0;
int killBatteryBool = 0;
int killRobotWithoutWd = 0;
int move = MESSAGE_ROBOT_STOP;
/**********************************************************************/
@ -85,6 +87,7 @@ private:
RT_MUTEX mutex_robot;
RT_MUTEX mutex_robotStarted;
RT_MUTEX mutex_move;
RT_MUTEX mutex_kill_battery;
/**********************************************************************/
/* Semaphores */