1
0
Fork 0
mirror of https://github.com/RobotechLille/cdf2018-principal synced 2024-11-16 13:26:03 +01:00
cdf2018-principal/arduino/movement.c

91 lines
2 KiB
C
Raw Normal View History

2018-02-14 18:07:10 +01:00
#include "movement.h"
#include "AC.h"
2018-02-16 22:13:24 +01:00
#include "position.h"
2018-02-14 18:07:10 +01:00
2018-02-16 22:13:24 +01:00
void TaskMovement(void* pvParameters)
{
(void)pvParameters;
2018-02-14 18:07:10 +01:00
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-16 22:13:24 +01:00
if (true) { // Arrivé à destination
2018-02-14 18:07:10 +01:00
sendAC(movement, NULL, 0); // On rapporte au chef qu'on a terminé l'action en cours
2018-02-16 22:13:24 +01:00
brake();
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);
}
}
}
2018-02-16 22:13:24 +01:00
void brake()
{
movement = C2AD_BRAKE;
// TODO Mettre les IN à ce qu'il faut
}
void onC2AD_BRAKE()
{
brake();
vTaskNotifyGiveFromISR(tMovement, NULL);
2018-02-14 18:07:10 +01:00
}
2018-02-16 22:13:24 +01:00
void freewheel()
{
movement = C2AD_FREE;
// TODO Mettre les IN à ce qu'il faut
}
void onC2AD_FREE()
{
freewheel();
}
void onC2AD_GOTO()
{
2018-02-14 18:07:10 +01:00
movement = C2AD_GOTO;
readAC(&destination, sizeof(struct C2AD_GOTOs));
vTaskNotifyGiveFromISR(tMovement, NULL);
2018-02-14 18:07:10 +01:00
}
2018-02-16 22:13:24 +01:00
void stop()
{
brake();
// TODO Actionneurs
}
void onC2AD_STOP()
{
stop();
sendAC(C2AD_STOP, NULL, 0);
}
2018-02-14 18:07:10 +01:00
2018-02-16 22:13:24 +01:00
void configureMovement()
{
2018-02-14 18:07:10 +01:00
// TODO Configuration des pins
2018-02-16 22:13:24 +01:00
freewheel();
2018-02-14 18:07:10 +01:00
2018-02-16 22:13:24 +01:00
registerRxHandlerAC(C2AD_BRAKE, onC2AD_BRAKE);
registerRxHandlerAC(C2AD_STOP, onC2AD_STOP);
2018-02-16 22:13:24 +01:00
registerRxHandlerAC(C2AD_FREE, onC2AD_FREE);
registerRxHandlerAC(C2AD_GOTO, onC2AD_GOTO);
2018-02-14 18:07:10 +01:00
2018-02-16 22:13:24 +01:00
xTaskCreate(TaskMovement, "Movement", 128, NULL, 2, &tMovement);
2018-02-14 18:07:10 +01:00
}