Para Juan
Dependencies: NAVDATA RA8875 mbed VCODATA
main.cpp@5:56d63eaa8415, 2017-04-08 (annotated)
- Committer:
- gstedile
- Date:
- Sat Apr 08 22:36:56 2017 +0000
- Revision:
- 5:56d63eaa8415
- Parent:
- 4:9901f6da64b7
- Child:
- 6:aebb3a0a040c
Se agrega generacion de curva de consumo/milla - velocidad con datos ficticios de consumo.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gstedile | 0:d92271b032c7 | 1 | |
gstedile | 0:d92271b032c7 | 2 | #include "mbed.h" // v112 |
gstedile | 0:d92271b032c7 | 3 | #include "RA8875.h" // v102 |
gstedile | 0:d92271b032c7 | 4 | #include "MyFont18x32.h" |
gstedile | 0:d92271b032c7 | 5 | #include "BPG_Arial08x08.h" |
gstedile | 0:d92271b032c7 | 6 | #include "BPG_Arial10x10.h" |
gstedile | 0:d92271b032c7 | 7 | #include "BPG_Arial20x20.h" |
gstedile | 0:d92271b032c7 | 8 | #include "BPG_Arial31x32.h" |
gstedile | 0:d92271b032c7 | 9 | #include "BPG_Arial63x63.h" |
gstedile | 0:d92271b032c7 | 10 | |
gstedile | 0:d92271b032c7 | 11 | // Agrego includes para uso en la comunicacion con el gps. |
gstedile | 4:9901f6da64b7 | 12 | #include "GPS.h" |
gstedile | 4:9901f6da64b7 | 13 | // Agrego includes para la clase NAVDATA que maneja los datos de navegación del último período. |
gstedile | 4:9901f6da64b7 | 14 | #include "NAVDATA.h" |
gstedile | 4:9901f6da64b7 | 15 | // Agrego includes para la clase VCODATA que maneja los datos de navegación más recientes parametrizados por velocidad de cada período. |
gstedile | 3:0c9ee19fb976 | 16 | #include "VCODATA.h" |
gstedile | 3:0c9ee19fb976 | 17 | |
gstedile | 4:9901f6da64b7 | 18 | #include <sstream> //include this to use string streams |
gstedile | 4:9901f6da64b7 | 19 | #include <string> |
gstedile | 0:d92271b032c7 | 20 | |
gstedile | 3:0c9ee19fb976 | 21 | float Counter=0; //Contador de pulsos del sensor de flujo. |
gstedile | 3:0c9ee19fb976 | 22 | float LCounter=0; //Consumo en litros |
gstedile | 3:0c9ee19fb976 | 23 | float Consumo_km=0; //Consumo en litros/km. |
gstedile | 3:0c9ee19fb976 | 24 | NAVDATA NAVIGATION_TABLE; //Objeto que maneja los datos de navegación del último período. $ |
gstedile | 3:0c9ee19fb976 | 25 | VCODATA NAVIGATION_VMATRIX(NAVIGATION_TABLE); // Objeto que maneja la matriz de datos de navegación $ |
gstedile | 0:d92271b032c7 | 26 | |
gstedile | 0:d92271b032c7 | 27 | |
gstedile | 0:d92271b032c7 | 28 | |
gstedile | 4:9901f6da64b7 | 29 | LocalFileSystem local("local"); // Because I want <PrintScreen> |
gstedile | 4:9901f6da64b7 | 30 | Serial pc(USBTX, USBRX); // And a little feedback |
gstedile | 0:d92271b032c7 | 31 | |
gstedile | 4:9901f6da64b7 | 32 | RA8875 lcd(p5, p6, p7, p12, NC, "tft"); // MOSI, MISO, SCK, /ChipSelect, /reset, name |
gstedile | 0:d92271b032c7 | 33 | |
gstedile | 4:9901f6da64b7 | 34 | void trigger() { //Función para la interrupción |
gstedile | 0:d92271b032c7 | 35 | Counter++; |
gstedile | 0:d92271b032c7 | 36 | LCounter=Counter/2500; |
gstedile | 0:d92271b032c7 | 37 | //point_t p_cursor = lcd.GetTextCursor(); |
gstedile | 0:d92271b032c7 | 38 | //lcd.SetTextCursor(0,200); |
gstedile | 0:d92271b032c7 | 39 | //lcd.printf("Flujo %d pulsos", Counter); |
gstedile | 0:d92271b032c7 | 40 | //lcd.SetTextCursor(p_cursor); |
gstedile | 0:d92271b032c7 | 41 | } |
gstedile | 5:56d63eaa8415 | 42 | /* Funcion print_VCO_curve : Imprime la curva de consumo/milla en funcion de la velocidad a partir del vector de objetos NAV_DATA de la clase VCODATA.*/ |
gstedile | 5:56d63eaa8415 | 43 | |
gstedile | 5:56d63eaa8415 | 44 | void print_VCO_curve(VCODATA Matrix_VCO){ |
gstedile | 5:56d63eaa8415 | 45 | int s,y,z; |
gstedile | 5:56d63eaa8415 | 46 | for (int x=0;x<100;x++){ |
gstedile | 5:56d63eaa8415 | 47 | s = Matrix_VCO.NAV_DATA[x].LAST_NAV_DATA[cons_mile_p]; |
gstedile | 5:56d63eaa8415 | 48 | y=200-2*s; // el consumo máximo es alrededor de 100 l/m. Multiplico por 2 para que ocupe mas pantalla. |
gstedile | 5:56d63eaa8415 | 49 | z=x*4; // para aumentar el span (eje x) |
gstedile | 5:56d63eaa8415 | 50 | lcd.SetTextCursor(z,y); |
gstedile | 5:56d63eaa8415 | 51 | //lcd.printf("%d",x); |
gstedile | 5:56d63eaa8415 | 52 | lcd.printf("."); |
gstedile | 5:56d63eaa8415 | 53 | } |
gstedile | 5:56d63eaa8415 | 54 | } |
gstedile | 5:56d63eaa8415 | 55 | |
gstedile | 5:56d63eaa8415 | 56 | |
gstedile | 5:56d63eaa8415 | 57 | /* Funcion build_test_Mtrx: Carga los datos del vector LAST_NAV_DATA de los objetos NAVDATA de VCODATA para testing.*/ |
gstedile | 5:56d63eaa8415 | 58 | |
gstedile | 5:56d63eaa8415 | 59 | void build_test_Mtrx(VCODATA Test_Matrix_VCO){ |
gstedile | 5:56d63eaa8415 | 60 | NAVDATA TestNDO; |
gstedile | 5:56d63eaa8415 | 61 | for (int i=0;i<50;i++){ |
gstedile | 5:56d63eaa8415 | 62 | TestNDO.LAST_NAV_DATA[cons_mile_p]=i; |
gstedile | 5:56d63eaa8415 | 63 | TestNDO.LAST_NAV_DATA[speed_p]=i; |
gstedile | 5:56d63eaa8415 | 64 | Test_Matrix_VCO.store_data(TestNDO); |
gstedile | 5:56d63eaa8415 | 65 | } |
gstedile | 5:56d63eaa8415 | 66 | for (int i=50,x=50;i>0;i--,x++){ |
gstedile | 5:56d63eaa8415 | 67 | TestNDO.LAST_NAV_DATA[cons_mile_p]=i; |
gstedile | 5:56d63eaa8415 | 68 | TestNDO.LAST_NAV_DATA[speed_p]=x; |
gstedile | 5:56d63eaa8415 | 69 | Test_Matrix_VCO.store_data(TestNDO); |
gstedile | 5:56d63eaa8415 | 70 | } |
gstedile | 5:56d63eaa8415 | 71 | } |
gstedile | 5:56d63eaa8415 | 72 | |
gstedile | 0:d92271b032c7 | 73 | |
gstedile | 0:d92271b032c7 | 74 | int main() |
gstedile | 0:d92271b032c7 | 75 | { |
gstedile | 0:d92271b032c7 | 76 | pc.baud(460800); // I like a snappy terminal, so crank it up! |
gstedile | 0:d92271b032c7 | 77 | pc.printf("\r\nRA8875 Soft Fonts - Build " __DATE__ " " __TIME__ "\r\n"); |
gstedile | 0:d92271b032c7 | 78 | |
gstedile | 0:d92271b032c7 | 79 | lcd.init(); |
gstedile | 4:9901f6da64b7 | 80 | |
gstedile | 4:9901f6da64b7 | 81 | // ************************** |
gstedile | 0:d92271b032c7 | 82 | //RunTestSet(lcd, pc); // If the library was compiled for test mode... |
gstedile | 0:d92271b032c7 | 83 | |
gstedile | 0:d92271b032c7 | 84 | lcd.foreground(RGB(255,255,0)); // Seteo del color de las letras. |
gstedile | 0:d92271b032c7 | 85 | lcd.SelectUserFont(BPG_Arial20x20); // Seleccion de tipo y tamaño de letras |
gstedile | 0:d92271b032c7 | 86 | //lcd.puts("BPG_Arial63x63"); |
gstedile | 4:9901f6da64b7 | 87 | |
gstedile | 0:d92271b032c7 | 88 | |
gstedile | 0:d92271b032c7 | 89 | GPS gps(p9, p10); // Agrego para comunicacion con el GPS |
gstedile | 0:d92271b032c7 | 90 | |
gstedile | 0:d92271b032c7 | 91 | //Inicializo variables para el sensor de flujo |
gstedile | 0:d92271b032c7 | 92 | //---------------------------------------------------- |
gstedile | 0:d92271b032c7 | 93 | DigitalOut myled(LED1); |
gstedile | 0:d92271b032c7 | 94 | DigitalOut myled2(LED2); |
gstedile | 0:d92271b032c7 | 95 | DigitalOut myled3(LED3); |
gstedile | 0:d92271b032c7 | 96 | DigitalOut myled4(LED4); |
gstedile | 0:d92271b032c7 | 97 | |
gstedile | 0:d92271b032c7 | 98 | |
gstedile | 0:d92271b032c7 | 99 | //DebounceIn pb(p8); |
gstedile | 0:d92271b032c7 | 100 | /*DigitalIn pb(p11); |
gstedile | 0:d92271b032c7 | 101 | int count=0; //Comento esto porque voy a usar interrupciones |
gstedile | 0:d92271b032c7 | 102 | int old_pb=0; |
gstedile | 0:d92271b032c7 | 103 | int new_pb; |
gstedile | 0:d92271b032c7 | 104 | // Use internal pullup for pushbutton |
gstedile | 0:d92271b032c7 | 105 | pb.mode(PullUp); |
gstedile | 0:d92271b032c7 | 106 | //pb.mode(PullNone); |
gstedile | 0:d92271b032c7 | 107 | // Delay for initial pullup to take effect |
gstedile | 0:d92271b032c7 | 108 | wait(.001);*/ |
gstedile | 0:d92271b032c7 | 109 | |
gstedile | 4:9901f6da64b7 | 110 | //---------------------------------------------------- |
gstedile | 4:9901f6da64b7 | 111 | // Sensor de flujo: |
gstedile | 0:d92271b032c7 | 112 | //----------------------------------------------------- |
gstedile | 0:d92271b032c7 | 113 | InterruptIn pulse_sensor(p11); // Defino pulse_sensor como una entrada de interrupción en p11. |
gstedile | 0:d92271b032c7 | 114 | pulse_sensor.mode(PullUp); // PullUp para esa entrada. |
gstedile | 0:d92271b032c7 | 115 | //DigitalOut led(LED1); |
gstedile | 0:d92271b032c7 | 116 | pulse_sensor.rise(&trigger); // Dispara interrupción con flanco ascendente. (Podría tambien ser desecendente--> fall) |
gstedile | 0:d92271b032c7 | 117 | |
gstedile | 4:9901f6da64b7 | 118 | |
gstedile | 4:9901f6da64b7 | 119 | |
gstedile | 4:9901f6da64b7 | 120 | |
gstedile | 4:9901f6da64b7 | 121 | while(1) { |
gstedile | 4:9901f6da64b7 | 122 | |
gstedile | 5:56d63eaa8415 | 123 | lcd.SetTextCursor(0,0); // Pongo cursor en posicion |
gstedile | 5:56d63eaa8415 | 124 | lcd.puts(">>>>>>>>>>>>>< Proyecto SNOCC ><<<<<<<<<<<<<<\r\n"); |
gstedile | 4:9901f6da64b7 | 125 | |
gstedile | 0:d92271b032c7 | 126 | |
gstedile | 0:d92271b032c7 | 127 | //----------------------------------------------------- |
gstedile | 0:d92271b032c7 | 128 | |
gstedile | 3:0c9ee19fb976 | 129 | //lcd.SetTextCursor(0,20); |
gstedile | 0:d92271b032c7 | 130 | //lcd.printf("M0: %s \r\n\r\n", gps.msg); //Imprimo el mensaje crudo proveniente de la uart |
gstedile | 0:d92271b032c7 | 131 | //lcd.printf("M1: %s \r\n", gps.mensaje1); |
gstedile | 0:d92271b032c7 | 132 | //lcd.printf("M2: %s \r\n", gps.mensaje2); |
gstedile | 0:d92271b032c7 | 133 | //lcd.printf("M3: %s \r\n", gps.mensaje3); |
gstedile | 0:d92271b032c7 | 134 | //lcd.printf("M4: %s \r\n", gps.mensaje4); |
gstedile | 0:d92271b032c7 | 135 | //lcd.printf("Posicion actual_0: %f, %f \r\n", gps.longitude, gps.latitude); |
gstedile | 0:d92271b032c7 | 136 | //lcd.printf("Contador = %d", Counter); |
gstedile | 0:d92271b032c7 | 137 | |
gstedile | 0:d92271b032c7 | 138 | if(gps.sample()) { // Si es exitosa la obtencion de datos del gps. |
gstedile | 3:0c9ee19fb976 | 139 | lcd.cls(); |
gstedile | 5:56d63eaa8415 | 140 | lcd.SetTextCursor(0,0); // Pongo cursor en posicion |
gstedile | 5:56d63eaa8415 | 141 | lcd.puts(">>>>>>>>>>>>>< Proyecto SNOCC ><<<<<<<<<<<<<<\r\n"); |
gstedile | 3:0c9ee19fb976 | 142 | |
gstedile | 4:9901f6da64b7 | 143 | if (NAVIGATION_TABLE.rotate_data(gps.longitude, gps.latitude, gps.time, Counter)){ |
gstedile | 4:9901f6da64b7 | 144 | NAVIGATION_VMATRIX.store_data(NAVIGATION_TABLE);// Luego de rotar los datos en la tabla de navegacion, la guarda en la matriz, |
gstedile | 4:9901f6da64b7 | 145 | // en el lugar correspondiente a la velocidad del preiodo (por ahora reemplaza...ver otras opciones) |
gstedile | 5:56d63eaa8415 | 146 | |
gstedile | 5:56d63eaa8415 | 147 | lcd.puts("Rotacion exitosa!-->"); |
gstedile | 5:56d63eaa8415 | 148 | int i=int(NAVIGATION_TABLE.LAST_NAV_DATA[speed_p]); |
gstedile | 4:9901f6da64b7 | 149 | float timetick_f_Mtrx = NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[time_f]; // DEBUG |
gstedile | 4:9901f6da64b7 | 150 | float distance_p_Mtrx = NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[distance_p]; // DEBUG |
gstedile | 4:9901f6da64b7 | 151 | float speed_p_Mtrx = NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[speed_p]; // DEBUG |
gstedile | 4:9901f6da64b7 | 152 | float longitude_f_Mtrx = NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[longitude_f]; // DEBUG |
gstedile | 4:9901f6da64b7 | 153 | float latitude_f_Mtrx = NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[latitude_f]; // DEBUG |
gstedile | 4:9901f6da64b7 | 154 | float cons_hour_p_Mtrx = NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[cons_hour_p]; |
gstedile | 5:56d63eaa8415 | 155 | //lcd.printf("Algunos datos guardados en la Matriz: \r\n"); // DEBUG |
gstedile | 5:56d63eaa8415 | 156 | lcd.printf("INDICE_Mtrx: %d\r\n",i); // DEBUG |
gstedile | 5:56d63eaa8415 | 157 | /*lcd.printf("Speed_f_Mtrx(%d): %f kn.\r\n",i, speed_p_Mtrx); // DEBUG |
gstedile | 5:56d63eaa8415 | 158 | lcd.printf("Time_f_Mtrx(%d): %f Hours.\r\n",i, timetick_f_Mtrx); // DEBUG |
gstedile | 5:56d63eaa8415 | 159 | lcd.printf("Distance_p_Mtrx(%d): %f miles.\r\n",i,distance_p_Mtrx); // DEBUG |
gstedile | 5:56d63eaa8415 | 160 | lcd.printf("Posicion: Long(%d): %f, Lat: %f\r\n",i,longitude_f_Mtrx,latitude_f_Mtrx); // DEBUG |
gstedile | 5:56d63eaa8415 | 161 | lcd.printf("FlujoVCOmtrx(%d): %f Litros/Hora\r\n",i, cons_hour_p_Mtrx); // DEBUG |
gstedile | 5:56d63eaa8415 | 162 | */ |
gstedile | 5:56d63eaa8415 | 163 | build_test_Mtrx(NAVIGATION_VMATRIX); // DEBUG Curve |
gstedile | 5:56d63eaa8415 | 164 | print_VCO_curve(NAVIGATION_VMATRIX); |
gstedile | 4:9901f6da64b7 | 165 | } |
gstedile | 3:0c9ee19fb976 | 166 | else |
gstedile | 4:9901f6da64b7 | 167 | { |
gstedile | 3:0c9ee19fb976 | 168 | lcd.puts("Periodo no valido!\r\n"); |
gstedile | 4:9901f6da64b7 | 169 | int i=int(NAVIGATION_TABLE.LAST_NAV_DATA[speed_p]); |
gstedile | 4:9901f6da64b7 | 170 | float timetick_f_Mtrx = NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[time_f]; // DEBUG |
gstedile | 4:9901f6da64b7 | 171 | float distance_p_Mtrx = NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[distance_p]; // DEBUG |
gstedile | 4:9901f6da64b7 | 172 | float speed_p_Mtrx = NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[speed_p]; // DEBUG |
gstedile | 4:9901f6da64b7 | 173 | float longitude_f_Mtrx = NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[longitude_f]; // DEBUG |
gstedile | 4:9901f6da64b7 | 174 | float latitude_f_Mtrx = NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[latitude_f]; // DEBUG |
gstedile | 4:9901f6da64b7 | 175 | float cons_hour_p_Mtrx = NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[cons_hour_p]; // DEBUG |
gstedile | 4:9901f6da64b7 | 176 | lcd.printf("Algunos datos guardados en la Matriz: \r\n"); // DEBUG |
gstedile | 5:56d63eaa8415 | 177 | lcd.printf("INDICE_Mtrx: %d (Parte entera de speed)\r\n",i); // DEBUG |
gstedile | 5:56d63eaa8415 | 178 | lcd.printf("Speed_f_Mtrx(%d): %f kn.\r\n",i, speed_p_Mtrx); // DEBUG |
gstedile | 5:56d63eaa8415 | 179 | lcd.printf("Time_f_Mtrx(%d): %f Hours.\r\n",i, timetick_f_Mtrx); // DEBUG |
gstedile | 5:56d63eaa8415 | 180 | lcd.printf("Distance_p_Mtrx(%d): %f miles.\r\n",i,distance_p_Mtrx); // DEBUG |
gstedile | 5:56d63eaa8415 | 181 | lcd.printf("Posicion: Long(%d): %f, Lat: %f\r\n",i,longitude_f_Mtrx,latitude_f_Mtrx); // DEBUG |
gstedile | 5:56d63eaa8415 | 182 | lcd.printf("FlujoVCOmtrx(%d): %f Litros/Hora\r\n",i, cons_hour_p_Mtrx); // DEBUG |
gstedile | 4:9901f6da64b7 | 183 | } |
gstedile | 4:9901f6da64b7 | 184 | /* lcd.SetTextCursor(0,80); |
gstedile | 3:0c9ee19fb976 | 185 | //lcd.printf("Posicion: %f, %f\r\n", gps.longitude, gps.latitude); |
gstedile | 4:9901f6da64b7 | 186 | lcd.printf("Posicion: %f, %f\r\n", NAVIGATION_TABLE.LAST_NAV_DATA[longitude_f], NAVIGATION_TABLE.LAST_NAV_DATA[latitude_f]); // $ |
gstedile | 3:0c9ee19fb976 | 187 | //lcd.printf("Velocidad %f km/h", gps.speed); |
gstedile | 3:0c9ee19fb976 | 188 | lcd.printf("Distancia_p %f km\r\n", NAVIGATION_TABLE.LAST_NAV_DATA[distance_p]); |
gstedile | 3:0c9ee19fb976 | 189 | lcd.printf("Velocidad %f km/h\r\n", NAVIGATION_TABLE.LAST_NAV_DATA[speed_p]); |
gstedile | 3:0c9ee19fb976 | 190 | lcd.printf("Timetick_i %f h\r\n", NAVIGATION_TABLE.LAST_NAV_DATA[time_i]); |
gstedile | 3:0c9ee19fb976 | 191 | lcd.printf("Timetick_f %f h\r\n", NAVIGATION_TABLE.LAST_NAV_DATA[time_f]); |
gstedile | 3:0c9ee19fb976 | 192 | lcd.printf("Timetick_gps %f NMEA\r\n", gps.time); |
gstedile | 4:9901f6da64b7 | 193 | // lcd.printf("Consumo %f l/km", getConsumo(Count; gps.speed); */ |
gstedile | 5:56d63eaa8415 | 194 | //lcd.SetTextCursor(0,220); |
gstedile | 4:9901f6da64b7 | 195 | //lcd.printf("Flujo %f Litros/Hora\r\n", NAVIGATION_TABLE.LAST_NAV_DATA[cons_hour_p]); |
gstedile | 4:9901f6da64b7 | 196 | //lcd.printf("FlujoVCOmtrx %f Litros/Hora\r\n", cons_hour_p_Mtrx); |
gstedile | 5:56d63eaa8415 | 197 | //lcd.printf("Flujo acumulado (contador):%f Litros\r\n", LCounter); |
gstedile | 0:d92271b032c7 | 198 | |
gstedile | 4:9901f6da64b7 | 199 | } |
gstedile | 4:9901f6da64b7 | 200 | else { |
gstedile | 0:d92271b032c7 | 201 | lcd.cls(); |
gstedile | 5:56d63eaa8415 | 202 | lcd.SetTextCursor(0,0); // Pongo cursor en posicion |
gstedile | 5:56d63eaa8415 | 203 | lcd.puts(">>>>>>>>>>>>>< Proyecto SNOCC ><<<<<<<<<<<<<<\r\n"); |
gstedile | 0:d92271b032c7 | 204 | lcd.SetTextCursor(0,100); |
gstedile | 4:9901f6da64b7 | 205 | lcd.printf("No hay datos disponibles :(\r\n"); |
gstedile | 3:0c9ee19fb976 | 206 | lcd.SetTextCursor(0,180); |
gstedile | 4:9901f6da64b7 | 207 | lcd.printf("Timestick %f km/h\r\n", NAVIGATION_TABLE.LAST_NAV_DATA[time_f]); |
gstedile | 4:9901f6da64b7 | 208 | lcd.printf("Flujo %f Litros/Hora\r\n", NAVIGATION_TABLE.LAST_NAV_DATA[cons_hour_p]); |
gstedile | 4:9901f6da64b7 | 209 | lcd.printf("Flujo %f Litros\r\n", LCounter); |
gstedile | 0:d92271b032c7 | 210 | } |
gstedile | 4:9901f6da64b7 | 211 | } |
gstedile | 0:d92271b032c7 | 212 | } |