Control up to two motors using filtered EMG signals and a PID controller

Dependencies:   FastPWM HIDScope MODSERIAL QEI Matrix biquadFilter controller errorFetch mbed motorConfig refGen MatrixMath inverseKinematics

Fork of Minor_test_serial by First Last

main.cpp

Committer:
tvlogman
Date:
2017-09-19
Revision:
9:5f0e796c9489
Parent:
8:0067469c3389
Child:
10:e23cbcdde7e3

File content as of revision 9:5f0e796c9489:

#include "mbed.h"
#include "MODSERIAL.h"
#include "HIDScope.h"
#include "QEI.h"

HIDScope scope(2);

Ticker AInTicker;
AnalogIn button1(A4);

volatile float x;
volatile float x_prev =0; 
volatile float y; // filtered 'output' of ReadAnalogInAndFilter 
volatile float ledBrightness = 0.00;

void ReadAnalogInAndFilter()
{
        x = button1;   // Capture data
        scope.set(0, x);   // store data in first element of scope memory
        y = (x_prev + x)/2.0;   // averaging filter
        scope.set(1, y);  // store data in second element of scope memory
        x_prev = x; // Prepare for next round
    
        scope.send(); // send what's in scope memory to PC
}

PwmOut ledPwm(D5);
float pwmPeriod = 1.0/5000.0;

AnalogIn pot(A5);

DigitalIn button2(D6);


MODSERIAL pc(USBTX, USBRX);


int main()
{
    
    pc.baud(115200);
    AInTicker.attach(&ReadAnalogInAndFilter, 0.01);
    ledPwm.period(pwmPeriod);
    pc.printf("Hello world");
    int counts;

    QEI Encoder(D12,D13,NC,32);
    
    while (true) {
        counts = Encoder.getPulses();
        pc.printf("Number of pulses is %i", counts);
        wait(0.5);
        
    }
    
}