Start van regelaar

Dependencies:   Encoder MODSERIAL mbed

Dependents:   K9motoraansturing_copy lichtpoortjes

Files at this revision

API Documentation at this revision

Comitter:
vsluiter
Date:
Tue Oct 08 21:57:18 2013 +0000
Child:
1:9d05c0236c7e
Commit message:
start

Changed in this revision

Encoder.lib Show annotated file Show diff for this revision Revisions of this file
MODSERIAL.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/Encoder.lib	Tue Oct 08 21:57:18 2013 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/vsluiter/code/Encoder/#2dd7853c911a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODSERIAL.lib	Tue Oct 08 21:57:18 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Sissors/code/MODSERIAL/#b04ce87dc424
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Oct 08 21:57:18 2013 +0000
@@ -0,0 +1,56 @@
+#include "mbed.h"
+#include "encoder.h"
+#include "MODSERIAL.h"
+
+/** Coerce -> float in, and coerce if less than min, or larger than max **/
+void coerce(float * in, float min, float max);
+AnalogIn potmeter(PTC2);
+volatile bool looptimerflag;
+
+
+void setlooptimerflag(void)
+{
+    looptimerflag = true;
+}
+
+
+int main() {
+    Encoder motor1(PTD0,PTC9);
+    MODSERIAL pc(USBTX,USBRX);
+    PwmOut pwm_motor(PTA12);
+    DigitalOut motordir(PTD3);
+    float setpoint;
+    float new_pwm;
+    pc.baud(115200);
+    Ticker looptimer;
+    looptimer.attach(setlooptimerflag,0.01);  
+    pc.printf("bla"); 
+    while(1) {
+        while(!looptimerflag);
+        looptimerflag = false;
+        setpoint = (potmeter.read())*2000;
+        pc.printf("s: %f, %d \n\r", setpoint, motor1.getPosition());
+        if(motor1.getPosition() > setpoint)
+            new_pwm = 0.5;
+        else
+            new_pwm = -0.5;
+
+        if(new_pwm > 0)
+            motordir = 0;
+        else
+            motordir = 1;  
+        pwm_motor.write(abs(new_pwm));
+    }
+}
+
+
+//coerces value 'in' to min or max when exceeding those values
+//if you'd like to understand the statement below take a google for
+//'ternary operators'.
+void coerce(float * in, float min, float max)
+{
+    *in > min ? *in < max? : *in = max: *in = min;
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Oct 08 21:57:18 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file