changement reload toutes les 1 seconde
This commit is contained in:
parent
cb30b572c7
commit
23fa284ea6
2 changed files with 79 additions and 62 deletions
|
@ -75,7 +75,10 @@ void Tasks::Init() {
|
||||||
cerr << "Error mutex create: " << strerror(-err) << endl << flush;
|
cerr << "Error mutex create: " << strerror(-err) << endl << flush;
|
||||||
exit(EXIT_FAILURE);
|
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;
|
cout << "Mutexes created successfully" << endl << flush;
|
||||||
|
@ -279,6 +282,8 @@ void Tasks::ReceiveFromMonTask(void *arg) {
|
||||||
|
|
||||||
if (msgRcv->CompareID(MESSAGE_MONITOR_LOST)) {
|
if (msgRcv->CompareID(MESSAGE_MONITOR_LOST)) {
|
||||||
delete(msgRcv);
|
delete(msgRcv);
|
||||||
|
cout << "Connection to monitor lost" << endl;
|
||||||
|
monitor.Close();
|
||||||
//exit(-1);
|
//exit(-1);
|
||||||
|
|
||||||
} else if (msgRcv->CompareID(MESSAGE_ROBOT_COM_OPEN)) {
|
} else if (msgRcv->CompareID(MESSAGE_ROBOT_COM_OPEN)) {
|
||||||
|
@ -344,21 +349,24 @@ void Tasks::StartRobotTaskWithoutWatchdog(void *arg) {
|
||||||
cout << "Start " << __PRETTY_FUNCTION__ << endl << flush;
|
cout << "Start " << __PRETTY_FUNCTION__ << endl << flush;
|
||||||
// Synchronization barrier (waiting that all tasks are starting)
|
// Synchronization barrier (waiting that all tasks are starting)
|
||||||
rt_sem_p(&sem_barrier, TM_INFINITE);
|
rt_sem_p(&sem_barrier, TM_INFINITE);
|
||||||
|
int killBattery=0;
|
||||||
/**************************************************************************************/
|
/**************************************************************************************/
|
||||||
/* The task startRobot starts here */
|
/* The task startRobot starts here */
|
||||||
/**************************************************************************************/
|
/**************************************************************************************/
|
||||||
while (1) {
|
|
||||||
Message* p_mess_answer_battery;
|
Message* p_mess_answer_battery;
|
||||||
Message * msgSend;
|
Message * msgSend;
|
||||||
rt_sem_p(&sem_startRobotWithoutWatchdog, TM_INFINITE);
|
rt_sem_p(&sem_startRobotWithoutWatchdog, TM_INFINITE);
|
||||||
cout << "Start robot without watchdog (";
|
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);
|
rt_mutex_acquire(&mutex_robot, TM_INFINITE);
|
||||||
msgSend = robot.Write(robot.StartWithoutWD());
|
msgSend = robot.Write(robot.StartWithoutWD());
|
||||||
rt_mutex_release(&mutex_robot);
|
rt_mutex_release(&mutex_robot);
|
||||||
cout << msgSend->GetID();
|
cout << msgSend->GetID();
|
||||||
cout << ")" << endl;
|
cout << ")" << endl;
|
||||||
|
|
||||||
cout << "Movement answer: " << msgSend->ToString() << endl << flush;
|
cout << "Movement answer: " << msgSend->ToString() << endl << flush;
|
||||||
WriteInQueue(&q_messageToMon, msgSend); // msgSend will be deleted by sendToMon
|
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);
|
rt_mutex_acquire(&mutex_robotStarted, TM_INFINITE);
|
||||||
robotStarted = 1;
|
robotStarted = 1;
|
||||||
rt_mutex_release(&mutex_robotStarted);
|
rt_mutex_release(&mutex_robotStarted);
|
||||||
rt_task_set_periodic(NULL, TM_NOW, 3000000000);
|
rt_task_set_periodic(NULL, TM_NOW, 500000000);
|
||||||
while (1) {
|
while (killBattery==0) {
|
||||||
rt_task_wait_period(NULL);
|
rt_task_wait_period(NULL);
|
||||||
rt_mutex_acquire(&mutex_robot, TM_INFINITE);
|
rt_mutex_acquire(&mutex_robot, TM_INFINITE);
|
||||||
p_mess_answer_battery = robot.Write(robot.GetBattery());
|
p_mess_answer_battery = robot.Write(robot.GetBattery());
|
||||||
|
@ -375,8 +383,10 @@ void Tasks::StartRobotTaskWithoutWatchdog(void *arg) {
|
||||||
rt_mutex_acquire(&mutex_monitor, TM_INFINITE);
|
rt_mutex_acquire(&mutex_monitor, TM_INFINITE);
|
||||||
monitor.Write(p_mess_answer_battery);
|
monitor.Write(p_mess_answer_battery);
|
||||||
rt_mutex_release(&mutex_monitor);
|
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 */
|
/* The task startRobot starts here */
|
||||||
/**************************************************************************************/
|
/**************************************************************************************/
|
||||||
while (1) {
|
|
||||||
Message* p_mess_answer_battery;
|
Message* p_mess_answer_battery;
|
||||||
Message * msgSend;
|
Message * msgSend;
|
||||||
int cpt=1;
|
int cpt=1;
|
||||||
|
@ -406,6 +415,12 @@ void Tasks::StartRobotTaskWithWatchdog(void *arg) {
|
||||||
rt_mutex_acquire(&mutex_robot, TM_INFINITE);
|
rt_mutex_acquire(&mutex_robot, TM_INFINITE);
|
||||||
msgSend = robot.Write(robot.StartWithWD());
|
msgSend = robot.Write(robot.StartWithWD());
|
||||||
rt_mutex_release(&mutex_robot);
|
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 << msgSend->GetID();
|
||||||
cout << ")" << endl;
|
cout << ")" << endl;
|
||||||
|
|
||||||
|
@ -417,14 +432,15 @@ void Tasks::StartRobotTaskWithWatchdog(void *arg) {
|
||||||
rt_mutex_acquire(&mutex_robotStarted, TM_INFINITE);
|
rt_mutex_acquire(&mutex_robotStarted, TM_INFINITE);
|
||||||
robotStarted = 1;
|
robotStarted = 1;
|
||||||
rt_mutex_release(&mutex_robotStarted);
|
rt_mutex_release(&mutex_robotStarted);
|
||||||
rt_task_set_periodic(NULL, TM_NOW, 300000000);
|
rt_task_set_periodic(NULL, TM_NOW, 500000000);
|
||||||
while (1) {
|
while (1) {
|
||||||
cpt++;
|
cpt++;
|
||||||
rt_task_wait_period(NULL);
|
if(cpt%2==0){
|
||||||
rt_mutex_acquire(&mutex_robot, TM_INFINITE);
|
rt_mutex_acquire(&mutex_robot, TM_INFINITE);
|
||||||
robot.Write(robot.ReloadWD());
|
robot.Write(robot.ReloadWD());
|
||||||
rt_mutex_release(&mutex_robot);
|
rt_mutex_release(&mutex_robot);
|
||||||
if(cpt%10==0){
|
}
|
||||||
|
rt_task_wait_period(NULL);
|
||||||
rt_mutex_acquire(&mutex_robot, TM_INFINITE);
|
rt_mutex_acquire(&mutex_robot, TM_INFINITE);
|
||||||
p_mess_answer_battery = robot.Write(robot.GetBattery());
|
p_mess_answer_battery = robot.Write(robot.GetBattery());
|
||||||
rt_mutex_release(&mutex_robot);
|
rt_mutex_release(&mutex_robot);
|
||||||
|
@ -434,8 +450,6 @@ void Tasks::StartRobotTaskWithWatchdog(void *arg) {
|
||||||
cout << endl << flush;
|
cout << endl << flush;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,8 @@ private:
|
||||||
ComMonitor monitor;
|
ComMonitor monitor;
|
||||||
ComRobot robot;
|
ComRobot robot;
|
||||||
int robotStarted = 0;
|
int robotStarted = 0;
|
||||||
|
int killBatteryBool = 0;
|
||||||
|
int killRobotWithoutWd = 0;
|
||||||
int move = MESSAGE_ROBOT_STOP;
|
int move = MESSAGE_ROBOT_STOP;
|
||||||
|
|
||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
|
@ -85,6 +87,7 @@ private:
|
||||||
RT_MUTEX mutex_robot;
|
RT_MUTEX mutex_robot;
|
||||||
RT_MUTEX mutex_robotStarted;
|
RT_MUTEX mutex_robotStarted;
|
||||||
RT_MUTEX mutex_move;
|
RT_MUTEX mutex_move;
|
||||||
|
RT_MUTEX mutex_kill_battery;
|
||||||
|
|
||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
/* Semaphores */
|
/* Semaphores */
|
||||||
|
|
Loading…
Reference in a new issue