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.
Revision 11:b12388526706, committed 2017-07-30
- Comitter:
- gstedile
- Date:
- Sun Jul 30 15:38:40 2017 +0000
- Parent:
- 10:08e1dc33199e
- Commit message:
- V9_UI
Changed in this revision
| VCODATA.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 08e1dc33199e -r b12388526706 VCODATA.cpp
--- a/VCODATA.cpp Fri Jun 23 03:59:00 2017 +0000
+++ b/VCODATA.cpp Sun Jul 30 15:38:40 2017 +0000
@@ -65,44 +65,46 @@
int VCODATA::store_data (NAVDATA &LastData,int cant_per){
-
- int cp=cant_per; // Periodos consecutivos a velocidad constante para validar datos.
+ int k_hist_data=3; // Coeficiente para dar peso al valor histórico almacenado.
+ int k_new_data=1; // Coeficiente para dar peso al valor nuevo a almacenar.
+ int k_total=k_hist_data+k_new_data; // Denominador
+ int cp=cant_per; // Periodos consecutivos a velocidad constante para validar datos.
int buff_index=int(this->NAV_DATA[vel_max].LAST_NAV_DATA[speed_p]+0.5); // (2)Indice del dato del "buffer" (situado en la posicion vel_max). Si hay cambio de velocidad,
// esto se actualiza cuando se "pisa" el objeto del buffer con el entrante. (Ver + adelante(*))
- //if (buff_index<0 || buff_index > vel_max) return 4; // si el indice esta fuera de rango, salgo con error.
+
int last_index=int(LastData.LAST_NAV_DATA[speed_p]+0.5); // Indice del dato entrante.
if (last_index<0 || last_index > vel_max) return 4; // si el indice esta fuera de rango, salgo con error.
- //float cons_m_hist4buff_index; // Valor historico corresp. a la velocidad en cuestion.
- //float cons_h_hist4buff_index; // Valor historico corresp. a la velocidad en cuestion.
+
+
double cons_m_hist4last_index=this->NAV_DATA[last_index].LAST_NAV_DATA[cons_mile_p]; // Valor historico corresp. a la velocidad en cuestion.
double cons_h_hist4last_index=this->NAV_DATA[last_index].LAST_NAV_DATA[cons_hour_p]; // Valor historico corresp. a la velocidad en cuestion.
- //(1)int data_type4buff_index=this->NAV_DATA[buff_index].LAST_NAV_DATA[cons_interpolated]; // Tipo de dato historico: 0-> real ; 1->interpolated; 2->smoothed; -1-> initial padding
-
+
+
int last_data_type=LastData.LAST_NAV_DATA[cons_interpolated]; // Tipo de dato entrante
double delta_t=LastData.LAST_NAV_DATA[time_f]- this->NAV_DATA[vel_max].LAST_NAV_DATA[time_f]; // Delta de tiempo entre entrante y buffer.
if ((delta_t > 0) || (last_data_type!=0)|| (this->NAV_DATA[vel_max].LAST_NAV_DATA[cons_interpolated]!=0)){ // Solo valido el dato entrante si el timestamp es posterior al almacenado
// o se trata de un valor inicial (no recolectado).
if ( delta_t > this->NAV_DATA->max_period_time || (fabs(this->NAV_DATA[vel_max].LAST_NAV_DATA[speed_p] - LastData.LAST_NAV_DATA[speed_p])> this->DeltaV) || (this->NAV_DATA[vel_max].np_concat==0)) {
- //if ( delta_t <= this->NAV_DATA->max_period_time && (fabs(this->NAV_DATA[vel_max].LAST_NAV_DATA[speed_p] - LastData.LAST_NAV_DATA[speed_p])< this->DeltaV)&& (this->NAV_DATA[vel_max].np_concat < cp) && (this->NAV_DATA[vel_max].np_concat!=0)) {
- //if ((fabs(this->NAV_DATA[vel_max].LAST_NAV_DATA[speed_p] - LastData.LAST_NAV_DATA[speed_p])< this->DeltaV)&& (this->NAV_DATA[vel_max].np_concat <= cp) ) {
- //Evaluacion de delta de velocidad para considerar no aceleracion, no ser fin de concatenacion a vel cte. ni datos de inicio de ciclo.
+
+
+ //Evaluacion de: delta de velocidad para considerar no aceleracion, no ser fin de concatenacion a vel cte. ni datos de inicio de ciclo.
this->NAV_DATA[vel_max]=LastData; // Cargo el entrante en la posicion [vel_max], reemplazando al anterior.
if (cp == 1) { // No se concatenan períodos-->corresponde almacenar los datos y resetear np_concat.
buff_index=last_index; //(*)(2) Indice: del nuevo dato del "buffer" (situado en la posicion vel_max)
- //if (buff_index<0 || buff_index > vel_max) return 4; // si el indice esta fuera de rango, salgo con error.
- int data_type4buff_index=this->NAV_DATA[buff_index].LAST_NAV_DATA[cons_interpolated]; //(1) Tipo de dato historico: 0-> real ; 1->interpolated; 2->smoothed; -1-> initial padding
- //cons_m_hist4buff_index=this->NAV_DATA[buff_index].LAST_NAV_DATA[cons_mile_p]; // (*)Actualiza valor historico corresp. a la velocidad apuntada por el nuevo dato.
- //cons_h_hist4buff_index=this->NAV_DATA[buff_index].LAST_NAV_DATA[cons_hour_p]; // (*)Actualiza valor historico corresp. a la velocidad apuntada por el nuevo dato.
+
+ int data_type4buff_index=this->NAV_DATA[buff_index].LAST_NAV_DATA[cons_interpolated]; //(1) Tipo de dato historico: 0-> real ; 1->interpolated; 2->smoothed; -1-> initial padding
+
+
this->NAV_DATA[buff_index] = this->NAV_DATA[vel_max]; // Carga el objeto del buffer reemplazando al anterior NAV_DATA para luego actualizar el valor de consumo promediandolo con el del buffer.
if (data_type4buff_index==0 && this->NAV_DATA[vel_max].LAST_NAV_DATA[cons_interpolated]==0){ // (1) Solo si valores existente y entrante son recolectado---> promediar cons. historico con buffer.
- this->NAV_DATA[buff_index].LAST_NAV_DATA[cons_mile_p]=(this->NAV_DATA[vel_max].LAST_NAV_DATA[cons_mile_p] + cons_m_hist4last_index)/2;
- // this->NAV_DATA[buff_index].LAST_NAV_DATA[cons_mile_p]=(this->NAV_DATA[vel_max].LAST_NAV_DATA[cons_mile_p] + this->NAV_DATA[buff_index].LAST_NAV_DATA[cons_mile_p])/2; //(3)
- this->NAV_DATA[buff_index].LAST_NAV_DATA[cons_hour_p]=(this->NAV_DATA[vel_max].LAST_NAV_DATA[cons_hour_p]+ cons_h_hist4last_index)/2;
- // this->NAV_DATA[buff_index].LAST_NAV_DATA[cons_hour_p]=(this->NAV_DATA[vel_max].LAST_NAV_DATA[cons_hour_p]+ this->NAV_DATA[buff_index].LAST_NAV_DATA[cons_hour_p])/2; //(4)
+ this->NAV_DATA[buff_index].LAST_NAV_DATA[cons_mile_p]=(k_new_data*this->NAV_DATA[vel_max].LAST_NAV_DATA[cons_mile_p] + k_hist_data*cons_m_hist4last_index)/k_total;
+
+ this->NAV_DATA[buff_index].LAST_NAV_DATA[cons_hour_p]=(k_new_data*this->NAV_DATA[vel_max].LAST_NAV_DATA[cons_hour_p]+ k_hist_data*cons_h_hist4last_index)/k_total;
+
}
this->NAV_DATA[vel_max].np_concat=0; // Reset de la cantidad de concatenamientos.
}
@@ -116,19 +118,19 @@
if (this->NAV_DATA[vel_max].np_concat == cp) { // Se alcanzo el numero de períodos cp a velocidad constante-->corresponde almacenar los datos y resetear np_concat.
buff_index=int(this->NAV_DATA[vel_max].LAST_NAV_DATA[speed_p]+0.5); //ACTUALIZO despues de merge(2) Indice: del dato del "buffer" (situado en la posicion vel_max)
- //cons_m_hist4buff_index=this->NAV_DATA[buff_index].LAST_NAV_DATA[cons_mile_p]; // (*)Actualiza valor historico luego del "merge" corresp. a la velocidad en cuestion.
- //cons_h_hist4buff_index=this->NAV_DATA[buff_index].LAST_NAV_DATA[cons_hour_p]; // (*)Actualiza valor historico luego del "merge" corresp. a la velocidad en cuestion.
+
+
int data_type4buff_index=this->NAV_DATA[buff_index].LAST_NAV_DATA[cons_interpolated]; //(1) Tipo de dato historico: 0-> real ; 1->interpolated; 2->smoothed; -1-> initial padding
this->NAV_DATA[buff_index] = this->NAV_DATA[vel_max]; // Carga el objeto del buffer reemplazando al anterior NAV_DATA para luego actualizar el valor de consumo promediandolo con el del buffer.
if (data_type4buff_index==0){ // (1) Solo si el valor existente es recolectado---> promediar cons. historico con buffer.
- this->NAV_DATA[buff_index].LAST_NAV_DATA[cons_mile_p]=(this->NAV_DATA[vel_max].LAST_NAV_DATA[cons_mile_p] + cons_m_hist4last_index)/2;
- // this->NAV_DATA[buff_index].LAST_NAV_DATA[cons_mile_p]=(this->NAV_DATA[vel_max].LAST_NAV_DATA[cons_mile_p] + this->NAV_DATA[buff_index].LAST_NAV_DATA[cons_mile_p])/2; //(3)
- this->NAV_DATA[buff_index].LAST_NAV_DATA[cons_hour_p]=(this->NAV_DATA[vel_max].LAST_NAV_DATA[cons_hour_p]+ cons_h_hist4last_index)/2;
- // this->NAV_DATA[buff_index].LAST_NAV_DATA[cons_hour_p]=(this->NAV_DATA[vel_max].LAST_NAV_DATA[cons_hour_p]+ this->NAV_DATA[buff_index].LAST_NAV_DATA[cons_hour_p])/2; //(4)
+ this->NAV_DATA[buff_index].LAST_NAV_DATA[cons_mile_p]=(k_new_data*this->NAV_DATA[vel_max].LAST_NAV_DATA[cons_mile_p] + k_hist_data*cons_m_hist4last_index)/k_total;
+
+ this->NAV_DATA[buff_index].LAST_NAV_DATA[cons_hour_p]=(k_new_data*this->NAV_DATA[vel_max].LAST_NAV_DATA[cons_hour_p]+ k_hist_data*cons_h_hist4last_index)/k_total;
+
}
- // No necesita else porque en ese caso queda el valor nuevo (sin promediar con el viejo) y el tipo de dato es el del nuevo, seteado oportunamente al generarse el dato
+
this->NAV_DATA[vel_max].np_concat=0; // Reset de la cantidad de concatenamientos.
}
}
@@ -155,7 +157,7 @@
int VCO=-1;
find GET_MAX=NO;
- for (int vel=0;vel<vel_max;vel++){
+ for (int vel=5;vel<vel_max;vel++){
if(GET_MAX==SI){ // Si halle el maximo y
if(GET_Min == 0){ // no encontré el Minimo. (Aun no halle la VCO)
if (this->NAV_DATA[vel].LAST_NAV_DATA[cons_mile_p]<=ConsMin){ //La curva sigue decreciendo
@@ -220,7 +222,7 @@
}
VCC[0]=VCO;
- return VCO;
+ return VCC[0];
}
@@ -258,7 +260,7 @@
while (x_P2>0 ) { // Puntos validos? (Si es no válido get_next devuelve -1).
if ( x_P2>x_P1+1) this->interp_x1_x2(x_P1, x_P2); // Interpola entre los 2 puntos dados.
x_P1=x_P2;
- x_P2=this->get_next_P(x_P2);
+ x_P2=this->get_next_P(x_P1);
}
}
@@ -266,13 +268,13 @@
//get_next_P(int x_value): Retorna la ordenada del siguiente valor recolectado, que no es resultado de la interpolacion.
int VCODATA::get_next_P(int x_value){
- int i=1;
- int j=i+x_value;
- while (j<=vel_max){
- if ( this->NAV_DATA[j].LAST_NAV_DATA[cons_mile_p] <=0 || this->NAV_DATA[j].LAST_NAV_DATA[cons_interpolated] == 1) j++; // Avanzar mientras haya valores ya interpolados, nulos, o -1 (caso de distancia recorrida nula-->0 milla)
+ //int i=1;
+ int j=x_value+1;
+ while (j<this->vel_max){
+ if ( this->NAV_DATA[j].LAST_NAV_DATA[cons_mile_p] <=0 || this->NAV_DATA[j].LAST_NAV_DATA[cons_interpolated] != 0) j++; // Avanzar mientras haya valores ya interpolados, nulos, o -1 (caso de distancia recorrida nula-->0 milla)
else break;
}
- if (j>vel_max)return(-1); // Llego al final sin hallar punto válido.
+ if (j==this->vel_max)return(-1); // Llego al final sin hallar punto válido.
else return(j);
}
@@ -327,7 +329,7 @@
int n_int=int (n_dots/2);
int n_dif_l=0; // Valor para sesgar el entorno de promediado, respecto de la posicion actual, en caso de n par.
if ((n_dots%n_int)==0)n_dif_l=1; // si n es par entonces tomo una muestra menos del lado derecho. Elijo esta forma porque
- // al discretizar la curva hemos redondeado hacia abajo los valores de velocidad; esto significa que el
+ // esto cambio....>> // al discretizar la curva hemos redondeado hacia abajo los valores de velocidad; esto significa que el
// valor de consumo asociado a una velocidad fue desplazado hacia la izquierda, por lo tanto, promediandolo
// con valores corresp. a velocidades con cierto sesgo hacia izquierda, mejora la representación y mas aún
// con respecto al caso opuesto. Debe pensarse estadisticamente teniendo en cuenta que