Demonstration of RPCVariables to implement closed loop control in LabVIEW of a motor using a QEI for feedback

Dependencies:   mbed QEI

main.cpp

Committer:
MichaelW
Date:
2010-09-20
Revision:
0:839ba4bb1be1
Child:
2:439a3a118526

File content as of revision 0:839ba4bb1be1:

#include "mbed.h"
#include "QEI.h"
#include "Motor.h"
#include "SerialRPCInterface.h"

//Create the interface on the USB Serial Port
SerialRPCInterface SerialInterface(USBTX, USBRX);

QEI Encoder(p29 ,p30, NC, 48);
Motor Wheel(p23, p21, p22);

//Create float variables
float MotorOutput = 50;
float Percentage = 0;

//Make these variables accessible over RPC by attaching them to an RPCVariable
RPCVariable<float> RPCMotorOut(&MotorOutput, "MotorOutput");
RPCVariable<float> RPCPercentage(&Percentage, "Percentage");

int main(){

    Encoder.reset();
    float NoPulses;
    
    while(1){ 
        //This code writes the value of MotorOutput to the Motor and reads the number of pulses into the percentage.
        
        NoPulses = Encoder.getPulses();
        Percentage = ((NoPulses / 48) * 100);
       
        //RPC will be used to set the value of MotorOut.
        Wheel.speed((MotorOutput - 50) * 2 / 100);
        
        wait(0.005);
    }
}