Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FastPWM mbed QEI biquadFilter HIDScope MODSERIAL
main.cpp
- Committer:
- efvanmarrewijk
- Date:
- 2018-10-22
- Revision:
- 20:695140b8db2f
- Parent:
- 19:1d0b25d4d775
- Parent:
- 18:ca084c362855
- Child:
- 21:363271dcfe1f
File content as of revision 20:695140b8db2f:
// Inclusion of libraries #include "mbed.h" #include "FastPWM.h" #include "QEI.h" // Includes library for encoder #include "MODSERIAL.h" #include "HIDScope.h" #include "BiQuad.h" // Input // Output // Utilisation of libraries MODSERIAL pc(USBTX, USBRX); QEI Encoder1(D11,D10,NC,4200); // Counterclockwise motor rotation is the positive direction QEI Encoder2(D9,D8,NC,4200); // Counterclockwise motor rotation is the positive direction QEI Encoder3(D13,D12,NC,4200); // Counterclockwise motor rotation is the positive direction Ticker motor; // Global variables const float pi = 3.14159265358979; float u3 = 0.0; // Normalised variable for the movement of motor 3 // Functions void Encoderinput() { int counts1; int counts2; int counts3; float angle1; float angle2; float angle3; counts1 = Encoder1.getPulses(); counts2 = Encoder2.getPulses(); counts3 = Encoder3.getPulses(); angle1 = ((float)counts1*2.0*pi)/4200.0; angle2 = ((float)counts2*2.0*pi)/4200.0; angle3 = ((float)counts3*2.0*pi)/4200.0; pc.printf("Counts1: %i Angle1: %f Counts2: %i Angle2: %f\r\n",counts1,angle1,counts2,angle2); } void draaibuttons() { /* Pressing button 2 concludes in a change of speed. While button 1 is pressed, the direction of change of speed is reversed. So pressing button 1 and 2 simultaneously results for the turning speed of motor 3 in a slower movement, and eventually the motor will turn the other way around. */ if (button1 == 1 && button2 == 1) { u3 = u3 + 0.1f; //In stapjes van 0.1 if (u3>1.0f) { u3 = 1.0f; } } else if (button1 == 0 && button2 == 1) { u3 = u3 - 0.1f; if (u3>1.0f) { u3 = 1.0f; } } void draai() /* Function for the movement of all motors, using the potmeters for the moving direction and speed of motor 1 and 2, and using button 1 and 2 on the biorobotics shield for the moving direction and speed of motor 3. */ { float u1 = 2.0*(pot1 - 0.5); // Normalised variable for the movement of motor 1 if (u1>0) { pin4 = true; } else if(u1<0) { pin4 = false; } pin5 = fabs(u1); float u2 = 2.0*(pot2 - 0.5); // Normalised variable for the movement of motor 2 if (u2<0) { pin7 = true; } else if(u2>0) { pin7 = false; } pin6 = fabs(u2); if (u3>0) { pin2 = true; } else if(u3<0) { pin2 = false; } else { pin3 = 0; } pin3 = fabs(u3); } // Main program int main() { pc.baud(115200); while (true) { Encoderinput(); } }