1
0
Fork 0
mirror of https://github.com/RobotechLille/cdf2018-principal synced 2024-12-22 05:30:37 +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
#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

View file

@ -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);
}

View file

@ -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();

View file

@ -23,6 +23,7 @@ void TaskBlink(void *pvParameters) {
}
}
int main(void) {
configureAC(); // 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(", 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);
}

View file

@ -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;

View file

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

View file

@ -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;