1
0
Fork 0
mirror of https://github.com/RobotechLille/cdf2018-principal synced 2024-12-04 14:06:05 +01:00

Attente fin de consigne

This commit is contained in:
Geoffrey Frogeye 2018-05-09 01:00:16 +02:00
parent de62a72457
commit 289898a763
2 changed files with 38 additions and 4 deletions

View file

@ -37,6 +37,8 @@
#define D_DIR_ECART_MAX 5.0 // mm #define D_DIR_ECART_MAX 5.0 // mm
#define O_DIR_ECART_MIN (6.0 / 360.0 * 2.0 * M_PI) // rad #define O_DIR_ECART_MIN (6.0 / 360.0 * 2.0 * M_PI) // rad
#define O_DIR_ECART_MAX (45.0 / 360.0 * 2.0 * M_PI) // rad #define O_DIR_ECART_MAX (45.0 / 360.0 * 2.0 * M_PI) // rad
#define D_CONS_THRESOLD 1.0 // mm
#define O_CONS_THRESOLD (6.0 / 360.0 * 2.0 * M_PI) // rad
#define O_GAIN 3.0 #define O_GAIN 3.0
#define P 3.0 #define P 3.0
#define I 0.0 #define I 0.0

View file

@ -1,7 +1,7 @@
#include <math.h> #include <math.h>
#include <pthread.h> #include <pthread.h>
#include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
@ -15,6 +15,9 @@ pthread_mutex_t movCons;
pthread_mutex_t movEnableMutex; pthread_mutex_t movEnableMutex;
pthread_cond_t movEnableCond; pthread_cond_t movEnableCond;
bool movEnableBool; bool movEnableBool;
pthread_mutex_t movDoneMutex;
pthread_cond_t movDoneCond;
bool movDoneBool;
float xDiff; float xDiff;
float yDiff; float yDiff;
@ -47,6 +50,9 @@ void configureMovement()
pthread_mutex_init(&movEnableMutex, NULL); pthread_mutex_init(&movEnableMutex, NULL);
pthread_cond_init(&movEnableCond, NULL); pthread_cond_init(&movEnableCond, NULL);
movEnableBool = false; movEnableBool = false;
pthread_mutex_init(&movDoneMutex, NULL);
pthread_cond_init(&movDoneCond, NULL);
movDoneBool = false;
pthread_create(&tMovement, NULL, TaskMovement, NULL); pthread_create(&tMovement, NULL, TaskMovement, NULL);
@ -78,6 +84,25 @@ void setDestination(struct position* pos)
pthread_mutex_unlock(&movCons); pthread_mutex_unlock(&movCons);
} }
void waitDestination()
{
pthread_mutex_lock(&movDoneMutex);
while (!movDoneBool) {
pthread_cond_wait(&movDoneCond, &movDoneMutex);
}
pthread_mutex_unlock(&movDoneMutex);
}
void sendTo(float x, float y, float o)
{
enableConsigne();
struct position pos = {x, y, o};
setDestination(&pos);
waitDestination();
brake();
disableConsigne();
}
float angleGap(float target, float actual) float angleGap(float target, float actual)
{ {
return fmod(target - actual + M_PI, 2 * M_PI) - M_PI; return fmod(target - actual + M_PI, 2 * M_PI) - M_PI;
@ -153,6 +178,13 @@ void* TaskMovement(void* pData)
} }
dErr = dRetenu ? 0 : dDirEcart; dErr = dRetenu ? 0 : dDirEcart;
// Calcul si on est arrivé
pthread_mutex_lock(&movDoneMutex);
clock_gettime(CLOCK_REALTIME, &pidNow);
movDoneBool = !dRetenu && !oRetenu && dDirEcart < D_CONS_THRESOLD && oEcart < O_CONS_THRESOLD;
pthread_cond_signal(&movDoneCond);
pthread_mutex_unlock(&movDoneMutex);
// Ordre → Volt // Ordre → Volt
// Nombre de rotation nécessaire sur les deux roues dans le même sens pour arriver à la distance voulue // Nombre de rotation nécessaire sur les deux roues dans le même sens pour arriver à la distance voulue
float dErrRev = dErr / WHEEL_PERIMETER; float dErrRev = dErr / WHEEL_PERIMETER;