Guillermo Stedile / VCODATA

Dependents:   SNOCC_V1 SNOCC_V2

Committer:
gstedile
Date:
Thu Apr 13 21:00:21 2017 +0000
Revision:
5:cec68064dda8
Parent:
4:af09ad305303
Child:
6:d575bd17b617
OBTIENE VCO

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gstedile 0:9faff39f9aa2 1 /* VCO DATA Library
gstedile 0:9faff39f9aa2 2 * Copyright (c) 2008-2010, sford
gstedile 0:9faff39f9aa2 3 *
gstedile 0:9faff39f9aa2 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
gstedile 0:9faff39f9aa2 5 * of this software and associated documentation files (the "Software"), to deal
gstedile 0:9faff39f9aa2 6 * in the Software without restriction, including without limitation the rights
gstedile 0:9faff39f9aa2 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
gstedile 0:9faff39f9aa2 8 * copies of the Software, and to permit persons to whom the Software is
gstedile 0:9faff39f9aa2 9 * furnished to do so, subject to the following conditions:
gstedile 0:9faff39f9aa2 10 *
gstedile 0:9faff39f9aa2 11 * The above copyright notice and this permission notice shall be included in
gstedile 0:9faff39f9aa2 12 * all copies or substantial portions of the Software.
gstedile 0:9faff39f9aa2 13 *
gstedile 0:9faff39f9aa2 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
gstedile 0:9faff39f9aa2 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
gstedile 0:9faff39f9aa2 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
gstedile 0:9faff39f9aa2 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
gstedile 0:9faff39f9aa2 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
gstedile 0:9faff39f9aa2 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
gstedile 0:9faff39f9aa2 20 * THE SOFTWARE.
gstedile 0:9faff39f9aa2 21 */
gstedile 1:9a2a94ffbffb 22
gstedile 0:9faff39f9aa2 23 #include "VCODATA.h"
gstedile 5:cec68064dda8 24
gstedile 1:9a2a94ffbffb 25 //#include <math.h>
gstedile 1:9a2a94ffbffb 26
gstedile 0:9faff39f9aa2 27
gstedile 0:9faff39f9aa2 28 /*############################################################################
gstedile 0:9faff39f9aa2 29 ##############################################################################*/
gstedile 0:9faff39f9aa2 30
gstedile 0:9faff39f9aa2 31
gstedile 0:9faff39f9aa2 32
gstedile 0:9faff39f9aa2 33
gstedile 0:9faff39f9aa2 34 /* CONSTRUCTOR: */
gstedile 0:9faff39f9aa2 35
gstedile 1:9a2a94ffbffb 36 VCODATA::VCODATA(NAVDATA InitData){
gstedile 2:c386c1f00d02 37 InitData.paddata(); // Inicializamos el vector LAST_NAV_DATA con valores default. Las constantes Klong, Klat; Ksen y ZH no se modifican.
gstedile 2:c386c1f00d02 38 NAV_DATA = new NAVDATA[100]; // Array de 100 elementos tipo NAVDATA
gstedile 2:c386c1f00d02 39 for (int i=0;i<100;i+=1)
gstedile 2:c386c1f00d02 40 this->NAV_DATA[i]= InitData; // Inicializa NAV_DATA[]. Carga el array repitiendo Initdata en todas las posiciones.
gstedile 0:9faff39f9aa2 41 }
gstedile 0:9faff39f9aa2 42
gstedile 3:75e22a2e2109 43
gstedile 3:75e22a2e2109 44 void VCODATA::store_data (NAVDATA LastData){
gstedile 3:75e22a2e2109 45 this->NAV_DATA[int(LastData.LAST_NAV_DATA[speed_p])] = LastData; // Carga el objeto en NAV_DATA tomando como índice a la parte entera de la velocidad.
gstedile 3:75e22a2e2109 46
gstedile 4:af09ad305303 47 }
gstedile 4:af09ad305303 48
gstedile 5:cec68064dda8 49 /* Obtiene la Velocidad Crucero Optima (VCO)*/
gstedile 4:af09ad305303 50
gstedile 5:cec68064dda8 51 int VCODATA::get_VCO(){
gstedile 5:cec68064dda8 52 int GET_Min=0;
gstedile 5:cec68064dda8 53 int GET_MAX=0;
gstedile 5:cec68064dda8 54 int Ratio_Min=6; // Entorno de evaluación de Máximos / Mínimos.
gstedile 5:cec68064dda8 55 int n_events_eps=0; // Cantidad de valores de v menores al Minimo (o mayores al Máximo) dentro del entorno Ratio_Min para evaluar validez de Minimo (o Maximo segun sea el caso).
gstedile 5:cec68064dda8 56 int n_events_critical=3; //Cantidad de ocurrencias para considerar la invalidéz del minimo hallado;
gstedile 5:cec68064dda8 57 float ConsMin=100;
gstedile 5:cec68064dda8 58 float ConsMAX=0;
gstedile 5:cec68064dda8 59 int VCO=-1;
gstedile 5:cec68064dda8 60
gstedile 5:cec68064dda8 61 for (int vel=0;vel<100;vel++){
gstedile 5:cec68064dda8 62 if(GET_MAX){ // Si halle el maximo y
gstedile 5:cec68064dda8 63 if(GET_Min == 0){ // no encontré el Minimo. (Aun no halle la VCO)
gstedile 5:cec68064dda8 64 if (this->NAV_DATA[vel].LAST_NAV_DATA[cons_mile_p]<ConsMin){ //La curva sigue decreciendo
gstedile 5:cec68064dda8 65 ConsMin=this->NAV_DATA[vel].LAST_NAV_DATA[cons_mile_p];
gstedile 5:cec68064dda8 66 }
gstedile 5:cec68064dda8 67 else{
gstedile 5:cec68064dda8 68 int eps_m=1;
gstedile 5:cec68064dda8 69 for (int eps=1; eps < Ratio_Min;eps++){
gstedile 5:cec68064dda8 70 if (this->NAV_DATA[vel+eps].LAST_NAV_DATA[cons_mile_p]<ConsMin) {//hay valores menores al minimo hallado en un entorno de v?
gstedile 5:cec68064dda8 71 n_events_eps++;
gstedile 5:cec68064dda8 72 ConsMin=this->NAV_DATA[vel+eps].LAST_NAV_DATA[cons_mile_p];
gstedile 5:cec68064dda8 73 eps_m=eps;
gstedile 5:cec68064dda8 74 }
gstedile 5:cec68064dda8 75 }
gstedile 5:cec68064dda8 76 if (n_events_eps > n_events_critical) vel=vel+eps_m; // falso minimo (hay muchos valores menores al minimo hallado)
gstedile 5:cec68064dda8 77 // nueva ubicación del minimo
gstedile 5:cec68064dda8 78 else {
gstedile 5:cec68064dda8 79 GET_Min=1;
gstedile 5:cec68064dda8 80 VCO=vel-1;
gstedile 5:cec68064dda8 81 }
gstedile 5:cec68064dda8 82 }
gstedile 5:cec68064dda8 83 }
gstedile 5:cec68064dda8 84 }
gstedile 5:cec68064dda8 85
gstedile 5:cec68064dda8 86 else{
gstedile 5:cec68064dda8 87 if (this->NAV_DATA[vel].LAST_NAV_DATA[cons_mile_p]>ConsMAX){ //La curva sigue creciendo
gstedile 5:cec68064dda8 88 ConsMAX=this->NAV_DATA[vel].LAST_NAV_DATA[cons_mile_p];
gstedile 5:cec68064dda8 89 }
gstedile 5:cec68064dda8 90 else{
gstedile 5:cec68064dda8 91 int eps_m=1;
gstedile 5:cec68064dda8 92 for (int eps=1; eps<Ratio_Min;eps++){
gstedile 5:cec68064dda8 93 if (this->NAV_DATA[vel+eps].LAST_NAV_DATA[cons_mile_p]>ConsMAX) {//hay valores mayores al maximo hallado en un entorno de v?
gstedile 5:cec68064dda8 94 n_events_eps++;
gstedile 5:cec68064dda8 95 ConsMAX=this->NAV_DATA[vel+eps].LAST_NAV_DATA[cons_mile_p];
gstedile 5:cec68064dda8 96 eps_m=eps;
gstedile 5:cec68064dda8 97 }
gstedile 5:cec68064dda8 98 }
gstedile 5:cec68064dda8 99 if (n_events_eps > n_events_critical) vel=vel+eps_m; // falso minimo (hay muchos valores menores al minimo hallado)
gstedile 5:cec68064dda8 100 // nueva ubicación del minimo
gstedile 5:cec68064dda8 101 else GET_MAX=1;
gstedile 5:cec68064dda8 102 }
gstedile 5:cec68064dda8 103 }
gstedile 5:cec68064dda8 104
gstedile 5:cec68064dda8 105 }
gstedile 5:cec68064dda8 106
gstedile 5:cec68064dda8 107 return (VCO);
gstedile 5:cec68064dda8 108 }