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: mantieneVelocidad.cpp
- Revision:
- 0:bd4170087cf1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mantieneVelocidad.cpp Mon May 04 08:39:07 2015 +0000
@@ -0,0 +1,31 @@
+#include "mbed.h"
+
+Serial pc3(USBTX, USBRX);
+void mantenerVelocidad(double velocidadDesead, double velocidadActua, double &potenciaMotoresFrameAnterior, double &potenciaMotores, PwmOut pinDAdelante, PwmOut pinIAdelante){
+
+ potenciaMotoresFrameAnterior = potenciaMotores;
+
+ //Para que nunca dividamos por 0
+ if(velocidadActua == 0.0){
+ velocidadActua=velocidadActua+0.1;
+ }
+ double indicePotencias = velocidadDesead/velocidadActua;
+ pc3.printf(" %f ", potenciaMotores);
+ if(indicePotencias>1.0){
+ //Quiere acelerar
+ potenciaMotores+= 0.01;
+
+ }
+ else if(indicePotencias<1.0&&indicePotencias>0.0){
+ potenciaMotores-= 0.01;
+ }
+ else if (indicePotencias < 0.0){
+ //Quiere ir marcha atras
+ }
+ //Limitamos la potencia del motor
+
+ pinDAdelante.write(potenciaMotores);
+ pinIAdelante.write(potenciaMotores);
+
+ }
+
