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.
Revision 0:e89ba43e3f05, committed 2014-10-29
- Comitter:
- wiesdat
- Date:
- Wed Oct 29 11:33:37 2014 +0000
- Child:
- 1:5ac17a29fa08
- Commit message:
- dign
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Encoder.lib Wed Oct 29 11:33:37 2014 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/vsluiter/code/Encoder/#18b000b443af
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed Oct 29 11:33:37 2014 +0000
@@ -0,0 +1,83 @@
+#include "mbed.h"
+#include "encoder.h"
+
+#include <iostream>
+
+Encoder encoderA(PTD0,PTD2);
+
+PwmOut pwm(PTA5);
+DigitalOut dir(PTA4);
+
+
+int32_t enca = 0,enca1 =0,enca2 =0,counts=0, encb;
+float speed = 0,v=0;
+int n=0,a =1 ,b =0;
+
+float pid(float setpoint, float measurement)
+{
+ float error;
+ static float prev_error = 0;
+ float out_p = 0;
+ static float out_i = 0;
+ float out_d = 0;
+ error = setpoint-measurement;
+ out_p = error*K_P;
+ out_i += error*K_I;
+ out_d = (error-prev_error)*K_D;
+ clamp(&out_i,-I_LIMIT,I_LIMIT);
+ prev_error = error;
+ scope.set(1,out_p);
+ scope.set(2,out_i);
+ scope.set(3,out_d);
+ return out_p + out_i + out_d;
+}
+/*
+int main()
+{
+ speed = 0.09;
+ pwm = speed;
+ while(1){
+ wait(0.2);
+ enca = encoderA.getPosition();
+ cout<<enca<<endl;
+ }
+}
+*/
+
+int main()
+{
+ speed = 0.3;
+ pwm = speed;
+
+ while(1){
+ wait(0.5);
+ enca = encoderA.getPosition();
+
+ enca2 = enca1;
+ enca1 = enca;
+
+ counts = (enca1 - enca2)/0.5;
+ v = (counts)*((2*3.14159265359)/1550);
+
+ cout<<"v: "<<v<<endl;
+
+
+
+ }
+
+
+
+
+
+}
+//clamps 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 clamp(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 Wed Oct 29 11:33:37 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1 \ No newline at end of file