]> rtime.felk.cvut.cz Git - eurobot/public.git/blob - src/robofsm/match-timing.c
Merge branch 'master' of eurobot@sojka:git
[eurobot/public.git] / src / robofsm / match-timing.c
1 #include "match-timing.h"
2 #include "robot.h"
3
4 #ifdef COMPETITION
5 #define COMPETITION_TIME_DEFAULT        90
6 #define TIME_TO_DEPOSITE_DEFAULT        60
7 #else
8 #define COMPETITION_TIME_DEFAULT        90
9 #define TIME_TO_DEPOSITE_DEFAULT        60
10 #endif
11
12 /* competition time in seconds */
13 #define COMPETITION_TIME        COMPETITION_TIME_DEFAULT
14 #define TIME_TO_DEPOSITE        TIME_TO_DEPOSITE_DEFAULT
15 /* competition time in seconds */
16
17
18
19 /** *********************************************************************
20  * Competition timer. Stop robot when the timer exceeds.
21  ********************************************************************** */
22
23 void *timing_thread(void *arg)
24 {
25         struct timespec start;
26         
27         sem_wait(&robot.start);
28         clock_gettime(CLOCK_MONOTONIC, &start);
29 #define WAIT(sec)                                                       \
30         do {                                                            \
31                 struct timespec t;                                      \
32                 t.tv_sec = start.tv_sec+sec;                            \
33                 t.tv_nsec = start.tv_nsec;                              \
34                 clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &t, NULL); \
35         } while(0)
36
37 //      WAIT(5);
38 //      // microswitch (backside opponent detector), ignore it while at starting point
39 //      robot.use_back_switch = true;
40 //      printf("Back switch not ignored\n");
41
42         WAIT(TIME_TO_DEPOSITE);
43         robot.short_time_to_end = true;
44
45         WAIT(COMPETITION_TIME);
46         printf("%d seconds timer exceeded! exiting!\n", COMPETITION_TIME);
47         robot_exit();
48
49         return NULL;
50 }
51