test with PID control to screen on your computer

Dependencies:   Motor_with_encoder MODSERIAL QEI mbed

Fork of Project_motor by Biorobotics Project

Revision:
1:e0f6cdefcd6e
Parent:
0:bc949f735b8d
Child:
2:80177e90c1e6
--- a/main.cpp	Tue Oct 03 15:07:02 2017 +0000
+++ b/main.cpp	Tue Oct 03 15:24:46 2017 +0000
@@ -7,13 +7,13 @@
 PwmOut motorspeed(D5);
 DigitalOut motorposition(D4);
 DigitalOut led1(D8);
-DigitalOut led2(D7);
+DigitalOut led2(D11);
 AnalogIn pot(A1);
 DigitalIn button1(D9);
 DigitalIn button2(D10);
 Ticker potmeterreadout;
-//Ticker encoderreadout;
-//Encoder motor1(PTD0,PTC4); // motor 1 is from encoder, otherwise it would be a pain in the ass to change all that code to motorencoder
+Ticker encoderreadout;
+Encoder motor1(PTD0,PTC4); // motor 1 is from encoder, otherwise it would be a pain in the ass to change all that code to motorencoder
 
 
 float PwmPeriod = 1.0/5000.0;
@@ -24,13 +24,15 @@
 }
 */
 volatile float potvalue = 0.0;
+volatile float position = 0.0;
 void readpot(){
     potvalue = pot.read();
+    //position = motor1.getPosition();
+    pc.printf("pos: %d, speed %f \r\n",motor1.getPosition(), motor1.getSpeed());
     }
 int main()
-{
+{  
     
-    //encoderreadout.attach(readoutencoder,0.2f);
     pc.baud(9600);
     potmeterreadout.attach(readpot,0.2f);
     motorspeed.period(0.0001f);
@@ -39,7 +41,7 @@
         
             led1 = potvalue;
             motorspeed = potvalue;
-            pc.printf("reference velocity = %.2f\r\n", potvalue);     
+            //pc.printf("reference velocity = %.2f\r\n", potvalue);     
         
 
             if ((button2 == 1)&&(button1 == 0)) {