Motor control, feedback, PI controller, BiQuad filter
Dependencies: FastPWM HIDScope MODSERIAL biquadFilter mbed QEI
Diff: main.cpp
- Revision:
- 16:0a8d4d746454
- Parent:
- 15:c2cfab737a4c
--- a/main.cpp Fri Oct 19 09:30:44 2018 +0000 +++ b/main.cpp Fri Oct 19 10:29:38 2018 +0000 @@ -3,17 +3,22 @@ #include "MODSERIAL.h" #include "QEI.h" #include <math.h> +#include "HIDScope.h" MODSERIAL pc(USBTX, USBRX); DigitalOut motor1DirectionPin(D7); FastPWM motor1MagnitudePin(D6); AnalogIn potMeter1(A4); AnalogIn potMeter2(A5); InterruptIn button2(D3); +DigitalOut led(LED1); + QEI Encoder (D12, D13, NC, 64, QEI::X4_ENCODING); +HIDScope scope(1); // 1 channel //Tickers Ticker MeasureControl; Ticker print; +Ticker hidscopetimer; /*Ticker MakeMotorRotate;*/ //Waar zal deze ticker voor dienen? //Global variables @@ -90,6 +95,12 @@ motorValue = FeedbackControl(referencePosition - measuredPosition); SetMotor1(motorValue); } +void hidscope() +{ + scope.set(0, 10.0); // set the encoder pulses in channel 0 + scope.send(); + led = !led; +} void printen() { @@ -105,10 +116,11 @@ int main() { //Initialize once - pc.baud(115200); + //pc.baud(115200); motor1MagnitudePin.period_us(60.0); // 60 microseconds PWM period: 16.7 kHz. MeasureControl.attach(MeasureAndControl, 0.01); - print.attach(printen, 3); + hidscopetimer.attach(&hidscope,0.05); + //print.attach(printen, 3); //Other initializations