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.
Dependencies: Encoder MODSERIAL mbed
Fork of P_controller_motor_Bouke by
Diff: main.cpp
- Revision:
- 5:8ea7a765c1f7
- Parent:
- 4:dfdfcb518e60
- Child:
- 6:34b39eb3dcb6
--- a/main.cpp Thu Sep 17 10:49:09 2015 +0000
+++ b/main.cpp Thu Sep 17 11:11:44 2015 +0000
@@ -8,22 +8,17 @@
// Define Encoder
-Encoder motorP(PTD0,PTC9,true);
+Encoder encoder(PTD0,PTC9,true);
Serial pc(USBTX,USBRX);
-pc.baud(115200);
-while(1) {
- wait(0.2);
- pc.printf("pos: %d, speed %f \r\n",motor1.getPosition(), motor1.getSpeed());
- }
// Define Potmeter
-
+AnalogIn potmeter1(PTB0);
////// P Motor Controller
// Controller gain
-const double motorP_Kp=2.5;
-const double Convert_volt_to_position=0.00300;
+const double motorP_Kp=2.500 ;
+const double Convert_volt_to_position=0.00300 ;
// Reusable P controller (FUNCTIE)
double P (double error, const double Kp)
@@ -31,9 +26,6 @@
return Kp*error;
}
-
-
-
// encoder1
// potmeter1
@@ -41,7 +33,7 @@
void motorP_Controller()
{
double reference_position = potmeter1.read();
- double position = Convert_volt_to_position*encoder1.getPosition();
+ double position = Convert_volt_to_position*encoder.getPosition();
motorP=P(reference_position - position, motorP_Kp);
}
