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.
Fork of RobotCompleto by
Diff: calculaVelocidad.cpp
- Revision:
- 0:bd4170087cf1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/calculaVelocidad.cpp Mon May 04 08:39:07 2015 +0000
@@ -0,0 +1,35 @@
+
+#include "calculaVelocidad.h"
+#include "main.h"
+
+double velocidadActual=0.0;
+double historialVelocidades[]={0.0,0.0,0.0};
+int nominado = 0;
+
+double suavizaVelocidad(double velocidad){
+ double res= velocidad*0.7+historialVelocidades[0]*0.1+historialVelocidades[1]*0.1+historialVelocidades[0]*0.1;
+ return res;
+ }
+
+
+//A partir de las muescas de la rueda, calcula la velocidad en km/h
+double calculaVelocidad(int periodo, int acumulador){
+ double minutos = periodo / 60000.0;
+ double revoluciones = acumulador / 20.0;
+ double revolucionesporMinuto = revoluciones/minutos;
+ double velocidad = revolucionesporMinuto*3.4*2*3.141592/60/100*3.6;
+ velocidad = suavizaVelocidad(velocidad);
+ historialVelocidades[nominado]=velocidad;
+ nominado++;
+ if(nominado >= 3){
+ nominado = 0;
+ }
+
+ velocidadActual = velocidad;
+
+ return velocidad;
+}
+
+
+
+
