From 48b2901da4c049a2c0b7d2994d3bd5477e8fdf39 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Wed, 2 May 2018 05:51:14 +0200 Subject: [PATCH] Misc --- chef/Makefile | 2 +- chef/src/CF.h | 2 +- chef/src/debug.c | 4 +- chef/src/movement.c | 5 +- chef/src/position.c | 19 +++++- chef/src/testForward.c | 10 +-- chef/src/testUpDown.c | 62 +++++++++++++++++++ log/.gitignore | 2 + raspberrypi/Makefile | 4 ++ .../rootfs_overlay/etc/extra.d/S40wifi | 3 +- 10 files changed, 99 insertions(+), 14 deletions(-) create mode 100644 chef/src/testUpDown.c create mode 100644 log/.gitignore diff --git a/chef/Makefile b/chef/Makefile index d70df86..71efb31 100644 --- a/chef/Makefile +++ b/chef/Makefile @@ -5,7 +5,7 @@ CC=gcc # Bibliothèques LIBS= ## Drapeaux pour le linker -LDFLAGS_CUSTOM += -lpthread -lwiringPi +LDFLAGS_CUSTOM += -lpthread -lwiringPi -lm ## Drapeaux pour le compilateur CFLAGS_CUSTOM += -g ## Générateurs de drapeaux pour les bibliothèques diff --git a/chef/src/CF.h b/chef/src/CF.h index af20ca1..d43d455 100644 --- a/chef/src/CF.h +++ b/chef/src/CF.h @@ -10,7 +10,7 @@ #define FPGA_PORTNAME "/dev/ttyUSB0" #define CF_BAUDRATE B115200 -// #define PRINTRAWDATA +#define PRINTRAWDATA int fpga; pthread_mutex_t sSendCF; diff --git a/chef/src/debug.c b/chef/src/debug.c index 09b4682..c8e0795 100644 --- a/chef/src/debug.c +++ b/chef/src/debug.c @@ -26,7 +26,7 @@ int nextId() if (d) { while ((dir = readdir(d)) != NULL) { - ret = sscanf(dir->d_name, "%d", &id); + ret = sscanf(dir->d_name, "%06d", &id); if (ret == 1 && id > maxId) { maxId = id; } @@ -101,7 +101,7 @@ void configureDebug() // Génération du nom de fichier char path[256]; - sprintf(path, "log/%d.csv", nextId()); + sprintf(path, "log/%06d.csv", nextId()); // Open file debugFd = fopen(path, "w"); diff --git a/chef/src/movement.c b/chef/src/movement.c index 59bb7c6..c6ae718 100644 --- a/chef/src/movement.c +++ b/chef/src/movement.c @@ -34,12 +34,11 @@ int setMoteurTension(float lVolt, float rVolt) msg.in = 0x00; + // TODO Protections + // Gauche bool lFor = lVolt < 0; lVolt = fabs(lVolt); - if (lVolt > MOT_MAX_V) { - lVolt = MOT_MAX_V; - } msg.in |= 1 << (lFor ? IN1 : IN2); msg.ena = tensionToPWM(lVolt); diff --git a/chef/src/position.c b/chef/src/position.c index 1a87006..fe6886f 100644 --- a/chef/src/position.c +++ b/chef/src/position.c @@ -3,12 +3,14 @@ */ #include +#include #include "debug.h" #include "position.h" +#include "dimensions.h" // Globales -struct position actuel; +struct position connu; struct F2CI_CODERs deltaCoders; pthread_mutex_t posPolling; pthread_t tPosition; @@ -42,6 +44,15 @@ void* TaskPosition(void* pData) nbCalcPos++; lCodTot += deltaCoders.dL; rCodTot += deltaCoders.dR; + + float deltaO = atan2(deltaCoders.dR - deltaCoders.dL, DISTANCE_BETWEEN_WHEELS); + float deltaD = (deltaCoders.dL + deltaCoders.dR) / 2; + + connu.o += deltaO; + float deltaX = deltaD * cos(connu.o); + float deltaY = deltaD * sin(connu.o); + connu.x += deltaX; + connu.y += deltaY; } return NULL; @@ -58,6 +69,12 @@ void configurePosition() registerRxHandler(F2CI_CODER, onF2CI_CODER); registerDebugVar("lCodTot", ld, &lCodTot); registerDebugVar("rCodTot", ld, &rCodTot); + connu.x = 0; + connu.y = 0; + connu.o = 0; + registerDebugVar("xConnu", f, &connu.x); + registerDebugVar("yConnu", f, &connu.y); + registerDebugVar("oConnu", f, &connu.o); registerDebugVar("nbCalcPos", d, &nbCalcPos); pthread_create(&tPosition, NULL, TaskPosition, NULL); } diff --git a/chef/src/testForward.c b/chef/src/testForward.c index ee618bd..9487688 100644 --- a/chef/src/testForward.c +++ b/chef/src/testForward.c @@ -12,6 +12,8 @@ #include "movement.h" #include "buttons.h" +#define PATATE 3.3/2 + int main(int argc, char* argv[]) { @@ -29,22 +31,22 @@ int main(int argc, char* argv[]) for (;;) { clearLCD(); printToLCD(LCD_LINE_1, "Forward"); - changerMoteurs(3.3, 3.3); + changerMoteurs(PATATE, PATATE); pressedButton(BUT_BLOCK); clearLCD(); printToLCD(LCD_LINE_1, "Right"); - changerMoteurs(-3.3, 3.3); + changerMoteurs(-PATATE, PATATE); pressedButton(BUT_BLOCK); clearLCD(); printToLCD(LCD_LINE_1, "Left"); - changerMoteurs(-3.3, -3.3); + changerMoteurs(-PATATE, -PATATE); pressedButton(BUT_BLOCK); clearLCD(); printToLCD(LCD_LINE_1, "Backward"); - changerMoteurs(3.3, -3.3); + changerMoteurs(PATATE, -PATATE); pressedButton(BUT_BLOCK); clearLCD(); diff --git a/chef/src/testUpDown.c b/chef/src/testUpDown.c new file mode 100644 index 0000000..2d884ef --- /dev/null +++ b/chef/src/testUpDown.c @@ -0,0 +1,62 @@ +/* Teste si une broche est connecté à une autre */ + +#include +#include +#include +#include +#include +#include + +#include "lcd.h" +#include "CF.h" +#include "movement.h" +#include "buttons.h" + +#define UP_TIME 1000 +#define HIGH_TIME 3000 +#define DOWN_TIME 1000 +#define LOW_TIME 2000 +#define MAXI 3.3 +#define INTERVAL 10 + +void changerMoteursWrapper(float l, float r) { + /* clearLCD(); */ + printfToLCD(LCD_LINE_1, "L: %f", l); + printfToLCD(LCD_LINE_2, "R: %f", r); + changerMoteurs(l, r); +} + +int main(int argc, char* argv[]) +{ + + (void)argc; + (void)argv; + + wiringPiSetup(); + + initI2C(); + initLCD(); + configureCF(); + configureButtons(); + configureMovement(); + + for (;;) { + for (int i = 0; i < UP_TIME; i += INTERVAL) { + float p = (float)i / (float)UP_TIME; + changerMoteursWrapper(p * MOT_MAX_V, p * MOT_MAX_V); + delay(INTERVAL); + } + changerMoteursWrapper(MOT_MAX_V, MOT_MAX_V); + delay(HIGH_TIME); + + for (int i = 0; i < DOWN_TIME; i += INTERVAL) { + float p = (float)i / (float)DOWN_TIME; + p = 1 - p; + changerMoteursWrapper(p * MOT_MAX_V, p * MOT_MAX_V); + delay(INTERVAL); + } + changerMoteursWrapper(0, 0); + delay(LOW_TIME); + } + +} diff --git a/log/.gitignore b/log/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/log/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/raspberrypi/Makefile b/raspberrypi/Makefile index b45cc08..015b9ac 100644 --- a/raspberrypi/Makefile +++ b/raspberrypi/Makefile @@ -125,6 +125,10 @@ restart: ssh -F sshconf principal true ssh -F sshconf principal /etc/init.d/S50chef restart +getlogs: + ssh -F sshconf principal true + rsync --rsh 'ssh -F sshconf' --archive principal:/opt/chef/log/* ../log/ + gdbcommands: echo "set sysroot $(TARGET_DIR)" > "$@" echo "exec-file $(TARGET_DIR)$(EXECDIR)$(EXECPATH)" >> "$@" diff --git a/raspberrypi/board/robotech/cdfprincipal/rootfs_overlay/etc/extra.d/S40wifi b/raspberrypi/board/robotech/cdfprincipal/rootfs_overlay/etc/extra.d/S40wifi index f3333fa..3609e06 100755 --- a/raspberrypi/board/robotech/cdfprincipal/rootfs_overlay/etc/extra.d/S40wifi +++ b/raspberrypi/board/robotech/cdfprincipal/rootfs_overlay/etc/extra.d/S40wifi @@ -7,6 +7,7 @@ start() { printf "Starting Wi-Fi connection: " # modprobe brcmfmac modprobe r8188eu + modprobe 8192cu ifup wlan0 echo "OK" } @@ -14,8 +15,6 @@ start() { stop() { printf "Stopping Wi-Fi connection: " ifdown wlan0 - # rmmod brcmfmac - rmmod r8188eu echo "OK" }