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
mantieneVelocidad.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 | #include "mbed.h" |
| Racafe | 0:bd4170087cf1 | 2 | |
| Racafe | 0:bd4170087cf1 | 3 | Serial pc3(USBTX, USBRX); |
| Racafe | 0:bd4170087cf1 | 4 | void mantenerVelocidad(double velocidadDesead, double velocidadActua, double &potenciaMotoresFrameAnterior, double &potenciaMotores, PwmOut pinDAdelante, PwmOut pinIAdelante){ |
| Racafe | 0:bd4170087cf1 | 5 | |
| Racafe | 0:bd4170087cf1 | 6 | potenciaMotoresFrameAnterior = potenciaMotores; |
| Racafe | 0:bd4170087cf1 | 7 | |
| Racafe | 0:bd4170087cf1 | 8 | //Para que nunca dividamos por 0 |
| Racafe | 0:bd4170087cf1 | 9 | if(velocidadActua == 0.0){ |
| Racafe | 0:bd4170087cf1 | 10 | velocidadActua=velocidadActua+0.1; |
| Racafe | 0:bd4170087cf1 | 11 | } |
| Racafe | 0:bd4170087cf1 | 12 | double indicePotencias = velocidadDesead/velocidadActua; |
| Racafe | 0:bd4170087cf1 | 13 | pc3.printf(" %f ", potenciaMotores); |
| Racafe | 0:bd4170087cf1 | 14 | if(indicePotencias>1.0){ |
| Racafe | 0:bd4170087cf1 | 15 | //Quiere acelerar |
| Racafe | 0:bd4170087cf1 | 16 | potenciaMotores+= 0.01; |
| Racafe | 0:bd4170087cf1 | 17 | |
| Racafe | 0:bd4170087cf1 | 18 | } |
| Racafe | 0:bd4170087cf1 | 19 | else if(indicePotencias<1.0&&indicePotencias>0.0){ |
| Racafe | 0:bd4170087cf1 | 20 | potenciaMotores-= 0.01; |
| Racafe | 0:bd4170087cf1 | 21 | } |
| Racafe | 0:bd4170087cf1 | 22 | else if (indicePotencias < 0.0){ |
| Racafe | 0:bd4170087cf1 | 23 | //Quiere ir marcha atras |
| Racafe | 0:bd4170087cf1 | 24 | } |
| Racafe | 0:bd4170087cf1 | 25 | //Limitamos la potencia del motor |
| Racafe | 0:bd4170087cf1 | 26 | |
| Racafe | 0:bd4170087cf1 | 27 | pinDAdelante.write(potenciaMotores); |
| Racafe | 0:bd4170087cf1 | 28 | pinIAdelante.write(potenciaMotores); |
| Racafe | 0:bd4170087cf1 | 29 | |
| Racafe | 0:bd4170087cf1 | 30 | } |
| Racafe | 0:bd4170087cf1 | 31 |
