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
calculaVelocidad.cpp@0:bd4170087cf1, 2015-05-04 (annotated)
- Committer:
- Racafe
- Date:
- Mon May 04 08:39:07 2015 +0000
- Revision:
- 0:bd4170087cf1
Todo a?adido;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Racafe | 0:bd4170087cf1 | 1 | |
| Racafe | 0:bd4170087cf1 | 2 | #include "calculaVelocidad.h" |
| Racafe | 0:bd4170087cf1 | 3 | #include "main.h" |
| Racafe | 0:bd4170087cf1 | 4 | |
| Racafe | 0:bd4170087cf1 | 5 | double velocidadActual=0.0; |
| Racafe | 0:bd4170087cf1 | 6 | double historialVelocidades[]={0.0,0.0,0.0}; |
| Racafe | 0:bd4170087cf1 | 7 | int nominado = 0; |
| Racafe | 0:bd4170087cf1 | 8 | |
| Racafe | 0:bd4170087cf1 | 9 | double suavizaVelocidad(double velocidad){ |
| Racafe | 0:bd4170087cf1 | 10 | double res= velocidad*0.7+historialVelocidades[0]*0.1+historialVelocidades[1]*0.1+historialVelocidades[0]*0.1; |
| Racafe | 0:bd4170087cf1 | 11 | return res; |
| Racafe | 0:bd4170087cf1 | 12 | } |
| Racafe | 0:bd4170087cf1 | 13 | |
| Racafe | 0:bd4170087cf1 | 14 | |
| Racafe | 0:bd4170087cf1 | 15 | //A partir de las muescas de la rueda, calcula la velocidad en km/h |
| Racafe | 0:bd4170087cf1 | 16 | double calculaVelocidad(int periodo, int acumulador){ |
| Racafe | 0:bd4170087cf1 | 17 | double minutos = periodo / 60000.0; |
| Racafe | 0:bd4170087cf1 | 18 | double revoluciones = acumulador / 20.0; |
| Racafe | 0:bd4170087cf1 | 19 | double revolucionesporMinuto = revoluciones/minutos; |
| Racafe | 0:bd4170087cf1 | 20 | double velocidad = revolucionesporMinuto*3.4*2*3.141592/60/100*3.6; |
| Racafe | 0:bd4170087cf1 | 21 | velocidad = suavizaVelocidad(velocidad); |
| Racafe | 0:bd4170087cf1 | 22 | historialVelocidades[nominado]=velocidad; |
| Racafe | 0:bd4170087cf1 | 23 | nominado++; |
| Racafe | 0:bd4170087cf1 | 24 | if(nominado >= 3){ |
| Racafe | 0:bd4170087cf1 | 25 | nominado = 0; |
| Racafe | 0:bd4170087cf1 | 26 | } |
| Racafe | 0:bd4170087cf1 | 27 | |
| Racafe | 0:bd4170087cf1 | 28 | velocidadActual = velocidad; |
| Racafe | 0:bd4170087cf1 | 29 | |
| Racafe | 0:bd4170087cf1 | 30 | return velocidad; |
| Racafe | 0:bd4170087cf1 | 31 | } |
| Racafe | 0:bd4170087cf1 | 32 | |
| Racafe | 0:bd4170087cf1 | 33 | |
| Racafe | 0:bd4170087cf1 | 34 | |
| Racafe | 0:bd4170087cf1 | 35 |
