Basis aansturing projectgroep 3
Dependencies: Biquad HIDScope MODSERIAL QEI mbed
main.cpp@0:a2db8cc5d5df, 2016-10-03 (annotated)
- Committer:
- s1588141
- Date:
- Mon Oct 03 13:14:39 2016 +0000
- Revision:
- 0:a2db8cc5d5df
- Child:
- 1:d8bb72c9c019
Eerste aansturing;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
s1588141 | 0:a2db8cc5d5df | 1 | #include "mbed.h" |
s1588141 | 0:a2db8cc5d5df | 2 | #include "MODSERIAL.h" |
s1588141 | 0:a2db8cc5d5df | 3 | #include "QEI.h" |
s1588141 | 0:a2db8cc5d5df | 4 | |
s1588141 | 0:a2db8cc5d5df | 5 | MODSERIAL pc(USBTX, USBRX); |
s1588141 | 0:a2db8cc5d5df | 6 | /////////////////////////// |
s1588141 | 0:a2db8cc5d5df | 7 | // Hardware initialiseren// |
s1588141 | 0:a2db8cc5d5df | 8 | /////////////////////////// |
s1588141 | 0:a2db8cc5d5df | 9 | //------------------------------------------------------------ |
s1588141 | 0:a2db8cc5d5df | 10 | //--------------------All sensors--------------------------- |
s1588141 | 0:a2db8cc5d5df | 11 | //------------------------------------------------------------ |
s1588141 | 0:a2db8cc5d5df | 12 | |
s1588141 | 0:a2db8cc5d5df | 13 | //--------------------Analog--------------------------------- |
s1588141 | 0:a2db8cc5d5df | 14 | AnalogIn P_M_L(A0); //Motorspeed Left |
s1588141 | 0:a2db8cc5d5df | 15 | AnalogIn P_M_R(A1); //MotorSpeed Right |
s1588141 | 0:a2db8cc5d5df | 16 | |
s1588141 | 0:a2db8cc5d5df | 17 | //-------------------Digital---------------------------------- |
s1588141 | 0:a2db8cc5d5df | 18 | |
s1588141 | 0:a2db8cc5d5df | 19 | |
s1588141 | 0:a2db8cc5d5df | 20 | //-------------------Interrupts------------------------------- |
s1588141 | 0:a2db8cc5d5df | 21 | InterruptIn Dir_L(D0); //Motor Dirrection left |
s1588141 | 0:a2db8cc5d5df | 22 | InterruptIn Dir_R(D1); //Motor Dirrection Right |
s1588141 | 0:a2db8cc5d5df | 23 | //------------------------------------------------------------ |
s1588141 | 0:a2db8cc5d5df | 24 | //--------------------All Motors---------------------------- |
s1588141 | 0:a2db8cc5d5df | 25 | //------------------------------------------------------------ |
s1588141 | 0:a2db8cc5d5df | 26 | |
s1588141 | 0:a2db8cc5d5df | 27 | //-------------------- Motor Links---------------------------- |
s1588141 | 0:a2db8cc5d5df | 28 | DigitalOut M_L_D(D4); //Richting motor links |
s1588141 | 0:a2db8cc5d5df | 29 | PwmOut M_L_S(D5); //Snelheid motor links |
s1588141 | 0:a2db8cc5d5df | 30 | DigitalOut M_R_D(D7); //Richting motor Rechts |
s1588141 | 0:a2db8cc5d5df | 31 | PwmOut M_R_S(D6); //Snelheid motor Rechts |
s1588141 | 0:a2db8cc5d5df | 32 | |
s1588141 | 0:a2db8cc5d5df | 33 | //-------------------------------------------------------------- |
s1588141 | 0:a2db8cc5d5df | 34 | //-----------------------Functions------------------------------ |
s1588141 | 0:a2db8cc5d5df | 35 | //-------------------------------------------------------------- |
s1588141 | 0:a2db8cc5d5df | 36 | |
s1588141 | 0:a2db8cc5d5df | 37 | //-----------------------Interrupts----------------------------- |
s1588141 | 0:a2db8cc5d5df | 38 | volatile int Motor_Frequency = 1000; |
s1588141 | 0:a2db8cc5d5df | 39 | void Boot(){ |
s1588141 | 0:a2db8cc5d5df | 40 | |
s1588141 | 0:a2db8cc5d5df | 41 | M_L_S.period(1.0/Motor_Frequency); |
s1588141 | 0:a2db8cc5d5df | 42 | M_L_D = 1; |
s1588141 | 0:a2db8cc5d5df | 43 | M_L_S = 0.0; |
s1588141 | 0:a2db8cc5d5df | 44 | M_R_S.period(1.0/Motor_Frequency); |
s1588141 | 0:a2db8cc5d5df | 45 | M_R_D = 0; |
s1588141 | 0:a2db8cc5d5df | 46 | M_R_S= 0.0; |
s1588141 | 0:a2db8cc5d5df | 47 | } |
s1588141 | 0:a2db8cc5d5df | 48 | void Switch_Dirr_L(){ // Switching dirrection left motor (Every motor starts in clockwise dirrection) |
s1588141 | 0:a2db8cc5d5df | 49 | M_L_D = !M_L_D; |
s1588141 | 0:a2db8cc5d5df | 50 | } |
s1588141 | 0:a2db8cc5d5df | 51 | |
s1588141 | 0:a2db8cc5d5df | 52 | void Switch_Dirr_R(){ // Switching dirrection Right motor |
s1588141 | 0:a2db8cc5d5df | 53 | M_R_D = !M_R_D; |
s1588141 | 0:a2db8cc5d5df | 54 | } |
s1588141 | 0:a2db8cc5d5df | 55 | |
s1588141 | 0:a2db8cc5d5df | 56 | int main() |
s1588141 | 0:a2db8cc5d5df | 57 | { |
s1588141 | 0:a2db8cc5d5df | 58 | //---------------------Setting constants and system booting-------------------- |
s1588141 | 0:a2db8cc5d5df | 59 | pc.baud(115200); |
s1588141 | 0:a2db8cc5d5df | 60 | pc.printf("\r\n**BOARD RESET**\r\n"); |
s1588141 | 0:a2db8cc5d5df | 61 | Boot(); |
s1588141 | 0:a2db8cc5d5df | 62 | |
s1588141 | 0:a2db8cc5d5df | 63 | Dir_L.fall(Switch_Dirr_L); |
s1588141 | 0:a2db8cc5d5df | 64 | Dir_R.fall(Switch_Dirr_R); |
s1588141 | 0:a2db8cc5d5df | 65 | |
s1588141 | 0:a2db8cc5d5df | 66 | while (true) { |
s1588141 | 0:a2db8cc5d5df | 67 | // control= pc.getc(); |
s1588141 | 0:a2db8cc5d5df | 68 | M_L_S = P_M_L.read()/5.0+0.1; |
s1588141 | 0:a2db8cc5d5df | 69 | M_R_S = P_M_R.read()/5.0+0.1; |
s1588141 | 0:a2db8cc5d5df | 70 | //wait(1.0f); |
s1588141 | 0:a2db8cc5d5df | 71 | pc.printf("%f",M_L_S); |
s1588141 | 0:a2db8cc5d5df | 72 | } |
s1588141 | 0:a2db8cc5d5df | 73 | } |