Màj batterie et démarrage robot

This commit is contained in:
Romain Vitrat 2020-03-26 16:47:36 +01:00
parent 6ffb7b6773
commit db9216cd7f
5 changed files with 32 additions and 47 deletions

View file

@ -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;

View file

@ -7,12 +7,7 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/home/romainv/Documents/temps_reel/dumber/software/raspberry/superviseur-robot/lib/comrobot.h</file>
<file>file:/home/romainv/Documents/temps_reel/dumber/software/raspberry/superviseur-robot/lib/commonitor.cpp</file>
<file>file:/home/romainv/Documents/temps_reel/dumber/software/raspberry/superviseur-robot/lib/commonitor.h</file>
<file>file:/home/romainv/Documents/temps_reel/dumber/software/raspberry/superviseur-robot/lib/messages.h</file>
<file>file:/home/romainv/Documents/temps_reel/dumber/software/raspberry/superviseur-robot/tasks.h</file>
<file>file:/home/romainv/Documents/temps_reel/dumber/software/raspberry/superviseur-robot/tasks.cpp</file>
<file>file:/home/romainv/Documents/temps_reel/dumber1/software/raspberry/superviseur-robot/tasks.h</file>
</group>
</open-files>
</project-private>

View file

@ -355,13 +355,10 @@ 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);
@ -369,20 +366,17 @@ void Tasks::StartRobotTaskWithoutWatchdog(void *arg) {
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
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);
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,18 +414,18 @@ 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);
cpt++;
if(cpt==2){
robot.Write(robot.ReloadWD());
if(cpt%10==0){
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;
}
}

View file

@ -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;

View file

@ -6,8 +6,6 @@
</data>
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/home/romainv/Documents/temps_reel/dumber/software/simulateur/main.cpp</file>
</group>
<group/>
</open-files>
</project-private>