Facking kut filter werkt EINDELIJK !311!!111!!1!!!!!!!!!!!!!!!!!!!

Dependencies:   HIDScope MODSERIAL Matrix QEI biquadFilter mbed

Fork of Filter by Jurriën Bos

Committer:
JurrienBos
Date:
Mon Oct 15 13:32:30 2018 +0000
Revision:
0:4591ba678a39
Child:
1:4bf64d003f3a
Motor kan draaien in beide richtingen met aansturing van 1 pot meter. Dit implementeren in het eindscript. Geldt tot nog toe voor 1 motor

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JurrienBos 0:4591ba678a39 1 #include "mbed.h"
JurrienBos 0:4591ba678a39 2 #include "MODSERIAL.h"
JurrienBos 0:4591ba678a39 3 MODSERIAL pc(USBTX, USBRX);
JurrienBos 0:4591ba678a39 4 DigitalOut DirectionPin1(D4);
JurrienBos 0:4591ba678a39 5 PwmOut PwmPin1(D5);
JurrienBos 0:4591ba678a39 6 DigitalIn Knop1(D2);
JurrienBos 0:4591ba678a39 7 AnalogIn pot1 (A5);
JurrienBos 0:4591ba678a39 8
JurrienBos 0:4591ba678a39 9 Ticker mycontrollerTicker;
JurrienBos 0:4591ba678a39 10 Ticker printTicker;
JurrienBos 0:4591ba678a39 11 Ticker Velo;
JurrienBos 0:4591ba678a39 12 volatile bool printer;
JurrienBos 0:4591ba678a39 13 const float maxVelocity=8.4; // in rad/s
JurrienBos 0:4591ba678a39 14 volatile float referenceVelocity = 0.5; //dit is de gecentreerde waarde en dus de nulstand
JurrienBos 0:4591ba678a39 15
JurrienBos 0:4591ba678a39 16 void velocityref_print()
JurrienBos 0:4591ba678a39 17 {
JurrienBos 0:4591ba678a39 18 printer = true;
JurrienBos 0:4591ba678a39 19 }
JurrienBos 0:4591ba678a39 20
JurrienBos 0:4591ba678a39 21 void velocity()
JurrienBos 0:4591ba678a39 22 {
JurrienBos 0:4591ba678a39 23 if (pot1.read()>0.5f)
JurrienBos 0:4591ba678a39 24 {
JurrienBos 0:4591ba678a39 25 // Clockwise rotation
JurrienBos 0:4591ba678a39 26 referenceVelocity = (pot1.read()-0.5f) * 2.0f;
JurrienBos 0:4591ba678a39 27 }
JurrienBos 0:4591ba678a39 28
JurrienBos 0:4591ba678a39 29 else if (pot1.read() == 0.5f)
JurrienBos 0:4591ba678a39 30 {
JurrienBos 0:4591ba678a39 31 referenceVelocity = pot1.read() * 0.0f;
JurrienBos 0:4591ba678a39 32 }
JurrienBos 0:4591ba678a39 33
JurrienBos 0:4591ba678a39 34 else if (pot1.read() < 0.5f)
JurrienBos 0:4591ba678a39 35 {
JurrienBos 0:4591ba678a39 36 // Counterclockwise rotation
JurrienBos 0:4591ba678a39 37 referenceVelocity = 2.0f * (pot1.read()-0.5f) ;
JurrienBos 0:4591ba678a39 38 }
JurrienBos 0:4591ba678a39 39
JurrienBos 0:4591ba678a39 40 }
JurrienBos 0:4591ba678a39 41
JurrienBos 0:4591ba678a39 42 void motor()
JurrienBos 0:4591ba678a39 43 {
JurrienBos 0:4591ba678a39 44 float u = referenceVelocity;
JurrienBos 0:4591ba678a39 45 DirectionPin1 = u < 0.0f;
JurrienBos 0:4591ba678a39 46 PwmPin1 = fabs(u);
JurrienBos 0:4591ba678a39 47 }
JurrienBos 0:4591ba678a39 48
JurrienBos 0:4591ba678a39 49
JurrienBos 0:4591ba678a39 50 int main()
JurrienBos 0:4591ba678a39 51 {
JurrienBos 0:4591ba678a39 52 pc.baud(115200);
JurrienBos 0:4591ba678a39 53 PwmPin1.period_us(120); //60 microseconds pwm period, 16.7 kHz
JurrienBos 0:4591ba678a39 54 mycontrollerTicker.attach(motor, 0.002);//500Hz
JurrienBos 0:4591ba678a39 55 printTicker.attach(velocityref_print, 0.5);
JurrienBos 0:4591ba678a39 56 Velo.attach(velocity, 0.002);
JurrienBos 0:4591ba678a39 57 while(true)
JurrienBos 0:4591ba678a39 58 {
JurrienBos 0:4591ba678a39 59 if (printer)
JurrienBos 0:4591ba678a39 60 {
JurrienBos 0:4591ba678a39 61 pc.printf("%f \n",referenceVelocity);
JurrienBos 0:4591ba678a39 62 pc.printf("%f \n",pot1.read());
JurrienBos 0:4591ba678a39 63 printer = false;
JurrienBos 0:4591ba678a39 64 }
JurrienBos 0:4591ba678a39 65 }
JurrienBos 0:4591ba678a39 66 }
JurrienBos 0:4591ba678a39 67