Alles in 1

Dependencies:   Encoder HIDScope MODSERIAL QEI mbed

Fork of RoboBird3 by Fernon Eijkhoudt

main.cpp

Committer:
Fernon
Date:
2015-09-28
Revision:
5:d47e6a96256b
Parent:
4:de94e1135968
Child:
6:cf20f04dbab4

File content as of revision 5:d47e6a96256b:

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

DigitalOut Direction(D4); //1 = CCW - 0 = CW
PwmOut PowerMotor(D5); //van 0 tot 1
AnalogIn PotMeter(A1);
QEI Encoder(D13,D12,NC,32,QEI::X2_ENCODING); //Encoder
Serial pc(USBTX, USBRX);
Ticker Pot;
Ticker PC;

double z;
const double twopi = 6.2831853071795;
const double pi = pi/2;
int Pulses;
double Rotatie;
double Rotatietwopi;

void readpot()
{
    z = PotMeter.read()/10;
}

void print()
{
    pc.printf ("Potmeter = %f\n", z); // het weergeven van de waarde waar z (PotMeter) op dat moment is
    pc.printf ("Rotatie = %f [pi radialen] \n", Rotatietwopi);
}

int main()
{
    pc.baud(115200);
    PowerMotor.write(0);
    Pot.attach(readpot,0.001); // Deze ticker moet de waarde uitlezen van de PotMeter 10 keer per seconde
    PC.attach(print,0.5);
    while (true) {
        PowerMotor.write(z);
        Pulses = Encoder.getPulses();
        Rotatie = (Pulses*twopi)/4192;
        Rotatietwopi = fmod(Rotatie,twopi);
    }
}