From af080ac4bfa58e8531c9f39078528acfa018d0a7 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Mon, 26 Mar 2018 10:06:32 +0200 Subject: [PATCH] =?UTF-8?q?Travail=20inachev=C3=A9=20avec=20Arduino?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Connexions.md | 15 ++++++++++++ arduino/ACsignals.h | 4 ++++ arduino/AFsignals.h | 4 ++-- arduino/debug.c | 3 +++ arduino/position.c | 56 ++++++++++++++++++++++++++++++++------------ arduino/position.h | 4 ++++ chef/src/AFsignals.h | 1 + chef/src/debug.c | 16 +++++++++---- chef/src/premier.c | 6 ++--- 9 files changed, 84 insertions(+), 25 deletions(-) create mode 100644 Connexions.md create mode 120000 chef/src/AFsignals.h diff --git a/Connexions.md b/Connexions.md new file mode 100644 index 0000000..2f44dbb --- /dev/null +++ b/Connexions.md @@ -0,0 +1,15 @@ +# Connexions + +Ce document a pour but de recenser les connexions entre les différents composants du robot. + +## Liste des composants + +- Raspberry Pi 3 (RPi) +- Arduino Mega 2560 (Ard) +- Micronova Mercury FPGA (FPGA) +- HEDM-550X Encodeur moteur gauche +- HEDM-550X Encodeur moteur droit + +## Connexions de puissance + +## Connexions d'information diff --git a/arduino/ACsignals.h b/arduino/ACsignals.h index 75b6ee9..33668fe 100644 --- a/arduino/ACsignals.h +++ b/arduino/ACsignals.h @@ -5,6 +5,8 @@ #ifndef __ACSIGNALS_H_ #define __ACSIGNALS_H_ +#include "AFsignals.h" + #define AC_BAUDRATE 9600UL // Structures used everywhere @@ -62,6 +64,8 @@ struct __attribute__ ((packed)) A2CI_DBGs { struct position actuel; struct position destination; unsigned char movement; + struct F2AI_CODERs deltaCoder; + uint16_t nbCalcPos; // ... }; diff --git a/arduino/AFsignals.h b/arduino/AFsignals.h index 0c7798d..8f4f074 100644 --- a/arduino/AFsignals.h +++ b/arduino/AFsignals.h @@ -41,8 +41,8 @@ struct __attribute__ ((packed)) F2AD_ERRs { // Récupère les valeur des encodeurs #define F2AI_CODER 'D' struct __attribute__ ((packed)) F2AI_CODERs { - int16_t left; - int16_t right; + int16_t dL; + int16_t dR; }; // Récupère les valeur des capteurs de distance diff --git a/arduino/debug.c b/arduino/debug.c index af9650b..19287d0 100644 --- a/arduino/debug.c +++ b/arduino/debug.c @@ -13,7 +13,10 @@ void TaskDebug(void *pvParameters) { // Copie des valeurs à envoyer en debug memcpy((void*) &debug.actuel, (const void*) &actuel, (unsigned long) sizeof(actuel)); memcpy((void*) &debug.destination, (const void*) &destination, (unsigned long) sizeof(destination)); + memcpy((void*) &debug.deltaCoder, (const void*) &deltaCoder, (unsigned long) sizeof(deltaCoder)); debug.movement = movement; + debug.nbCalcPos = nbCalcPos; + nbCalcPos = 0; // Envoi des valeurs sendAC(A2CI_DBG, &debug, sizeof(debug)); diff --git a/arduino/position.c b/arduino/position.c index 8809e3a..6562f3c 100644 --- a/arduino/position.c +++ b/arduino/position.c @@ -1,25 +1,51 @@ #include "position.h" #include "AC.h" +#include "AF.h" +#include "dimensions.h" -void TaskPosition(void *pvParameters) { - (void) pvParameters; - TickType_t xLastWakeTime; - TickType_t xFrequency = 100 / portTICK_PERIOD_MS; +void TaskPosition(void* pvParameters) +{ + (void)pvParameters; + + const TickType_t xDelay = 500 / portTICK_PERIOD_MS; - ulTaskNotifyTake(pdFALSE, portMAX_DELAY); // TODO Dummy - xLastWakeTime = xTaskGetTickCount(); for (;;) { - vTaskDelayUntil(&xLastWakeTime, xFrequency); + sendAF(F2AI_CODER, NULL, 0); + + ulTaskNotifyTake(pdFALSE, portMAX_DELAY); // Wait until new information has arrived + + nbCalcPos++; + + float adjacent = DISTANCE_BETWEEN_WHEELS; + float opposite = deltaCoder.dR - deltaCoder.dL; + float deltaO = atan(opposite / adjacent); + + float deltaD = (deltaCoder.dL + deltaCoder.dR) / 2; + + actuel.o += deltaO; + float deltaX = deltaD * cos(actuel.o); + float deltaY = deltaD * sin(actuel.o); + actuel.x += deltaX; + actuel.y += deltaY; + + vTaskDelay(xDelay); } } - - -void configurePosition() { - actuel.x = 0; - actuel.y = 0; - actuel.o = 90; - - xTaskCreate(TaskPosition, "Position", 128, NULL, 2, &tPosition);; +void onF2AI_CODER() +{ + readAF(&deltaCoder, sizeof(struct F2AI_CODERs)); + vTaskNotifyGiveFromISR(tPosition, NULL); } +void configurePosition() +{ + actuel.x = 0; + actuel.y = 0; + actuel.o = 0; + + registerRxHandlerAF(F2AI_CODER, onF2AI_CODER); + + xTaskCreate(TaskPosition, "Position", 128, NULL, 2, &tPosition); + ; +} diff --git a/arduino/position.h b/arduino/position.h index 528f1f9..5fca31a 100644 --- a/arduino/position.h +++ b/arduino/position.h @@ -9,11 +9,15 @@ #include #include "ACsignals.h" +#include "AFsignals.h" struct position actuel; +struct F2AI_CODERs deltaCoder; TaskHandle_t tPosition; +uint16_t nbCalcPos; + void TaskPosition(); void configurePosition(); diff --git a/chef/src/AFsignals.h b/chef/src/AFsignals.h new file mode 120000 index 0000000..d3658b4 --- /dev/null +++ b/chef/src/AFsignals.h @@ -0,0 +1 @@ +../../arduino/AFsignals.h \ No newline at end of file diff --git a/chef/src/debug.c b/chef/src/debug.c index 138e428..4431d4f 100644 --- a/chef/src/debug.c +++ b/chef/src/debug.c @@ -21,14 +21,20 @@ void* TaskDebug(void* pdata) void printDebugInfos(struct A2CI_DBGs* debug) { - printf("← Position actuelle (%f; %f) (%f°)", debug->actuel.x, debug->actuel.y, debug->actuel.o); - printf(", destination : "); + // Position + printf("← + % .6g; % .6g % .6g°", debug->actuel.x, debug->actuel.y, debug->actuel.o); + // Frequence de calcul de la position + printf(" % 5d☼", debug->nbCalcPos); + // Delta codeuses + printf(", %5d↿↾%-5d", debug->deltaCoder.dL, debug->deltaCoder.dR); + // Destination + printf(", "); if (debug->movement == C2AD_BRAKE) { - printf("ne pas bouger\n"); + printf("⇞ \n"); } else if (debug->movement == C2AD_FREE) { - printf("là où le vent l'emporte\n"); + printf("↕ \n"); } else { - printf("(%f; %f) (%f°)\n", debug->destination.x, debug->destination.y, debug->destination.o); + printf("↑ % .6g; % .6g % .6g°\n", debug->destination.x, debug->destination.y, debug->destination.o); } } diff --git a/chef/src/premier.c b/chef/src/premier.c index c2e79a2..417b7d6 100644 --- a/chef/src/premier.c +++ b/chef/src/premier.c @@ -8,7 +8,7 @@ #include "movement.h" #include "debug.h" -#define TEMPSMAX 10 +#define TEMPSMAX 60 void* TaskParcours(void *pdata) { @@ -42,8 +42,8 @@ int main() /* printf("En attente de la tirette...\n"); // TODO */ printf("C'est parti !\n"); - pthread_t tParcours; - pthread_create(&tParcours, NULL, TaskParcours, NULL); + /* pthread_t tParcours; */ + /* pthread_create(&tParcours, NULL, TaskParcours, NULL); */ sleep(TEMPSMAX);