1
0
Fork 0
mirror of https://github.com/RobotechLille/cdf2018-principal synced 2024-11-23 16:46:04 +01:00
cdf2018-principal/arduino/position.c

52 lines
1.1 KiB
C
Raw Normal View History

2018-02-14 18:07:10 +01:00
#include "position.h"
#include "AC.h"
2018-03-26 10:06:32 +02:00
#include "AF.h"
#include "dimensions.h"
2018-02-14 18:07:10 +01:00
2018-03-26 10:06:32 +02:00
void TaskPosition(void* pvParameters)
{
(void)pvParameters;
const TickType_t xDelay = 500 / portTICK_PERIOD_MS;
2018-02-14 18:07:10 +01:00
for (;;) {
2018-03-26 10:06:32 +02:00
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);
2018-02-14 18:07:10 +01:00
}
}
2018-03-26 10:06:32 +02:00
void onF2AI_CODER()
{
readAF(&deltaCoder, sizeof(struct F2AI_CODERs));
vTaskNotifyGiveFromISR(tPosition, NULL);
}
2018-02-14 18:07:10 +01:00
2018-03-26 10:06:32 +02:00
void configurePosition()
{
actuel.x = 0;
actuel.y = 0;
2018-03-26 10:06:32 +02:00
actuel.o = 0;
2018-03-26 10:06:32 +02:00
registerRxHandlerAF(F2AI_CODER, onF2AI_CODER);
2018-02-14 18:07:10 +01:00
2018-03-26 10:06:32 +02:00
xTaskCreate(TaskPosition, "Position", 128, NULL, 2, &tPosition);
;
}