Guillermo Stedile / NAVDATA

Dependents:   SNOCC_V1 SNOCC_V2

Committer:
gstedile
Date:
Mon Apr 17 12:35:29 2017 +0000
Revision:
8:e105a233d4b1
Parent:
7:0522eded4738
Child:
9:b4232b5aa4ed
Se agregavalidacion de datos recolectados y promediado  antes del almacenamiento.; Tambien grafico interpolado con rectas.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gstedile 0:9370c06bf7f3 1 /* NAVIGATION DATA Library
gstedile 0:9370c06bf7f3 2 * Copyright (c) 2008-2010, sford
gstedile 0:9370c06bf7f3 3 *
gstedile 0:9370c06bf7f3 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
gstedile 0:9370c06bf7f3 5 * of this software and associated documentation files (the "Software"), to deal
gstedile 0:9370c06bf7f3 6 * in the Software without restriction, including without limitation the rights
gstedile 0:9370c06bf7f3 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
gstedile 0:9370c06bf7f3 8 * copies of the Software, and to permit persons to whom the Software is
gstedile 0:9370c06bf7f3 9 * furnished to do so, subject to the following conditions:
gstedile 0:9370c06bf7f3 10 *
gstedile 0:9370c06bf7f3 11 * The above copyright notice and this permission notice shall be included in
gstedile 0:9370c06bf7f3 12 * all copies or substantial portions of the Software.
gstedile 0:9370c06bf7f3 13 *
gstedile 0:9370c06bf7f3 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
gstedile 0:9370c06bf7f3 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
gstedile 0:9370c06bf7f3 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
gstedile 0:9370c06bf7f3 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
gstedile 0:9370c06bf7f3 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
gstedile 0:9370c06bf7f3 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
gstedile 0:9370c06bf7f3 20 * THE SOFTWARE.
gstedile 0:9370c06bf7f3 21 */
gstedile 0:9370c06bf7f3 22
gstedile 0:9370c06bf7f3 23 #include "NAVDATA.h"
gstedile 4:400b92fb528c 24
gstedile 0:9370c06bf7f3 25
gstedile 0:9370c06bf7f3 26 /*############################################################################
gstedile 1:48e2f1194609 27 ##############################################################################*/
gstedile 0:9370c06bf7f3 28
gstedile 6:fc2eb58bac36 29 /* CONSTRUCTOR1: Si no se pasan argumentos se toman los seteados en la declaracion; Latitud/Longitud expresadas en Millas Náuticas y Cte. del sensor en pulsos por Litro*/
gstedile 0:9370c06bf7f3 30
gstedile 4:400b92fb528c 31 NAVDATA::NAVDATA(float Klongitud=49.38797982997941, float Klatitud=59.99999981628485, float Ksensor=2500, int ZoneHour=-3) : Klong(Klongitud), Klat(Klatitud), Ksen(Ksensor), ZH(ZoneHour) {
gstedile 4:400b92fb528c 32 this->paddata();
gstedile 4:400b92fb528c 33 }
gstedile 6:fc2eb58bac36 34 /* CONSTRUCTOR2:Sin argumentos. Necesario para declarar vectores de objetos NAVDATA*/
gstedile 4:400b92fb528c 35 NAVDATA::NAVDATA(){
gstedile 4:400b92fb528c 36 Klong= 49.38797982997941;
gstedile 4:400b92fb528c 37 Klat=59.99999981628485;
gstedile 4:400b92fb528c 38 Ksen=2500;
gstedile 4:400b92fb528c 39 ZH=-3;
gstedile 4:400b92fb528c 40
gstedile 4:400b92fb528c 41 this->paddata();
gstedile 4:400b92fb528c 42 }
gstedile 4:400b92fb528c 43
gstedile 4:400b92fb528c 44
gstedile 4:400b92fb528c 45
gstedile 2:86e9ac5dcacc 46 int NAVDATA::rotate_data(float x, float y, float t, float c){ // Longitud, Latitud, Timestamp, Consumption;
gstedile 3:de86e5eb7a8a 47 if ( t > LAST_NAV_DATA[time_f] ) { // Tiempo válido?
gstedile 3:de86e5eb7a8a 48 this->LAST_NAV_DATA[longitude_i]=this->LAST_NAV_DATA[longitude_f];
gstedile 3:de86e5eb7a8a 49 this->LAST_NAV_DATA[longitude_f]=x;
gstedile 3:de86e5eb7a8a 50 this->LAST_NAV_DATA[latitude_i]=this->LAST_NAV_DATA[latitude_f];
gstedile 3:de86e5eb7a8a 51 this->LAST_NAV_DATA[latitude_f]=y;
gstedile 5:ae5dfda6b0ab 52 this->LAST_NAV_DATA[time_i]=this->LAST_NAV_DATA[time_f]; // EN HORAS
gstedile 7:0522eded4738 53 this->LAST_NAV_DATA[time_f]=time_NMEA2hours(t); // EN HORAS
gstedile 3:de86e5eb7a8a 54 this->LAST_NAV_DATA[distance_p]= sqrt(pow(Klong*(this->LAST_NAV_DATA[longitude_f]-this->LAST_NAV_DATA[longitude_i]),2) + pow(Klat*(this->LAST_NAV_DATA[latitude_f]-this->LAST_NAV_DATA[latitude_i]),2)) ; // Distancia recorrida durante este período.
gstedile 3:de86e5eb7a8a 55 this->LAST_NAV_DATA[speed_p]=this->LAST_NAV_DATA[distance_p]/(this->LAST_NAV_DATA[time_f]-this->LAST_NAV_DATA[time_i]);
gstedile 5:ae5dfda6b0ab 56 this->LAST_NAV_DATA[consumption_i]=this->LAST_NAV_DATA[consumption_f];
gstedile 5:ae5dfda6b0ab 57 this->LAST_NAV_DATA[consumption_f]=c/Ksen;
gstedile 5:ae5dfda6b0ab 58 this->LAST_NAV_DATA[consumption_p]=this->LAST_NAV_DATA[consumption_f]-this->LAST_NAV_DATA[consumption_i]; // Consumo en litros del período.
gstedile 8:e105a233d4b1 59 this->LAST_NAV_DATA[cons_interpolated]=0; // Valor interpolado? 0-> real ; 1-> interpolated; -1-> initial padding
gstedile 3:de86e5eb7a8a 60
gstedile 7:0522eded4738 61 if (this->LAST_NAV_DATA[distance_p] > 0) this->LAST_NAV_DATA[cons_mile_p]=this->LAST_NAV_DATA[consumption_p]/this->LAST_NAV_DATA[distance_p]; // Consumo en litros por milla nautica.
gstedile 5:ae5dfda6b0ab 62 else this->LAST_NAV_DATA[cons_mile_p]= -1; // Variable no mensurable (-1)
gstedile 3:de86e5eb7a8a 63
gstedile 5:ae5dfda6b0ab 64 this->LAST_NAV_DATA[cons_hour_p]=this->LAST_NAV_DATA[consumption_p]/(this->LAST_NAV_DATA[time_f]-this->LAST_NAV_DATA[time_i]); // Consumo en litros por hora.
gstedile 2:86e9ac5dcacc 65 return 1;
gstedile 2:86e9ac5dcacc 66 }
gstedile 2:86e9ac5dcacc 67 else
gstedile 3:de86e5eb7a8a 68 return 0; // Período no válido. Tiempo <=0!
gstedile 2:86e9ac5dcacc 69 }
gstedile 3:de86e5eb7a8a 70
gstedile 5:ae5dfda6b0ab 71 float NAVDATA::time_NMEA2hours(float timetickNMEA){
gstedile 3:de86e5eb7a8a 72 float seconds, minutes, hours;
gstedile 5:ae5dfda6b0ab 73 hours= int(timetickNMEA/10000); //Formato NMEA: hhmmss,sss; => int(hh,mmssss)=hh
gstedile 6:fc2eb58bac36 74 seconds= (timetickNMEA/100 - int(timetickNMEA/100))*100; // => (hhmmss,sss/100 - int(hhmmss,sss/100))*100 = ss,sss
gstedile 6:fc2eb58bac36 75 minutes= int(timetickNMEA/100 - hours*100); // => int(hh,mmsssss - hh*100)= mm
gstedile 7:0522eded4738 76 if ((hours+ZH)>=0) return (hours + ZH + minutes/60 + seconds/3600); // => Hora local,expresado en horas, formato decimal
gstedile 7:0522eded4738 77 else return (hours + 24 + ZH + minutes/60 + seconds/3600); // => Hora local,expresado en horas, formato decimal
gstedile 3:de86e5eb7a8a 78 }
gstedile 3:de86e5eb7a8a 79
gstedile 4:400b92fb528c 80 void NAVDATA::paddata(){
gstedile 5:ae5dfda6b0ab 81 this->LAST_NAV_DATA[longitude_f]=-58.5797; // Longitud y Latitud iniciales y finales correspondiente a Tigre.
gstedile 5:ae5dfda6b0ab 82 this->LAST_NAV_DATA[longitude_i]=-58.5797;
gstedile 5:ae5dfda6b0ab 83 this->LAST_NAV_DATA[latitude_f]=-34.4251;
gstedile 5:ae5dfda6b0ab 84 this->LAST_NAV_DATA[latitude_i]=-34.4251;
gstedile 6:fc2eb58bac36 85 this->LAST_NAV_DATA[time_f]=-1; // El dato (timestamp al final del período en cuestion, en horas) se obtendrá luego proveniente del GPS.
gstedile 4:400b92fb528c 86 this->LAST_NAV_DATA[time_i]=0; // Timestamp al inicio del período en horas.
gstedile 4:400b92fb528c 87 this->LAST_NAV_DATA[distance_p]=0; // Distancia recorrida durante este período en millas nauticas.
gstedile 8:e105a233d4b1 88 this->LAST_NAV_DATA[speed_p]=-1; // Velocidad media del período en nudos.
gstedile 5:ae5dfda6b0ab 89 this->LAST_NAV_DATA[consumption_i]=0; // Consumo en litros al comienzo del período.
gstedile 5:ae5dfda6b0ab 90 this->LAST_NAV_DATA[consumption_f]=0; // Consumo en litros al final del período.
gstedile 4:400b92fb528c 91 this->LAST_NAV_DATA[consumption_p]=0; // Consumo en litros del período.
gstedile 4:400b92fb528c 92 this->LAST_NAV_DATA[cons_mile_p]=0; // Consumo en litros por milla nautica.
gstedile 4:400b92fb528c 93 this->LAST_NAV_DATA[cons_hour_p]=0; // Consumo en litros por hora.
gstedile 8:e105a233d4b1 94 this->LAST_NAV_DATA[cons_interpolated]=-1; // Consumo interpolado?: -1-> initial padding
gstedile 4:400b92fb528c 95 }
gstedile 4:400b92fb528c 96
gstedile 4:400b92fb528c 97
gstedile 3:de86e5eb7a8a 98
gstedile 3:de86e5eb7a8a 99
gstedile 4:400b92fb528c 100