2018-05-01 14:51:41 +02:00
|
|
|
#include <unistd.h>
|
2018-05-05 15:56:39 +02:00
|
|
|
#include <stdio.h>
|
2018-05-01 14:51:41 +02:00
|
|
|
|
|
|
|
#include "diagnostics.h"
|
|
|
|
#include "buttons.h"
|
|
|
|
#include "lcd.h"
|
|
|
|
|
|
|
|
#include "CF.h"
|
2018-05-06 08:14:51 +02:00
|
|
|
#include "motor.h"
|
2018-05-05 15:56:39 +02:00
|
|
|
#include "imu.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);
|
|
|
|
}
|
2018-05-06 01:14:09 +02:00
|
|
|
registerRxHandler(C2FD_PING, NULL);
|
2018-05-01 14:51:41 +02:00
|
|
|
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) {
|
2018-05-06 08:14:51 +02:00
|
|
|
setPWMTension(tension, 0);
|
2018-05-02 08:26:35 +02:00
|
|
|
} else {
|
2018-05-06 08:14:51 +02:00
|
|
|
setPWMTension(0, tension);
|
2018-05-02 08:26:35 +02:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-05 15:56:39 +02:00
|
|
|
bool diagIMU(void* arg)
|
|
|
|
{
|
|
|
|
(void) arg;
|
|
|
|
return connectedIMU();
|
|
|
|
}
|
|
|
|
|
2018-05-02 08:26:35 +02:00
|
|
|
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-05 15:56:39 +02:00
|
|
|
execDiagnostic("Lien IMU", diagIMU, NULL);
|
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
|
|
|
}
|
|
|
|
|