Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
NAVDATA.cpp@4:400b92fb528c, 2017-04-04 (annotated)
- Committer:
- gstedile
- Date:
- Tue Apr 04 02:24:45 2017 +0000
- Revision:
- 4:400b92fb528c
- Parent:
- 3:de86e5eb7a8a
- Child:
- 5:ae5dfda6b0ab
Sin terminar pero sin errores de compilaci?n.
Who changed what in which revision?
| User | Revision | Line number | New 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 | 2:86e9ac5dcacc | 29 | /* CONSTRUCTOR: 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 | 4:400b92fb528c | 34 | NAVDATA::NAVDATA(){ |
| gstedile | 4:400b92fb528c | 35 | Klong= 49.38797982997941; |
| gstedile | 4:400b92fb528c | 36 | Klat=59.99999981628485; |
| gstedile | 4:400b92fb528c | 37 | Ksen=2500; |
| gstedile | 4:400b92fb528c | 38 | ZH=-3; |
| gstedile | 4:400b92fb528c | 39 | |
| gstedile | 4:400b92fb528c | 40 | this->paddata(); |
| gstedile | 4:400b92fb528c | 41 | } |
| gstedile | 4:400b92fb528c | 42 | |
| gstedile | 4:400b92fb528c | 43 | |
| gstedile | 4:400b92fb528c | 44 | |
| gstedile | 2:86e9ac5dcacc | 45 | int NAVDATA::rotate_data(float x, float y, float t, float c){ // Longitud, Latitud, Timestamp, Consumption; |
| gstedile | 3:de86e5eb7a8a | 46 | if ( t > LAST_NAV_DATA[time_f] ) { // Tiempo válido? |
| gstedile | 3:de86e5eb7a8a | 47 | this->LAST_NAV_DATA[longitude_i]=this->LAST_NAV_DATA[longitude_f]; |
| gstedile | 3:de86e5eb7a8a | 48 | this->LAST_NAV_DATA[longitude_f]=x; |
| gstedile | 3:de86e5eb7a8a | 49 | this->LAST_NAV_DATA[latitude_i]=this->LAST_NAV_DATA[latitude_f]; |
| gstedile | 3:de86e5eb7a8a | 50 | this->LAST_NAV_DATA[latitude_f]=y; |
| gstedile | 3:de86e5eb7a8a | 51 | this->LAST_NAV_DATA[time_i]=this->LAST_NAV_DATA[time_f] + ZH; // EN HORAS |
| gstedile | 3:de86e5eb7a8a | 52 | this->LAST_NAV_DATA[time_f]=time_NMEA2hours(t); // EN HORAS |
| gstedile | 3:de86e5eb7a8a | 53 | 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 | 54 | 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 | 3:de86e5eb7a8a | 55 | this->LAST_NAV_DATA[consumption_p]=c; // Consumo en litros del período. |
| gstedile | 3:de86e5eb7a8a | 56 | |
| gstedile | 3:de86e5eb7a8a | 57 | if (this->LAST_NAV_DATA[distance_p] != 0) this->LAST_NAV_DATA[cons_mile_p]=c/this->LAST_NAV_DATA[distance_p]; // Consumo en litros por milla nautica. |
| gstedile | 3:de86e5eb7a8a | 58 | else this->LAST_NAV_DATA[cons_mile_p]= -1; // Variable no mensurable (-1) |
| gstedile | 3:de86e5eb7a8a | 59 | |
| gstedile | 3:de86e5eb7a8a | 60 | this->LAST_NAV_DATA[cons_hour_p]=c/(this->LAST_NAV_DATA[time_f]-this->LAST_NAV_DATA[time_i]); // Consumo en litros por hora. |
| gstedile | 2:86e9ac5dcacc | 61 | return 1; |
| gstedile | 2:86e9ac5dcacc | 62 | } |
| gstedile | 2:86e9ac5dcacc | 63 | else |
| gstedile | 3:de86e5eb7a8a | 64 | return 0; // Período no válido. Tiempo <=0! |
| gstedile | 2:86e9ac5dcacc | 65 | } |
| gstedile | 3:de86e5eb7a8a | 66 | |
| gstedile | 3:de86e5eb7a8a | 67 | float NAVDATA::time_NMEA2hours(float timestickNMEA){ |
| gstedile | 3:de86e5eb7a8a | 68 | float seconds, minutes, hours; |
| gstedile | 3:de86e5eb7a8a | 69 | hours= int(timestickNMEA/10000); //Formato NMEA: hhmmss,sss; => int(hh,mmssss)=hh |
| gstedile | 3:de86e5eb7a8a | 70 | seconds= (timestickNMEA/100 - int(timestickNMEA/100))*100; // => (hhmmss,sss/100 - int(hhmmss,sss/100))*100 = ss,sss |
| gstedile | 3:de86e5eb7a8a | 71 | minutes= (int(timestickNMEA/10000 - hours))*100; // => int((hh,mmsssss - hh)*100)= mm |
| gstedile | 3:de86e5eb7a8a | 72 | return (hours + minutes/60 + seconds/3600); // => expresado en horas, formato decimal |
| gstedile | 3:de86e5eb7a8a | 73 | } |
| gstedile | 3:de86e5eb7a8a | 74 | |
| gstedile | 4:400b92fb528c | 75 | void NAVDATA::paddata(){ |
| gstedile | 4:400b92fb528c | 76 | this->LAST_NAV_DATA[longitude_f]=-58,5797; // Longitud y Latitud iniciales y finales correspondiente a Tigre. |
| gstedile | 4:400b92fb528c | 77 | this->LAST_NAV_DATA[longitude_i]=-58,5797; |
| gstedile | 4:400b92fb528c | 78 | this->LAST_NAV_DATA[latitude_f]=-34,4251; |
| gstedile | 4:400b92fb528c | 79 | this->LAST_NAV_DATA[latitude_i]=-34,4251; |
| gstedile | 4:400b92fb528c | 80 | this->LAST_NAV_DATA[time_f]=0; // El dato (timestamp al final del período en cuestion, en horas) se obtendrá luego proveniente del GPS. |
| gstedile | 4:400b92fb528c | 81 | this->LAST_NAV_DATA[time_i]=0; // Timestamp al inicio del período en horas. |
| gstedile | 4:400b92fb528c | 82 | this->LAST_NAV_DATA[distance_p]=0; // Distancia recorrida durante este período en millas nauticas. |
| gstedile | 4:400b92fb528c | 83 | this->LAST_NAV_DATA[speed_p]=0; // Velocidad media del período en nudos. |
| gstedile | 4:400b92fb528c | 84 | this->LAST_NAV_DATA[consumption_p]=0; // Consumo en litros del período. |
| gstedile | 4:400b92fb528c | 85 | this->LAST_NAV_DATA[cons_mile_p]=0; // Consumo en litros por milla nautica. |
| gstedile | 4:400b92fb528c | 86 | this->LAST_NAV_DATA[cons_hour_p]=0; // Consumo en litros por hora. |
| gstedile | 4:400b92fb528c | 87 | } |
| gstedile | 4:400b92fb528c | 88 | |
| gstedile | 4:400b92fb528c | 89 | |
| gstedile | 3:de86e5eb7a8a | 90 | /// AGREGAR ACA int NAVDATA::rotate_data(float x, float y, float t, float c) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%<<<< |
| gstedile | 3:de86e5eb7a8a | 91 | |
| gstedile | 3:de86e5eb7a8a | 92 | |
| gstedile | 4:400b92fb528c | 93 |