Facking kut filter werkt EINDELIJK !311!!111!!1!!!!!!!!!!!!!!!!!!!
Dependencies: HIDScope MODSERIAL Matrix QEI biquadFilter mbed
Fork of Turning_Motor_V6 by
main.cpp
- Committer:
- JurrienBos
- Date:
- 2018-10-15
- Revision:
- 0:4591ba678a39
- Child:
- 1:4bf64d003f3a
File content as of revision 0:4591ba678a39:
#include "mbed.h" #include "MODSERIAL.h" MODSERIAL pc(USBTX, USBRX); DigitalOut DirectionPin1(D4); PwmOut PwmPin1(D5); DigitalIn Knop1(D2); AnalogIn pot1 (A5); Ticker mycontrollerTicker; Ticker printTicker; Ticker Velo; volatile bool printer; const float maxVelocity=8.4; // in rad/s volatile float referenceVelocity = 0.5; //dit is de gecentreerde waarde en dus de nulstand void velocityref_print() { printer = true; } void velocity() { if (pot1.read()>0.5f) { // Clockwise rotation referenceVelocity = (pot1.read()-0.5f) * 2.0f; } else if (pot1.read() == 0.5f) { referenceVelocity = pot1.read() * 0.0f; } else if (pot1.read() < 0.5f) { // Counterclockwise rotation referenceVelocity = 2.0f * (pot1.read()-0.5f) ; } } void motor() { float u = referenceVelocity; DirectionPin1 = u < 0.0f; PwmPin1 = fabs(u); } int main() { pc.baud(115200); PwmPin1.period_us(120); //60 microseconds pwm period, 16.7 kHz mycontrollerTicker.attach(motor, 0.002);//500Hz printTicker.attach(velocityref_print, 0.5); Velo.attach(velocity, 0.002); while(true) { if (printer) { pc.printf("%f \n",referenceVelocity); pc.printf("%f \n",pot1.read()); printer = false; } } }