1
0
Fork 0
mirror of https://github.com/RobotechLille/cdf2018-principal synced 2024-06-01 18:45:01 +02:00
This commit is contained in:
Geoffrey Frogeye 2018-05-02 08:26:35 +02:00
parent 48b2901da4
commit fc1c7786da
13 changed files with 124 additions and 36 deletions

View file

@ -10,7 +10,7 @@
#define FPGA_PORTNAME "/dev/ttyUSB0" #define FPGA_PORTNAME "/dev/ttyUSB0"
#define CF_BAUDRATE B115200 #define CF_BAUDRATE B115200
#define PRINTRAWDATA // #define PRINTRAWDATA
int fpga; int fpga;
pthread_mutex_t sSendCF; pthread_mutex_t sSendCF;

View file

@ -40,6 +40,13 @@ struct timespec debugStart;
struct timespec debugNow; struct timespec debugNow;
struct timespec debugEcoule; struct timespec debugEcoule;
int debugInterval = DEBUG_INTERVAL_IDLE;
void debugSetActive(bool active)
{
debugInterval = active ? DEBUG_INTERVAL_ACTIVE : DEBUG_INTERVAL_IDLE;
}
void* TaskDebug(void* pdata) void* TaskDebug(void* pdata)
{ {
(void)pdata; (void)pdata;
@ -90,7 +97,7 @@ void* TaskDebug(void* pdata)
fprintf(debugFd, "\n"); fprintf(debugFd, "\n");
fflush(debugFd); fflush(debugFd);
usleep(DEBUG_INTERVAL * 1000); usleep(debugInterval * 1000);
} }
return NULL; return NULL;

View file

