Biorobotics / Mbed 2 deprecated Motor_moving_setpoint

Dependencies:   QEI mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "QEI.h"
00003 
00004 Serial pc(USBTX, USBRX);
00005 QEI wheel (PTC10, PTC11, NC, 624); // Pin for counting (analog in)
00006 
00007 // Define pin for motor control
00008 DigitalOut directionPin(D4);
00009 PwmOut PWM(D5);
00010 
00011 
00012 
00013 // 8400 counts per revolution
00014 // so 8400 / (2 *pi) is counts/pi
00015 
00016 
00017 Ticker tellen;
00018 
00019 volatile bool stoppen = false;
00020 
00021 void GOTO()
00022 {
00023 double Offset = 10341 ;//8400 counts is aangegeven op de motor ( is te weinig) 10511 schiet iets over
00024 double resolution = Offset / (2 * 3.14159265);
00025 double Rotation = 4; // rotation in pi
00026 double movement = Rotation * resolution;
00027    
00028            //  pc.printf("The number of real rotation is %i \n",Rotation);
00029     
00030 
00031         if (wheel.getPulses() <= movement) {
00032             directionPin.write(1);
00033             PWM.write(0.3);
00034             pc.printf("Pulses is: %i\n", wheel.getPulses());
00035         } else {
00036             PWM.write(0);
00037             //pc.printf("The motor turned %i rotations \n",Rotation);
00038             pc.printf("Pulses is: %i\n The motor turned %.2f  pi rotations\n", wheel.getPulses(),wheel.getPulses()/resolution);
00039             stoppen = true;
00040         
00041 
00042     }
00043                    
00044          
00045     
00046 
00047 }
00048 
00049 
00050 
00051 int main()
00052 
00053 {
00054    int proberenn = 1000;
00055        pc.printf("The number of rotation is %i \n",proberenn);
00056        
00057       while(1){
00058     if(stoppen == false){ // doet eerst de while loop en dan begint hij met de ticker
00059             tellen.attach(&GOTO, 0.1); 
00060               pc.printf("dit is if \n");
00061         stoppen = true;
00062             } else
00063             {
00064        
00065            pc.printf("wees geen bitch \n");
00066            
00067            }
00068            
00069          }
00070 }
00071 
00072           
00073    
00074    
00075                 
00076 
00077         
00078     
00079        
00080 
00081