1
0
Fork 0
mirror of https://github.com/RobotechLille/cdf2018-principal synced 2024-06-29 14:39:01 +02:00
cdf2018-principal/arduino/movement.c

59 lines
1.6 KiB
C
Raw Normal View History

2018-02-14 18:07:10 +01:00
#include "movement.h"
#include "position.h"
2018-02-14 18:07:10 +01:00
#include "AC.h"
void TaskMovement(void *pvParameters) {
(void) pvParameters;
TickType_t xLastWakeTime;
TickType_t xFrequency = 100 / portTICK_PERIOD_MS;
ulTaskNotifyTake(pdFALSE, portMAX_DELAY); // Mettre en veille jusqu'à l'arrivée de la prochaine instruction
2018-02-14 18:07:10 +01:00
xLastWakeTime = xTaskGetTickCount();
for (;;) {
// TODO Ici ira le code qui changera les valeurs des moteurs
vTaskDelayUntil(&xLastWakeTime, 1000 / portTICK_PERIOD_MS);
if (movement == C2AD_GOTO) {
actuel.x = destination.x;
actuel.y = destination.y;
actuel.o = destination.o;
}
2018-02-14 18:07:10 +01:00
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;
2018-02-14 18:07:10 +01:00
ulTaskNotifyTake(pdFALSE, portMAX_DELAY); // Mettre en veille jusqu'à l'arrivée de la prochaine instruction
2018-02-14 18:07:10 +01:00
xLastWakeTime = xTaskGetTickCount();
} else {
vTaskDelayUntil(&xLastWakeTime, xFrequency);
}
}
}
void onC2AD_STOP() {
movement = C2AD_STOP;
vTaskNotifyGiveFromISR(tMovement, NULL);
2018-02-14 18:07:10 +01:00
}
void onC2AD_GOTO() {
movement = C2AD_GOTO;
readAC(&destination, sizeof(struct C2AD_GOTOs));
vTaskNotifyGiveFromISR(tMovement, NULL);
2018-02-14 18:07:10 +01:00
}
void configureMovement() {
// TODO Configuration des pins
movement = C2AD_STOP;
registerRxHandlerAC(C2AD_STOP, onC2AD_STOP);
registerRxHandlerAC(C2AD_GOTO, onC2AD_GOTO);
2018-02-14 18:07:10 +01:00
xTaskCreate(TaskMovement, "Movement", 128, NULL, 2, &tMovement);;
}