1
0
Fork 0
mirror of https://github.com/RobotechLille/cdf2018-principal synced 2024-11-24 00:56:04 +01:00

Sécurité

This commit is contained in:
Geoffrey Frogeye 2018-05-09 04:09:38 +02:00
parent 171e51e288
commit 041dae8e41
4 changed files with 107 additions and 1 deletions

View file

@ -11,7 +11,7 @@ CFLAGS_CUSTOM += -g
## Générateurs de drapeaux pour les bibliothèques ## Générateurs de drapeaux pour les bibliothèques
PKG_CONFIG=pkg-config PKG_CONFIG=pkg-config
## Nom des objets communs ## Nom des objets communs
OBJS=actionneurs buttons CA CF debug diagnostics i2c imu ihm lcd motor movement parcours points position OBJS=actionneurs buttons CA CF debug diagnostics i2c imu ihm lcd motor movement parcours points position securite
OBJS_O=$(addprefix obj/,$(addsuffix .o,$(OBJS))) OBJS_O=$(addprefix obj/,$(addsuffix .o,$(OBJS)))
# VARIABLES AUTOMATIQUES # VARIABLES AUTOMATIQUES

66
chef/src/securite.c Normal file
View file

@ -0,0 +1,66 @@
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "debug.h"
#include "securite.h"
// Globales
pthread_t tSecurite;
pthread_mutex_t secPolling;
pthread_mutex_t secData;
struct F2CI_CAPTs secRaw;
float secFront, secBack;
void onF2CI_CAPT()
{
readCF(&secRaw, sizeof(struct F2CI_CAPTs));
pthread_mutex_unlock(&secPolling);
}
void* TaskSecurite(void* pData)
{
(void)pData;
for (;;) {
pthread_mutex_lock(&secPolling);
sendCF(F2CI_CAPT, NULL, 0);
// Waiting for reception
pthread_mutex_lock(&secPolling);
pthread_mutex_unlock(&secPolling);
pthread_mutex_lock(&secData);
secFront = (float)secRaw.front * SOUND_MM_P_MS;
secBack = (float)secRaw.back * SOUND_MM_P_MS;
pthread_mutex_unlock(&secData);
usleep(SENSOR_SAMPLING_INTERVAL * 1000);
}
return NULL;
}
void getDistance(float* front, float* back)
{
pthread_mutex_lock(&secData);
*front = secFront;
*back = secBack;
pthread_mutex_unlock(&secData);
}
void configureSecurite()
{
pthread_mutex_init(&secPolling, NULL);
pthread_mutex_init(&secData, NULL);
registerRxHandlerCF(F2CI_CODER, onF2CI_CAPT);
registerDebugVar("secFront", ld, &secFront);
registerDebugVar("secBack", ld, &secBack);
pthread_create(&tSecurite, NULL, TaskSecurite, NULL);
}
void deconfigureSecurite()
{
pthread_cancel(tSecurite);
}

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

@ -0,0 +1,16 @@
#ifndef __SECURITE_H_
#define __SECURITE_H_
#include "CF.h"
#include <pthread.h>
#define SOUND_MM_P_MS 0.3312
#define SENSOR_SAMPLING_INTERVAL 60
// Fonctions
void configureSecurite();
void deconfigureSecurite();
void getDistance(float* avant, float* arriere);
#endif

24
chef/src/testSecu.c Normal file
View file

@ -0,0 +1,24 @@
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include "CF.h"
#include "securite.h"
int main(int argc, char* argv[])
{
(void)argc;
(void)argv;
configureCF();
configureSecurite();
float f, b;
for (;;) {
getDistance(&f, &b);
printf("Av: %6f Ar: %6f\n", f, b);
sleep(1);
}
}