Ramon Waninge / Mbed 2 deprecated Milestone1

Dependencies:   FastPWM mbed QEI biquadFilter HIDScope MODSERIAL

Committer:
efvanmarrewijk
Date:
Wed Oct 31 17:35:57 2018 +0000
Revision:
45:53c4fca47ed4
Parent:
18:ca084c362855
Working version with all angles in doubles

Who changed what in which revision?

UserRevisionLine numberNew contents of line
efvanmarrewijk 16:720365110953 1 // Inclusion of libraries
Ramonwaninge 0:3ea1bbfbeaae 2 #include "mbed.h"
efvanmarrewijk 11:3efd6a324f16 3 #include "FastPWM.h"
efvanmarrewijk 11:3efd6a324f16 4 #include "QEI.h" // Includes library for encoder
efvanmarrewijk 13:6556cd086d07 5 #include "MODSERIAL.h"
efvanmarrewijk 13:6556cd086d07 6 #include "HIDScope.h"
efvanmarrewijk 13:6556cd086d07 7 #include "BiQuad.h"
Ramonwaninge 0:3ea1bbfbeaae 8
efvanmarrewijk 14:e21cb701ccb8 9 // Input
efvanmarrewijk 9:65c52c1f4a57 10
efvanmarrewijk 14:e21cb701ccb8 11 // Output
Ramonwaninge 2:d8a552d1d33a 12
efvanmarrewijk 16:720365110953 13 // Utilisation of libraries
efvanmarrewijk 16:720365110953 14 MODSERIAL pc(USBTX, USBRX);
efvanmarrewijk 18:ca084c362855 15 QEI Encoder1(D11,D10,NC,4200); // Counterclockwise motor rotation is the positive direction
efvanmarrewijk 18:ca084c362855 16 QEI Encoder2(D9,D8,NC,4200); // Counterclockwise motor rotation is the positive direction
efvanmarrewijk 18:ca084c362855 17 QEI Encoder3(D13,D12,NC,4200); // Counterclockwise motor rotation is the positive direction
efvanmarrewijk 9:65c52c1f4a57 18
efvanmarrewijk 16:720365110953 19 // Global variables
efvanmarrewijk 45:53c4fca47ed4 20 const double pi = 3.14159265358979;
efvanmarrewijk 18:ca084c362855 21
efvanmarrewijk 16:720365110953 22
efvanmarrewijk 16:720365110953 23 // Functions
efvanmarrewijk 18:ca084c362855 24 void Encoderinput()
efvanmarrewijk 18:ca084c362855 25 { int counts1;
efvanmarrewijk 18:ca084c362855 26 int counts2;
efvanmarrewijk 18:ca084c362855 27 int counts3;
efvanmarrewijk 45:53c4fca47ed4 28 double angle1;
efvanmarrewijk 45:53c4fca47ed4 29 double angle2;
efvanmarrewijk 45:53c4fca47ed4 30 double angle3;
efvanmarrewijk 18:ca084c362855 31 counts1 = Encoder1.getPulses();
efvanmarrewijk 18:ca084c362855 32 counts2 = Encoder2.getPulses();
efvanmarrewijk 18:ca084c362855 33 counts3 = Encoder3.getPulses();
efvanmarrewijk 45:53c4fca47ed4 34 angle1 = ((double)counts1*2.0*pi)/4200.0;
efvanmarrewijk 45:53c4fca47ed4 35 angle2 = ((double)counts2*2.0*pi)/4200.0;
efvanmarrewijk 45:53c4fca47ed4 36 angle3 = ((double)counts3*2.0*pi)/4200.0;
efvanmarrewijk 18:ca084c362855 37
efvanmarrewijk 18:ca084c362855 38 pc.printf("Counts1: %i Angle1: %f Counts2: %i Angle2: %f\r\n",counts1,angle1,counts2,angle2);
efvanmarrewijk 18:ca084c362855 39 }
efvanmarrewijk 16:720365110953 40
efvanmarrewijk 16:720365110953 41 // Main program
efvanmarrewijk 11:3efd6a324f16 42 int main()
efvanmarrewijk 18:ca084c362855 43 {
efvanmarrewijk 14:e21cb701ccb8 44 pc.baud(115200);
efvanmarrewijk 18:ca084c362855 45
efvanmarrewijk 17:0ae9e8c958f8 46
efvanmarrewijk 16:720365110953 47 while (true)
efvanmarrewijk 18:ca084c362855 48 { Encoderinput();
Ramonwaninge 3:d39285fdd103 49 }
Ramonwaninge 0:3ea1bbfbeaae 50 }