• Non ci sono risultati.

Q Campo ‘output’ della S-function per il salvataggio dei dat

Di seguito è riportato il codice da inserire nel campo Outputs della S-function scritta per il salvataggio dei dati acquisiti tramite reta CAN:

int d;

constchar *pchar; char *nf = "_prova_sin"; int ts=5; FILE *fp; if(ts==-1) { if ((fp = fopen("salva_sin.txt","a+"))==NULL) {

printf("Cannot open file.\n"); exit(1); } fprintf(fp,"%f",*u0); fprintf(fp,"\t"); fprintf(fp,"%f",*u1); fprintf(fp,"\t"); fprintf(fp,"%f\n",*time); fclose(fp); } else { d=*time/ts; itoa(d, pchar, 10); strcat(pchar,nf); strcat(pchar,".txt"); if ((fp = fopen(pchar,"a+"))==NULL) {

printf("Cannot open file.\n"); exit(1); } fprintf(fp,"%f",*u0); fprintf(fp,"\t"); fprintf(fp,"%f",*u1); fprintf(fp,"\t"); fprintf(fp,"%f\n",*time); fclose(fp); }

In questo codice viene prima definito un oggetto di tipo file, in questo caso puntato da fp (FILE: FILE *fp). Si associa poi un flusso di dati, stream, ad un file facendo l’operazione di apertura, open: fopen: fp = fopen(“salva_sin.txt”,”a+”) dove l’a+ indica il modo di apertura, in questo caso: Append o create un file di testo per la scrittura o la lettura.

Quindi, grazie alla funzione fprintf si scrive nel file, per esempio fprintf (fp, “%f”,*u0) scrive nel file puntato da fp un numero di tipo floating point (%f) contenuto nella variabile puntata da u0.

\t è usato per inserire uno spazio e \n per andare a capo.

Successivamente viene descritto come è possibile scegliere la dimensione, in termini di tempo di acquisito, dei file che vengono creati.

Il numero intero ts rappresenta, in secondi, l’intervallo di tempo che viene acquisito in ogni singolo file, se ts è uguale a -1 viene creato un unico file come è possibile vedere dal primo if del codice.

Se ts è diverso da -1 viene eseguita la seconda parte del codice che è del tutto analoga alla prima per quanto riguarda il salvataggio dei dati, l’unica cosa che cambia è come viene assegnato il nome al file.

Come prima cosa viene assegnato ad una variabile di tipo intero il valore del rapporto tra il tempo della simulazione e ts, quindi, con la funzione itoa viene convertito l’intero contenuto di d in una stringa di tipo const char puntata da pchar, il terzo campo; in questo caso è 10 cioè il numero viene mantenuto decimale (con questa funzione è anche possibile fare, ad esempio, una conversione da decimale a esadecimale).

Infine viene composto il nome del file con i due strcat che concatenano le singole stringhe.

Parte IV

SUMMARY

R

Introduction

The deaths and handicaps resulting from road accidents are one of the main problems of public health in the world: according to the World Health Organisation (2001), more than one million people pass away in road accidents, which means around 2 per cent of the global mortality in the world. As far as Italy is concerned, 225.141 accidents took place in 2003, causing more than 6.000 deaths (ACI-Istat 2004).

One of the main causes of these accidents is the change of the psychophysical state of the driver, usually due to tiredness, which can result in a loss of attention and eventually in falling asleep; imprudence and dangerous driving are the other main causes of road accidents.

More specifically, according to recent researches at least a fifth of the accidents which occur on Italian roads results from the decrease of attention due to the driver drowsiness, while other studies attribute to such cause about the 40 per cent of the fatal accidents (Ministero della Salute 2004, Convegno di Genova 2004). Indeed, it is difficult to estimate the exact number of the accidents resulting from these factors. However, even if these data might change, depending on the country and also on the methods used to determine the accidents cause, all the researchers agree that this problem is one of the most worthy of consideration in order to increase road safety.

For all these reasons, several studies show an interest in the driver psychophysical conditions monitoring, which belong to the preventive safety field. Some of the systems already developed are based on physiological signals, such as alpha waves, or physics parameters such as eye blinking, head position or facial muscles relaxation, obtained, for instance, by video cameras (Eriksson et al. 1998, Ji, Yang 2002); this kind of approach, even if accurate, is likely not to be easily accepted by automotive manufacturers and customers, due to its intrinsic intrusive characteristic.

Moreover, other studies demonstrate how a sleepy driver can also be identified on the basis of characteristic driving signals, obtained from the vehicle system. In particular, after conducting an in-depth analysis of the state of art of these devices and techniques, the steering system monitoring, discussed behind, appeared the most interesting to the researcher.

This PhD research has been the first step of a project launched in this direction by the Department of Mechanical, Nuclear and Production Engineering of the University of Pisa. Aim of the research is to analyze if potentially hazardous situations, deriving to a non proper relationship between the vehicle dynamic conditions and the driver ability or psychophysical conditions (e.g. high

velocity and a non expert driver), can be recognised on the basis of signals acquired directly from the vehicle system; the basic idea was supported by the fact that, nowadays, it’s relatively simple to achieve many information about vehicle systems; indeed, modern vehicles are endowed with many transducers, whose signals are available on a communication network, which allow to accurately determine both vehicle motion and driver’s actions; moreover, by GPS systems it could be also possible to take into account additional environmental and infrastructure conditions.

However, in a first stage of the research, the development of a system able to detect possible dangerous situations only through driving actions and/or vehicle dynamics requires also some neurophysiological measurements to be validated. Indeed, the electroencephalogram is considered the most reliable system in this field. For this reason the collaboration with a team of neurologists of the University of Pisa has been agreed and about a hundredth of tests have been arranged. During these tests, data will be recorded for subsequent correlation analysis; in this way, it will be possible to analyse any relationship between the different quantities and to realize if the signals describing the vehicle motion conditions themselves can be used to recognise potentially dangerous situations; this approach is similar to that described from Ogawa and Shimotani (1997).

Given the difficulty and the riskiness in carrying out these tests on the road, the use of a real-time driving simulator is the more common solution (Chung et al. 2004, Allen et al. 1998).

The design and development of such simulator, both hardware and software components, was the main outcome of this research activity.

Documenti correlati