1
0
Fork 0
mirror of https://github.com/RobotechLille/cdf2018-principal synced 2024-12-21 13:10:37 +01:00

Essai de calibrage en position

This commit is contained in:
Geoffrey Frogeye 2018-05-16 07:58:55 +02:00
parent d0d3e7f244
commit 5f6e9b3ee5
3 changed files with 105 additions and 0 deletions

42
chef/src/calibrage.c Normal file
View file

@ -0,0 +1,42 @@
#include <stdbool.h>
#include <stdio.h>
#include <unistd.h>
#include "calibrage.h"
#include "movement.h"
#include "dimensions.h"
#include "securite.h"
#include "motor.h"
#include "common.h"
void calibrer(bool orange)
{
struct position pos = {0, 0, 0};
setPosition(&pos);
return;
// Calibrage contre mur court
/* pos.o = orange ? M_PI_2 : -M_PI_2; */
setDestination(&pos);
waitDestination();
disableAsservissement();
float frontL, frontR, backL, backR;
struct movAvg diffL, diffR;
initMovAvg(&diffL, CALIBRAGE_MOVAVG_SIZE);
initMovAvg(&diffR, CALIBRAGE_MOVAVG_SIZE);
for (int i = 0; i < CALIBRAGE_TEMPS_ACQUISITION; i += SENSOR_SAMPLING_INTERVAL) {
getAllDistance(&frontL, &frontR, &backL, &backR);
addMovAvg(&diffL, frontL - CALIBRAGE_DISTANCE_Y);
addMovAvg(&diffR, frontR - CALIBRAGE_DISTANCE_Y);
setMoteurTension(diffL.current * D_KP, diffR.current * D_KP);
usleep(SENSOR_SAMPLING_INTERVAL * 1000);
}
// Les moteurs n'auront peut-être pas atteint le point voulu exactement,
// on enregistre alors la différence
float diff = (diffL.current + diffR.current) / 2;
pos.y = diff;
}

16
chef/src/calibrage.h Normal file
View file

@ -0,0 +1,16 @@
#ifndef __CALIBRAGE_H_
#define __CALIBRAGE_H_
#include <stdbool.h>
// Constantes
#define CALIBRAGE_TEMPS_ACQUISITION 30000
#define CALIBRAGE_DISTANCE_X 300
#define CALIBRAGE_DISTANCE_Y 300
#define CALIBRAGE_MOVAVG_SIZE 4
// Public
void calibrer(bool orange);
#endif

47
chef/src/testCalibrage.c Normal file
View file

@ -0,0 +1,47 @@
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h> // random seed
#include <unistd.h> // sleep
#include <wiringPi.h>
#include "actionneurs.h"
#include "calibrage.h"
#include "debug.h"
#include "i2c.h"
#include "motor.h"
#include "movement.h"
#include "position.h"
pthread_mutex_t sRunning;
void endRunning(int signal)
{
(void)signal;
pthread_mutex_unlock(&sRunning);
}
int main()
{
if (wiringPiSetup() < 0) {
fprintf(stderr, "Impossible d'initialiser WiringPi\n");
exit(EXIT_FAILURE);
}
initI2C();
srand(time(NULL));
configureDebug();
configurePosition();
configureMovement();
debugSetActive(true);
startDebug();
calibrer(false);
deconfigureMovement();
deconfigurePosition();
deconfigureDebug();
return EXIT_SUCCESS;
}