2018-04-30 16:15:47 +02:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <stdio.h>
|
2018-04-30 22:40:20 +02:00
|
|
|
#include <unistd.h>
|
2018-04-30 16:15:47 +02:00
|
|
|
|
2018-05-06 01:14:09 +02:00
|
|
|
#include "debug.h"
|
2018-04-30 22:40:20 +02:00
|
|
|
#include "lcd.h"
|
2018-04-30 16:15:47 +02:00
|
|
|
#include "movement.h"
|
2018-05-06 08:14:51 +02:00
|
|
|
#include "motor.h"
|
2018-04-30 22:40:20 +02:00
|
|
|
#include "parcours.h"
|
2018-04-30 16:15:47 +02:00
|
|
|
#include "points.h"
|
2018-04-30 22:40:20 +02:00
|
|
|
#include "position.h"
|
2018-04-30 16:15:47 +02:00
|
|
|
|
|
|
|
pthread_t tParcours;
|
|
|
|
bool isOrange;
|
|
|
|
struct timespec tempsStart;
|
|
|
|
struct timespec tempsNow;
|
2018-05-06 01:14:09 +02:00
|
|
|
struct timespec tempsEcoule = { 0, 0 };
|
2018-05-02 08:26:35 +02:00
|
|
|
|
|
|
|
void configureParcours()
|
|
|
|
{
|
|
|
|
registerDebugVar("temps", ld, &tempsEcoule.tv_sec);
|
|
|
|
configurePoints();
|
|
|
|
}
|
2018-04-30 16:15:47 +02:00
|
|
|
|
|
|
|
void prepareParcours(bool orange)
|
|
|
|
{
|
|
|
|
isOrange = orange;
|
|
|
|
clearLCD();
|
2018-04-30 22:40:20 +02:00
|
|
|
printfToLCD(LCD_LINE_1, "--:--/%2d:%02d", TEMPS_PARCOURS / 60, TEMPS_PARCOURS % 60);
|
|
|
|
printRightLCD(LCD_LINE_1, "ATT");
|
2018-04-30 16:15:47 +02:00
|
|
|
|
|
|
|
resetPoints();
|
|
|
|
showPoints();
|
2018-04-30 22:40:20 +02:00
|
|
|
printRightLCD(LCD_LINE_2, isOrange ? "Org" : "Vrt");
|
2018-05-06 18:35:26 +02:00
|
|
|
enableConsigne();
|
2018-04-30 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void startParcours()
|
|
|
|
{
|
|
|
|
clock_gettime(CLOCK_REALTIME, &tempsStart);
|
|
|
|
pthread_create(&tParcours, NULL, TaskParcours, NULL); // TODO Start on mutex unlock
|
2018-04-30 22:40:20 +02:00
|
|
|
printRightLCD(LCD_LINE_1, " ");
|
2018-05-02 08:26:35 +02:00
|
|
|
debugSetActive(true);
|
2018-04-30 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void updateTimeDisplay()
|
|
|
|
{
|
2018-04-30 22:40:20 +02:00
|
|
|
printfToLCD(LCD_LINE_1, "%2ld:%02ld", tempsEcoule.tv_sec / 60, tempsEcoule.tv_sec % 60);
|
2018-04-30 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int updateParcours()
|
|
|
|
{
|
|
|
|
clock_gettime(CLOCK_REALTIME, &tempsNow);
|
|
|
|
if ((tempsNow.tv_nsec - tempsStart.tv_nsec) < 0) {
|
|
|
|
tempsEcoule.tv_sec = tempsNow.tv_sec - tempsStart.tv_sec - 1;
|
|
|
|
tempsEcoule.tv_nsec = tempsNow.tv_nsec - tempsStart.tv_nsec + 1000000000UL;
|
|
|
|
} else {
|
|
|
|
tempsEcoule.tv_sec = tempsNow.tv_sec - tempsStart.tv_sec;
|
|
|
|
tempsEcoule.tv_nsec = tempsNow.tv_nsec - tempsStart.tv_nsec;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tempsEcoule.tv_sec >= TEMPS_PARCOURS) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateTimeDisplay();
|
|
|
|
|
|
|
|
return (1000000000UL - tempsEcoule.tv_nsec) / 1000000UL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void stopParcours()
|
|
|
|
{
|
|
|
|
pthread_cancel(tParcours);
|
|
|
|
stop();
|
2018-05-06 18:35:26 +02:00
|
|
|
disableConsigne();
|
2018-04-30 16:15:47 +02:00
|
|
|
|
|
|
|
updateTimeDisplay();
|
2018-04-30 22:40:20 +02:00
|
|
|
printRightLCD(LCD_LINE_1, "FIN");
|
2018-04-30 16:15:47 +02:00
|
|
|
showPoints();
|
2018-05-02 08:26:35 +02:00
|
|
|
debugSetActive(false);
|
2018-04-30 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void* TaskParcours(void* pdata)
|
|
|
|
{
|
|
|
|
(void)pdata;
|
|
|
|
|
2018-05-06 18:35:26 +02:00
|
|
|
struct position dest1 = {0, 0, 0};
|
|
|
|
setDestination(&dest1);
|
2018-05-06 12:50:03 +02:00
|
|
|
|
2018-05-06 18:35:26 +02:00
|
|
|
sleep(1);
|
|
|
|
|
2018-05-07 20:25:38 +02:00
|
|
|
struct position dest2 = {0, 0, M_PI_2};
|
2018-05-06 18:35:26 +02:00
|
|
|
setDestination(&dest2);
|
|
|
|
|
2018-05-07 20:25:38 +02:00
|
|
|
sleep(10);
|
|
|
|
|
|
|
|
stop();
|
|
|
|
|
2018-05-06 18:35:26 +02:00
|
|
|
/* */
|
|
|
|
/* struct position dest3 = {1000, 1000, 0}; */
|
|
|
|
/* setDestination(&dest3); */
|
|
|
|
/* */
|
|
|
|
/* sleep(5); */
|
2018-04-30 16:15:47 +02:00
|
|
|
|
2018-05-07 20:25:38 +02:00
|
|
|
|
|
|
|
|
2018-04-30 16:15:47 +02:00
|
|
|
return NULL;
|
|
|
|
}
|