Exemplo de controlador proporcional

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Nestordp
Date:
Sun Feb 22 17:16:46 2015 +0000
Child:
1:bdfcf96dc8b1
Commit message:
controlador proporcional

Changed in this revision

HC-SR04.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HC-SR04.lib	Sun Feb 22 17:16:46 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/Nestordp/code/HC-SR04/#12d6d751f4fc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Feb 22 17:16:46 2015 +0000
@@ -0,0 +1,49 @@
+#include "mbed.h"
+#include "HCSR04.h"
+
+#define velocidade(a, b)    MDPWM = a; MEPWM = b 
+#define sentido(a, b)       MDdirect = a; MEdirect = b
+
+//DigitalOut myled(LED1);
+//Serial pc(USBTX,USBRX);     
+
+HCSR04 sonarF(D13, D12);
+
+DigitalOut MEdirect(D4);    //Motor 2 Direction control
+DigitalOut MDdirect(D7);    //Motor 1 Direction control
+PwmOut MEPWM(D5);           //Motor 2 PWM control
+PwmOut MDPWM(D6);           //Motor 1 PWM control
+
+float SP = 25.0;
+float VM;
+float Kp = 0.06;
+float e;
+float v;
+
+int main() {
+    velocidade(0.4, 0.4);
+    while(1){
+        VM = sonarF.getCm();
+        e = SP - VM;
+        v = Kp * e;
+        if(e <= 0){
+            velocidade(v*(-1), v*(-1));
+            sentido(1, 1);
+        }
+        else{
+            velocidade(v, v);
+            sentido(0, 0);
+        }
+        wait(0.2);
+    }
+    
+    /*while(1){
+        if(sonarF.getCm() < 25){
+            sentido(0, 0);
+        }
+        else{
+            sentido(1, 1);
+        }
+        wait(0.2);
+    }*/
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Feb 22 17:16:46 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9ad691361fac
\ No newline at end of file