Basis aansturing projectgroep 3

Dependencies:   Biquad HIDScope MODSERIAL QEI mbed

Committer:
s1588141
Date:
Mon Oct 03 13:39:28 2016 +0000
Revision:
1:d8bb72c9c019
Parent:
0:a2db8cc5d5df
Child:
2:0954eb04bb4c
Ineens heel hard draaien;

Who changed what in which revision?

UserRevisionLine numberNew 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 1:d8bb72c9c019 23 InterruptIn OnOff(SW3); //Motor On/off
s1588141 1:d8bb72c9c019 24
s1588141 1:d8bb72c9c019 25 //------------------Ticker------------------------------------
s1588141 1:d8bb72c9c019 26 Ticker Measure;
s1588141 0:a2db8cc5d5df 27 //------------------------------------------------------------
s1588141 0:a2db8cc5d5df 28 //--------------------All Motors----------------------------
s1588141 0:a2db8cc5d5df 29 //------------------------------------------------------------
s1588141 0:a2db8cc5d5df 30
s1588141 0:a2db8cc5d5df 31 //-------------------- Motor Links----------------------------
s1588141 0:a2db8cc5d5df 32 DigitalOut M_L_D(D4); //Richting motor links
s1588141 0:a2db8cc5d5df 33 PwmOut M_L_S(D5); //Snelheid motor links
s1588141 0:a2db8cc5d5df 34 DigitalOut M_R_D(D7); //Richting motor Rechts
s1588141 0:a2db8cc5d5df 35 PwmOut M_R_S(D6); //Snelheid motor Rechts
s1588141 0:a2db8cc5d5df 36
s1588141 0:a2db8cc5d5df 37 //--------------------------------------------------------------
s1588141 0:a2db8cc5d5df 38 //-----------------------Functions------------------------------
s1588141 0:a2db8cc5d5df 39 //--------------------------------------------------------------
s1588141 0:a2db8cc5d5df 40
s1588141 0:a2db8cc5d5df 41 //-----------------------Interrupts-----------------------------
s1588141 0:a2db8cc5d5df 42 volatile int Motor_Frequency = 1000;
s1588141 1:d8bb72c9c019 43 volatile bool Active = false;
s1588141 0:a2db8cc5d5df 44 void Boot(){
s1588141 0:a2db8cc5d5df 45
s1588141 0:a2db8cc5d5df 46 M_L_S.period(1.0/Motor_Frequency);
s1588141 0:a2db8cc5d5df 47 M_L_D = 1;
s1588141 0:a2db8cc5d5df 48 M_L_S = 0.0;
s1588141 0:a2db8cc5d5df 49 M_R_S.period(1.0/Motor_Frequency);
s1588141 0:a2db8cc5d5df 50 M_R_D = 0;
s1588141 0:a2db8cc5d5df 51 M_R_S= 0.0;
s1588141 0:a2db8cc5d5df 52 }
s1588141 0:a2db8cc5d5df 53 void Switch_Dirr_L(){ // Switching dirrection left motor (Every motor starts in clockwise dirrection)
s1588141 0:a2db8cc5d5df 54 M_L_D = !M_L_D;
s1588141 0:a2db8cc5d5df 55 }
s1588141 0:a2db8cc5d5df 56
s1588141 0:a2db8cc5d5df 57 void Switch_Dirr_R(){ // Switching dirrection Right motor
s1588141 0:a2db8cc5d5df 58 M_R_D = !M_R_D;
s1588141 0:a2db8cc5d5df 59 }
s1588141 1:d8bb72c9c019 60 void De_Activate(){
s1588141 1:d8bb72c9c019 61 Active = !Active;
s1588141 1:d8bb72c9c019 62 }
s1588141 1:d8bb72c9c019 63
s1588141 1:d8bb72c9c019 64 void Information(){
s1588141 1:d8bb72c9c019 65 pc.printf("test");
s1588141 1:d8bb72c9c019 66 }
s1588141 0:a2db8cc5d5df 67
s1588141 0:a2db8cc5d5df 68 int main()
s1588141 0:a2db8cc5d5df 69 {
s1588141 0:a2db8cc5d5df 70 //---------------------Setting constants and system booting--------------------
s1588141 0:a2db8cc5d5df 71 pc.baud(115200);
s1588141 0:a2db8cc5d5df 72 pc.printf("\r\n**BOARD RESET**\r\n");
s1588141 0:a2db8cc5d5df 73 Boot();
s1588141 0:a2db8cc5d5df 74
s1588141 0:a2db8cc5d5df 75 Dir_L.fall(Switch_Dirr_L);
s1588141 0:a2db8cc5d5df 76 Dir_R.fall(Switch_Dirr_R);
s1588141 1:d8bb72c9c019 77 OnOff.fall(De_Activate);
s1588141 0:a2db8cc5d5df 78
s1588141 0:a2db8cc5d5df 79 while (true) {
s1588141 0:a2db8cc5d5df 80 // control= pc.getc();
s1588141 1:d8bb72c9c019 81 if (Active == true){
s1588141 1:d8bb72c9c019 82 M_L_S = P_M_L.read()/5.0+0.1;
s1588141 1:d8bb72c9c019 83 M_R_S = P_M_R.read()/5.0+0.1;
s1588141 1:d8bb72c9c019 84 } else {
s1588141 1:d8bb72c9c019 85 if(Active == false){
s1588141 1:d8bb72c9c019 86 M_L_S = 0;
s1588141 1:d8bb72c9c019 87 M_R_S = 0;
s1588141 1:d8bb72c9c019 88 }
s1588141 1:d8bb72c9c019 89 }
s1588141 1:d8bb72c9c019 90 Measure.attach(Information, 2.0);
s1588141 0:a2db8cc5d5df 91 //wait(1.0f);
s1588141 1:d8bb72c9c019 92
s1588141 0:a2db8cc5d5df 93 }
s1588141 0:a2db8cc5d5df 94 }