Biorobotics / Mbed 2 deprecated Motor_moving_setpoint

Dependencies:   QEI mbed

main.cpp

Committer:
yohoo15
Date:
2015-09-28
Revision:
0:70a6fd5751a6
Child:
1:c855dee2c6d4

File content as of revision 0:70a6fd5751a6:

#include "mbed.h"
#include "QEI.h"

Serial pc(USBTX, USBRX);
QEI wheel (PTC10, PTC11, NC, 624); // Pin for counting (analog in)

// Define pin for motor control
DigitalOut directionPin(D4);
PwmOut PWM(D5);



// 8400 counts per revolution
// so 8400 / (2 *pi) is counts/pi


Ticker tellen;
bool stoppen = false;

void GOTO()
{
double resolution = 8400 / (2 * 3.14592);
double Rotation = 4; // rotation in pi
double movement = Rotation * resolution;
   
           //  pc.printf("The number of real rotation is %i \n",Rotation);
    

        if (wheel.getPulses() <= movement) {
            directionPin.write(1);
            PWM.write(0.3);
            pc.printf("Pulses is: %i\n", wheel.getPulses());
        } else {
            PWM.write(0);
            //pc.printf("The motor turned %i rotations \n",Rotation);
            pc.printf("Pulses is: %i\n The motor turned %.2f rotations\n", wheel.getPulses(),Rotation);
            stoppen = true;
        

    }
                   
         
    

}



int main()
{
   int proberen = 1000;
       pc.printf("The number of rotation is %i \n",proberen);
   
       
   
   
    
           tellen.attach(&GOTO, 0.1); 
           
           
          
                

        
    
       

}