1
0
Fork 0
mirror of https://github.com/RobotechLille/cdf2018-principal synced 2024-05-20 13:49:37 +02:00
cdf2018-principal/chef/src/diagnostics.c

100 lines
2.1 KiB
C
Raw Normal View History

2018-05-01 14:51:41 +02:00
#include <unistd.h>
#include "diagnostics.h"
#include "buttons.h"
#include "lcd.h"
#include "CF.h"
2018-05-02 08:26:35 +02:00
#include "movement.h"
2018-05-01 14:51:41 +02:00
bool recu;
void setRecu()
{
recu = true;
}
2018-05-02 08:26:35 +02:00
bool diagFPGA(void* arg)
2018-05-01 14:51:41 +02:00
{
2018-05-02 08:26:35 +02:00
(void) arg;
2018-05-01 14:51:41 +02:00
recu = false;
registerRxHandler(C2FD_PING, setRecu);
sendCF(C2FD_PING, NULL, 0);
for (int i = 0; i <= DIAGNOSTIC_SERIAL_TIMEOUT; i += DIAGNOSTIC_POLL_INTERVAL) {
if (recu) {
break;
}
usleep(DIAGNOSTIC_POLL_INTERVAL * 1000);
}
return recu;
}
2018-05-02 08:26:35 +02:00
bool diagArduino(void* arg)
2018-05-01 14:51:41 +02:00
{
2018-05-02 08:26:35 +02:00
(void) arg;
2018-05-01 14:51:41 +02:00
return false;
}
2018-05-02 08:26:35 +02:00
bool diagCodeuse(void* arg)
{
int i = *((int*) arg);
long lCod, rCod;
getCoders(&lCod, &rCod);
float tension = DIAGNOSTIC_TENSION_TEST;
if (i % 2 == 1) { // Arrière
tension = - tension;
}
printf("49 %f\n", tension);
if (i < 2) {
changerMoteurs(tension, 0);
} else {
changerMoteurs(0, tension);
}
usleep(500*1000);
brake();
long lCodn, rCodn;
getCoders(&lCodn, &rCodn);
long diff;
printf("60 %ld %ld %ld %ld\n", lCod, lCodn, rCod, rCodn);
if (i < 2) {
diff = lCodn - lCod;
} else {
diff = rCodn - rCod;
}
printf("65 %ld\n", diff);
if (i % 2 == 0) { // Avant
return (diff > DIAGNOSTIC_CODEUSES_DIFF_MIN);
} else { // Arrière
return (-diff > DIAGNOSTIC_CODEUSES_DIFF_MIN);
}
}
void execDiagnostic(char *name, bool (*diagnostic)(void* arg), void* arg)
2018-05-01 14:51:41 +02:00
{
clearLCD();
printToLCD(LCD_LINE_1, name);
printToLCD(LCD_LINE_2, "...");
2018-05-02 08:26:35 +02:00
bool res = diagnostic(arg);
2018-05-01 14:51:41 +02:00
if (res) {
printToLCD(LCD_LINE_2, "Ok!");
usleep(DIAGNOSTIC_INTERVAL * 1000);
} else {
printToLCD(LCD_LINE_2, "Echec!");
pressedButton(BUT_BLOCK);
}
}
void runDiagnostics()
{
2018-05-02 08:26:35 +02:00
execDiagnostic("Lien FPGA", diagFPGA, NULL);
2018-05-01 14:51:41 +02:00
/* execDiagnostic("Lien Arduino", diagArduino); */
2018-05-02 08:26:35 +02:00
int i;
i = 0; execDiagnostic("Mot+Cod L AV", diagCodeuse, &i);
i = 1; execDiagnostic("Mot+Cod L AR", diagCodeuse, &i);
i = 2; execDiagnostic("Mot+Cod R AV", diagCodeuse, &i);
i = 3; execDiagnostic("Mot+Cod R AR", diagCodeuse, &i);
2018-05-01 14:51:41 +02:00
}