Draaiende motor op commando van knopje (WERKEND)

Dependencies:   Encoder MODSERIAL mbed

Fork of P_controller_motor by Bouke Scheltinga

Committer:
ThomasBNL
Date:
Thu Sep 17 10:08:19 2015 +0000
Revision:
0:843492f4fe62
Child:
1:b0d3c64bd4d8
Basics P motor controller untested;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ThomasBNL 0:843492f4fe62 1 #include "mbed.h"
ThomasBNL 0:843492f4fe62 2 #include "HIDScope.h"
ThomasBNL 0:843492f4fe62 3
ThomasBNL 0:843492f4fe62 4 //P Motor Controller
ThomasBNL 0:843492f4fe62 5
ThomasBNL 0:843492f4fe62 6 // Controller gain
ThomasBNL 0:843492f4fe62 7 const double motorP_Kp=2.5;
ThomasBNL 0:843492f4fe62 8 const double Convert_volt_to_position=0.00300;
ThomasBNL 0:843492f4fe62 9
ThomasBNL 0:843492f4fe62 10 // Reusable P controller (FUNCTIE)
ThomasBNL 0:843492f4fe62 11 double P (double error, const double Kp)
ThomasBNL 0:843492f4fe62 12 {
ThomasBNL 0:843492f4fe62 13 Return Kp*error;
ThomasBNL 0:843492f4fe62 14 }
ThomasBNL 0:843492f4fe62 15
ThomasBNL 0:843492f4fe62 16 // Error measurement and apply the output to the plant
ThomasBNL 0:843492f4fe62 17 void motorP_Controller()
ThomasBNL 0:843492f4fe62 18 {
ThomasBNL 0:843492f4fe62 19 double reference_position = potmeter1.read();
ThomasBNL 0:843492f4fe62 20 double position = Convert_volt_to_position*encoder1.getPosition();
ThomasBNL 0:843492f4fe62 21 motorP=P(reference_position - position, motorP_Kp);
ThomasBNL 0:843492f4fe62 22 }
ThomasBNL 0:843492f4fe62 23
ThomasBNL 0:843492f4fe62 24 int main()
ThomasBNL 0:843492f4fe62 25 {
ThomasBNL 0:843492f4fe62 26 myControllerTicker.attach(&motorP_Controller,0.01f); //100Hz
ThomasBNL 0:843492f4fe62 27 while(1){}
ThomasBNL 0:843492f4fe62 28 }