@ -3,13 +3,20 @@
#include <pthread.h> #include <pthread.h>
#include <time.h> #include <time.h>
#include <stdbool.h>
// Constantes // Constantes
#define DEBUG_INTERVAL 100 #define DEBUG_INTERVAL_IDLE 50
#define DEBUG_INTERVAL_ACTIVE 1000
// Structures // Structures
enum debugArgTypes {d, f, ld, lf, s}; enum debugArgTypes {
d,
f,
ld,
lf,
s
};
struct debugArg { struct debugArg {
enum debugArgTypes type; enum debugArgTypes type;
@ -17,12 +24,12 @@ struct debugArg {
struct debugArg* next; struct debugArg* next;
}; };
// Public // Public
void configureDebug(); // Avant tous les configure void configureDebug(); // Avant tous les configure
void registerDebugVar(char* name, enum debugArgTypes type, void* var); void registerDebugVar(char* name, enum debugArgTypes type, void* var);
void startDebug(); // Après tous les configure void startDebug(); // Après tous les configure
void deconfigureDebug(); void deconfigureDebug();
void debugSetActive(bool active);
// Private // Private
void* TaskDebug(void* pdata); void* TaskDebug(void* pdata);

View file

@ -5,6 +5,7 @@
#include "lcd.h" #include "lcd.h"
#include "CF.h" #include "CF.h"
#include "movement.h"
bool recu; bool recu;
@ -13,8 +14,10 @@ void setRecu()
recu = true; recu = true;
} }
bool diagFPGA() bool diagFPGA(void* arg)
{ {
(void) arg;
recu = false; recu = false;
registerRxHandler(C2FD_PING, setRecu); registerRxHandler(C2FD_PING, setRecu);
sendCF(C2FD_PING, NULL, 0); sendCF(C2FD_PING, NULL, 0);
@ -28,17 +31,52 @@ bool diagFPGA()
return recu; return recu;
} }
bool diagArduino() bool diagArduino(void* arg)
{ {
(void) arg;
return false; return false;
} }
void execDiagnostic(char *name, bool (*diagnostic)(void)) 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)
{ {
clearLCD(); clearLCD();
printToLCD(LCD_LINE_1, name); printToLCD(LCD_LINE_1, name);
printToLCD(LCD_LINE_2, "..."); printToLCD(LCD_LINE_2, "...");
bool res = diagnostic(); bool res = diagnostic(arg);
if (res) { if (res) {
printToLCD(LCD_LINE_2, "Ok!"); printToLCD(LCD_LINE_2, "Ok!");
usleep(DIAGNOSTIC_INTERVAL * 1000); usleep(DIAGNOSTIC_INTERVAL * 1000);
@ -50,7 +88,12 @@ void execDiagnostic(char *name, bool (*diagnostic)(void))
void runDiagnostics() void runDiagnostics()
{ {
execDiagnostic("Lien FPGA", diagFPGA); execDiagnostic("Lien FPGA", diagFPGA, NULL);
/* execDiagnostic("Lien Arduino", diagArduino); */ /* execDiagnostic("Lien Arduino", diagArduino); */
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);
} }

View file

@ -8,10 +8,13 @@
#define DIAGNOSTIC_POLL_INTERVAL 100 #define DIAGNOSTIC_POLL_INTERVAL 100
#define DIAGNOSTIC_SERIAL_TIMEOUT 10000 #define DIAGNOSTIC_SERIAL_TIMEOUT 10000
#define DIAGNOSTIC_TENSION_TEST 1
#define DIAGNOSTIC_CODEUSES_DIFF_MIN 1000
// Public // Public
void runDiagnostics(); void runDiagnostics();
// Private // Private
void execDiagnostic(char *name, bool (*diagnostic)(void)); void execDiagnostic(char *name, bool (*diagnostic)(void* arg), void* arg);
#endif #endif

View file

@ -2,13 +2,11 @@
#include <signal.h> #include <signal.h>
#include <time.h> #include <time.h>
#include "ihm.h"
#include "movement.h"
#include "parcours.h"
#include "points.h"
#include "lcd.h"
#include "buttons.h" #include "buttons.h"
#include "diagnostics.h" #include "diagnostics.h"
#include "ihm.h"
#include "lcd.h"
#include "parcours.h"
// Globales // Globales
pthread_t tIHM; pthread_t tIHM;
@ -18,6 +16,7 @@ void configureIHM()
{ {
initLCD(); initLCD();
printToLCD(LCD_LINE_1, "Demarrage"); printToLCD(LCD_LINE_1, "Demarrage");
configureParcours();
} }
void startIHM() void startIHM()
@ -66,6 +65,20 @@ void* TaskIHM(void* pdata)
/* } */ /* } */
/* } */ /* } */
// Diagnostics
for (;;) {
clearLCD();
printToLCD(LCD_LINE_1, "Diagnostiquer");
bout = pressedButton(BUT_BLOCK);
if (bout == rouge) {
clearLCD();
runDiagnostics();
} else if (bout == jaune) {
break;
}
}
// Couleur // Couleur
for (;;) { for (;;) {
clearLCD(); clearLCD();
@ -82,7 +95,6 @@ void* TaskIHM(void* pdata)
// Calibrage // Calibrage
for (;;) { for (;;) {
clearLCD(); clearLCD();
printf("84 %ld\n", calibrageLast.tv_sec);
if (calibrageLast.tv_sec > 0) { if (calibrageLast.tv_sec > 0) {
clock_gettime(CLOCK_REALTIME, &calibrageNow); clock_gettime(CLOCK_REALTIME, &calibrageNow);
if ((calibrageNow.tv_nsec - calibrageLast.tv_nsec) > 0) { if ((calibrageNow.tv_nsec - calibrageLast.tv_nsec) > 0) {
@ -110,20 +122,6 @@ void* TaskIHM(void* pdata)
} }
} }
// Diagnostics
for (;;) {
clearLCD();
printToLCD(LCD_LINE_1, "Diagnostiquer");
bout = pressedButton(BUT_BLOCK);
if (bout == rouge) {
clearLCD();
runDiagnostics();
} else if (bout == jaune) {
break;
}
}
// Parcours // Parcours
for (;;) { for (;;) {
clearLCD(); clearLCD();

View file

@ -8,12 +8,19 @@
#include "parcours.h" #include "parcours.h"
#include "points.h" #include "points.h"
#include "position.h" #include "position.h"
#include "debug.h"
pthread_t tParcours; pthread_t tParcours;
bool isOrange; bool isOrange;
struct timespec tempsStart; struct timespec tempsStart;
struct timespec tempsNow; struct timespec tempsNow;
struct timespec tempsEcoule; struct timespec tempsEcoule = {0, 0};
void configureParcours()
{
registerDebugVar("temps", ld, &tempsEcoule.tv_sec);
configurePoints();
}
void prepareParcours(bool orange) void prepareParcours(bool orange)
{ {
@ -32,6 +39,7 @@ void startParcours()
clock_gettime(CLOCK_REALTIME, &tempsStart); clock_gettime(CLOCK_REALTIME, &tempsStart);
pthread_create(&tParcours, NULL, TaskParcours, NULL); // TODO Start on mutex unlock pthread_create(&tParcours, NULL, TaskParcours, NULL); // TODO Start on mutex unlock
printRightLCD(LCD_LINE_1, " "); printRightLCD(LCD_LINE_1, " ");
debugSetActive(true);
} }
void updateTimeDisplay() void updateTimeDisplay()
@ -67,6 +75,7 @@ void stopParcours()
updateTimeDisplay(); updateTimeDisplay();
printRightLCD(LCD_LINE_1, "FIN"); printRightLCD(LCD_LINE_1, "FIN");
showPoints(); showPoints();
debugSetActive(false);
} }
#define UP_TIME 1000 #define UP_TIME 1000

View file

@ -5,6 +5,7 @@
#define TEMPS_PARCOURS 100 #define TEMPS_PARCOURS 100
void configureParcours();
void prepareParcours(bool orange); void prepareParcours(bool orange);
void startParcours(); void startParcours();
// Returns : -1 if parcours ended, N ms for the next time it should be checked // Returns : -1 if parcours ended, N ms for the next time it should be checked

View file

@ -1,9 +1,15 @@
#include <stdio.h> #include <stdio.h>
#include "lcd.h" #include "lcd.h"
#include "debug.h"
int points; int points;
void configurePoints()
{
registerDebugVar("points", d, &points);
}
void resetPoints() void resetPoints()
{ {
points = 0; points = 0;

View file

@ -2,6 +2,7 @@
#define __POINTS_H__ #define __POINTS_H__
// Public // Public
void configurePoints();
void resetPoints(); void resetPoints();
int getPoints(); int getPoints();
void addPoints(int points); void addPoints(int points);

View file

@ -83,3 +83,10 @@ void deconfigurePosition()
{ {
pthread_cancel(tPosition); pthread_cancel(tPosition);
} }
void getCoders(long* l, long* r)
{
*l = lCodTot;
*r = rCodTot;
}

View file

@ -19,6 +19,7 @@ struct __attribute__ ((packed)) position {
// Fonctions // Fonctions
void configurePosition(); void configurePosition();
void deconfigurePosition(); void deconfigurePosition();
void getCoders(long* l, long* r);
#endif #endif

View file

@ -11,3 +11,8 @@ export PS1="[\u@\h \W] "
export PS2="> " export PS2="> "
export PS3="+ " export PS3="+ "
export PS4="- " export PS4="- "
alias r="/etc/init.d/S50chef restart"
alias s="/etc/init.d/S50chef stop"
alias c="cd /opt/chef/"
alias l="tail -f $(find /opt/chef/log | sort | tail -1)"