From 98e1bde49d69a5cbbec91a33e838e77c276fe7d2 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Fri, 16 Feb 2018 22:13:24 +0100 Subject: [PATCH] =?UTF-8?q?Diff=C3=A9rentiation=20Stop=20/=20Brake?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arduino/ACsignals.h | 6 ++++ arduino/movement.c | 70 +++++++++++++++++++++++++++++++++------------ arduino/movement.h | 5 ++++ arduino/principal.c | 1 + chef/src/debug.c | 6 ++-- chef/src/movement.c | 14 +++++++++ chef/src/movement.h | 2 +- chef/src/premier.c | 6 ++-- 8 files changed, 85 insertions(+), 25 deletions(-) diff --git a/arduino/ACsignals.h b/arduino/ACsignals.h index 2e4b35c..75b6ee9 100644 --- a/arduino/ACsignals.h +++ b/arduino/ACsignals.h @@ -34,6 +34,12 @@ struct __attribute__ ((packed)) position { // Arrête tous les actionneurs #define C2AD_STOP 'S' +// Stoppe les roues +#define C2AD_BRAKE 'B' + +// Laisse les roues libres +#define C2AD_FREE 'F' + // Donne une destination #define C2AD_GOTO 'G' #define C2AD_GOTOs position diff --git a/arduino/movement.c b/arduino/movement.c index ddddded..60abba2 100644 --- a/arduino/movement.c +++ b/arduino/movement.c @@ -1,9 +1,10 @@ #include "movement.h" -#include "position.h" #include "AC.h" +#include "position.h" -void TaskMovement(void *pvParameters) { - (void) pvParameters; +void TaskMovement(void* pvParameters) +{ + (void)pvParameters; TickType_t xLastWakeTime; TickType_t xFrequency = 100 / portTICK_PERIOD_MS; @@ -20,10 +21,9 @@ void TaskMovement(void *pvParameters) { actuel.o = destination.o; } - if (true) { // Arrivé à destination + if (true) { // Arrivé à destination sendAC(movement, NULL, 0); // On rapporte au chef qu'on a terminé l'action en cours - // TODO Mettre en brake - movement = C2AD_STOP; + brake(); ulTaskNotifyTake(pdFALSE, portMAX_DELAY); // Mettre en veille jusqu'à l'arrivée de la prochaine instruction xLastWakeTime = xTaskGetTickCount(); @@ -33,26 +33,58 @@ void TaskMovement(void *pvParameters) { } } -void onC2AD_STOP() { - movement = C2AD_STOP; +void brake() +{ + movement = C2AD_BRAKE; + // TODO Mettre les IN à ce qu'il faut +} + +void onC2AD_BRAKE() +{ + brake(); vTaskNotifyGiveFromISR(tMovement, NULL); } -void onC2AD_GOTO() { +void freewheel() +{ + movement = C2AD_FREE; + // TODO Mettre les IN à ce qu'il faut +} + +void onC2AD_FREE() +{ + freewheel(); +} + +void onC2AD_GOTO() +{ movement = C2AD_GOTO; readAC(&destination, sizeof(struct C2AD_GOTOs)); vTaskNotifyGiveFromISR(tMovement, NULL); } - -void configureMovement() { - // TODO Configuration des pins - - movement = C2AD_STOP; - - registerRxHandlerAC(C2AD_STOP, onC2AD_STOP); - registerRxHandlerAC(C2AD_GOTO, onC2AD_GOTO); - - xTaskCreate(TaskMovement, "Movement", 128, NULL, 2, &tMovement);; +void stop() +{ + brake(); + // TODO Actionneurs } +void onC2AD_STOP() +{ + stop(); + sendAC(C2AD_STOP, NULL, 0); +} + +void configureMovement() +{ + // TODO Configuration des pins + + freewheel(); + + registerRxHandlerAC(C2AD_BRAKE, onC2AD_BRAKE); + registerRxHandlerAC(C2AD_STOP, onC2AD_STOP); + registerRxHandlerAC(C2AD_FREE, onC2AD_FREE); + registerRxHandlerAC(C2AD_GOTO, onC2AD_GOTO); + + xTaskCreate(TaskMovement, "Movement", 128, NULL, 2, &tMovement); +} diff --git a/arduino/movement.h b/arduino/movement.h index 41b64b9..0501b5a 100644 --- a/arduino/movement.h +++ b/arduino/movement.h @@ -17,6 +17,11 @@ TaskHandle_t tMovement; unsigned char movement; struct C2AD_GOTOs destination; +// Mouvements qui ne dérangent pas la liaison série +void brake(); +void freewheel(); +void stop(); + void TaskMovement(); void configureMovement(); diff --git a/arduino/principal.c b/arduino/principal.c index c55785f..eb3797b 100644 --- a/arduino/principal.c +++ b/arduino/principal.c @@ -23,6 +23,7 @@ void TaskBlink(void *pvParameters) { } } + int main(void) { configureAC(); // Doit rester en premier :) configureAF(); // Doit rester en premier :) diff --git a/chef/src/debug.c b/chef/src/debug.c index ff2b532..138e428 100644 --- a/chef/src/debug.c +++ b/chef/src/debug.c @@ -23,8 +23,10 @@ void printDebugInfos(struct A2CI_DBGs* debug) { printf("← Position actuelle (%f; %f) (%f°)", debug->actuel.x, debug->actuel.y, debug->actuel.o); printf(", destination : "); - if (debug->movement == C2AD_STOP) { - printf("aucune\n"); + if (debug->movement == C2AD_BRAKE) { + printf("ne pas bouger\n"); + } else if (debug->movement == C2AD_FREE) { + printf("là où le vent l'emporte\n"); } else { printf("(%f; %f) (%f°)\n", debug->destination.x, debug->destination.y, debug->destination.o); } diff --git a/chef/src/movement.c b/chef/src/movement.c index 2f07e5d..d248d53 100644 --- a/chef/src/movement.c +++ b/chef/src/movement.c @@ -18,6 +18,20 @@ void stop() sendCA(C2AD_STOP, NULL, 0); } +void onC2AD_BRAKE() +{ + // On considère que l'arrêt se fait très rapidement pour ne pas + // avoir à attendre le signal de retour de C2AD_BRAKE + registerRxHandler(C2AD_BRAKE, NULL); +} + +void brake() +{ + printf("→ Frein\n"); + registerRxHandler(C2AD_BRAKE, onC2AD_BRAKE); + sendCA(C2AD_BRAKE, NULL, 0); +} + // Inspiré de https://stackoverflow.com/a/1760819 pthread_mutex_t reponseMutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t reponseCond = PTHREAD_COND_INITIALIZER; diff --git a/chef/src/movement.h b/chef/src/movement.h index 5f568e4..caca772 100644 --- a/chef/src/movement.h +++ b/chef/src/movement.h @@ -3,7 +3,7 @@ #include "CA.h" -void stop(); +void brake(); void aller(struct position* pos); #endif diff --git a/chef/src/premier.c b/chef/src/premier.c index 014546d..c2e79a2 100644 --- a/chef/src/premier.c +++ b/chef/src/premier.c @@ -21,7 +21,7 @@ void* TaskParcours(void *pdata) pos.o = (int) (rand()*360.0/RAND_MAX); aller(&pos); sleep(1); - stop(); + brake(); sleep(2); } @@ -51,8 +51,8 @@ int main() /* pthread_cancel(tParcours); */ - /* stop(); */ - /* */ + stop(); + deconfigureDebug(); deconfigureCA(); return EXIT_SUCCESS;