Basis aansturing projectgroep 3
Dependencies: Biquad HIDScope MODSERIAL QEI mbed
main.cpp
- Committer:
- s1588141
- Date:
- 2016-10-03
- Revision:
- 1:d8bb72c9c019
- Parent:
- 0:a2db8cc5d5df
- Child:
- 2:0954eb04bb4c
File content as of revision 1:d8bb72c9c019:
#include "mbed.h" #include "MODSERIAL.h" #include "QEI.h" MODSERIAL pc(USBTX, USBRX); /////////////////////////// // Hardware initialiseren// /////////////////////////// //------------------------------------------------------------ //--------------------All sensors--------------------------- //------------------------------------------------------------ //--------------------Analog--------------------------------- AnalogIn P_M_L(A0); //Motorspeed Left AnalogIn P_M_R(A1); //MotorSpeed Right //-------------------Digital---------------------------------- //-------------------Interrupts------------------------------- InterruptIn Dir_L(D0); //Motor Dirrection left InterruptIn Dir_R(D1); //Motor Dirrection Right InterruptIn OnOff(SW3); //Motor On/off //------------------Ticker------------------------------------ Ticker Measure; //------------------------------------------------------------ //--------------------All Motors---------------------------- //------------------------------------------------------------ //-------------------- Motor Links---------------------------- DigitalOut M_L_D(D4); //Richting motor links PwmOut M_L_S(D5); //Snelheid motor links DigitalOut M_R_D(D7); //Richting motor Rechts PwmOut M_R_S(D6); //Snelheid motor Rechts //-------------------------------------------------------------- //-----------------------Functions------------------------------ //-------------------------------------------------------------- //-----------------------Interrupts----------------------------- volatile int Motor_Frequency = 1000; volatile bool Active = false; void Boot(){ M_L_S.period(1.0/Motor_Frequency); M_L_D = 1; M_L_S = 0.0; M_R_S.period(1.0/Motor_Frequency); M_R_D = 0; M_R_S= 0.0; } void Switch_Dirr_L(){ // Switching dirrection left motor (Every motor starts in clockwise dirrection) M_L_D = !M_L_D; } void Switch_Dirr_R(){ // Switching dirrection Right motor M_R_D = !M_R_D; } void De_Activate(){ Active = !Active; } void Information(){ pc.printf("test"); } int main() { //---------------------Setting constants and system booting-------------------- pc.baud(115200); pc.printf("\r\n**BOARD RESET**\r\n"); Boot(); Dir_L.fall(Switch_Dirr_L); Dir_R.fall(Switch_Dirr_R); OnOff.fall(De_Activate); while (true) { // control= pc.getc(); if (Active == true){ M_L_S = P_M_L.read()/5.0+0.1; M_R_S = P_M_R.read()/5.0+0.1; } else { if(Active == false){ M_L_S = 0; M_R_S = 0; } } Measure.attach(Information, 2.0); //wait(1.0f); } }