1
0
Fork 0
mirror of https://github.com/RobotechLille/cdf2018-principal synced 2024-11-21 23:56:04 +01:00

Différentiation Stop / Brake

This commit is contained in:
Geoffrey Frogeye 2018-02-16 22:13:24 +01:00
parent 89d3bf21cd
commit 98e1bde49d
8 changed files with 85 additions and 25 deletions

View file

@ -34,6 +34,12 @@ struct __attribute__ ((packed)) position {
// Arrête tous les actionneurs // Arrête tous les actionneurs
#define C2AD_STOP 'S' #define C2AD_STOP 'S'
// Stoppe les roues
#define C2AD_BRAKE 'B'
// Laisse les roues libres
#define C2AD_FREE 'F'
// Donne une destination // Donne une destination
#define C2AD_GOTO 'G' #define C2AD_GOTO 'G'
#define C2AD_GOTOs position #define C2AD_GOTOs position

View file

@ -1,9 +1,10 @@
#include "movement.h" #include "movement.h"
#include "position.h"
#include "AC.h" #include "AC.h"
#include "position.h"
void TaskMovement(void *pvParameters) { void TaskMovement(void* pvParameters)
(void) pvParameters; {
(void)pvParameters;
TickType_t xLastWakeTime; TickType_t xLastWakeTime;
TickType_t xFrequency = 100 / portTICK_PERIOD_MS; TickType_t xFrequency = 100 / portTICK_PERIOD_MS;
@ -20,10 +21,9 @@ void TaskMovement(void *pvParameters) {
actuel.o = destination.o; 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 sendAC(movement, NULL, 0); // On rapporte au chef qu'on a terminé l'action en cours
// TODO Mettre en brake brake();
movement = C2AD_STOP;
ulTaskNotifyTake(pdFALSE, portMAX_DELAY); // Mettre en veille jusqu'à l'arrivée de la prochaine instruction ulTaskNotifyTake(pdFALSE, portMAX_DELAY); // Mettre en veille jusqu'à l'arrivée de la prochaine instruction
xLastWakeTime = xTaskGetTickCount(); xLastWakeTime = xTaskGetTickCount();
@ -33,26 +33,58 @@ void TaskMovement(void *pvParameters) {
} }
} }
void onC2AD_STOP() { void brake()
movement = C2AD_STOP; {
movement = C2AD_BRAKE;
// TODO Mettre les IN à ce qu'il faut
}
void onC2AD_BRAKE()
{
brake();
vTaskNotifyGiveFromISR(tMovement, NULL); 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; movement = C2AD_GOTO;
readAC(&destination, sizeof(struct C2AD_GOTOs)); readAC(&destination, sizeof(struct C2AD_GOTOs));
vTaskNotifyGiveFromISR(tMovement, NULL); vTaskNotifyGiveFromISR(tMovement, NULL);
} }
void stop()
void configureMovement() { {
// TODO Configuration des pins brake();
// TODO Actionneurs
movement = C2AD_STOP;
registerRxHandlerAC(C2AD_STOP, onC2AD_STOP);
registerRxHandlerAC(C2AD_GOTO, onC2AD_GOTO);
xTaskCreate(TaskMovement, "Movement", 128, NULL, 2, &tMovement);;
} }
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);
}

View file

@ -17,6 +17,11 @@ TaskHandle_t tMovement;
unsigned char movement; unsigned char movement;
struct C2AD_GOTOs destination; struct C2AD_GOTOs destination;
// Mouvements qui ne dérangent pas la liaison série
void brake();
void freewheel();
void stop();
void TaskMovement(); void TaskMovement();
void configureMovement(); void configureMovement();

View file

@ -23,6 +23,7 @@ void TaskBlink(void *pvParameters) {
} }
} }
int main(void) { int main(void) {
configureAC(); // Doit rester en premier :) configureAC(); // Doit rester en premier :)
configureAF(); // Doit rester en premier :) configureAF(); // Doit rester en premier :)

View file

@ -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("← Position actuelle (%f; %f) (%f°)", debug->actuel.x, debug->actuel.y, debug->actuel.o);
printf(", destination : "); printf(", destination : ");
if (debug->movement == C2AD_STOP) { if (debug->movement == C2AD_BRAKE) {
printf("aucune\n"); printf("ne pas bouger\n");
} else if (debug->movement == C2AD_FREE) {
printf("là où le vent l'emporte\n");
} else { } else {
printf("(%f; %f) (%f°)\n", debug->destination.x, debug->destination.y, debug->destination.o); printf("(%f; %f) (%f°)\n", debug->destination.x, debug->destination.y, debug->destination.o);
} }

View file

@ -18,6 +18,20 @@ void stop()
sendCA(C2AD_STOP, NULL, 0); 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 // Inspiré de https://stackoverflow.com/a/1760819
pthread_mutex_t reponseMutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t reponseMutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t reponseCond = PTHREAD_COND_INITIALIZER; pthread_cond_t reponseCond = PTHREAD_COND_INITIALIZER;

View file

@ -3,7 +3,7 @@
#include "CA.h" #include "CA.h"
void stop(); void brake();
void aller(struct position* pos); void aller(struct position* pos);
#endif #endif

View file

@ -21,7 +21,7 @@ void* TaskParcours(void *pdata)
pos.o = (int) (rand()*360.0/RAND_MAX); pos.o = (int) (rand()*360.0/RAND_MAX);
aller(&pos); aller(&pos);
sleep(1); sleep(1);
stop(); brake();
sleep(2); sleep(2);
} }
@ -51,8 +51,8 @@ int main()
/* pthread_cancel(tParcours); */ /* pthread_cancel(tParcours); */
/* stop(); */ stop();
/* */
deconfigureDebug(); deconfigureDebug();
deconfigureCA(); deconfigureCA();
return EXIT_SUCCESS; return EXIT_SUCCESS;