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

Dependencies:   mbed QEI

Committer:
MichaelW
Date:
Tue Sep 21 16:00:43 2010 +0000
Revision:
2:439a3a118526
Parent:
0:839ba4bb1be1

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MichaelW 2:439a3a118526 1 /**
MichaelW 2:439a3a118526 2 * Copyright (c)2010 ARM Ltd.
MichaelW 2:439a3a118526 3 * Released under the MIT License: http://mbed.org/license/mit
MichaelW 2:439a3a118526 4 */
MichaelW 2:439a3a118526 5
MichaelW 0:839ba4bb1be1 6 #include "mbed.h"
MichaelW 0:839ba4bb1be1 7 #include "QEI.h"
MichaelW 0:839ba4bb1be1 8 #include "Motor.h"
MichaelW 0:839ba4bb1be1 9 #include "SerialRPCInterface.h"
MichaelW 0:839ba4bb1be1 10
MichaelW 0:839ba4bb1be1 11 //Create the interface on the USB Serial Port
MichaelW 0:839ba4bb1be1 12 SerialRPCInterface SerialInterface(USBTX, USBRX);
MichaelW 0:839ba4bb1be1 13
MichaelW 0:839ba4bb1be1 14 QEI Encoder(p29 ,p30, NC, 48);
MichaelW 0:839ba4bb1be1 15 Motor Wheel(p23, p21, p22);
MichaelW 0:839ba4bb1be1 16
MichaelW 0:839ba4bb1be1 17 //Create float variables
MichaelW 0:839ba4bb1be1 18 float MotorOutput = 50;
MichaelW 0:839ba4bb1be1 19 float Percentage = 0;
MichaelW 0:839ba4bb1be1 20
MichaelW 0:839ba4bb1be1 21 //Make these variables accessible over RPC by attaching them to an RPCVariable
MichaelW 0:839ba4bb1be1 22 RPCVariable<float> RPCMotorOut(&MotorOutput, "MotorOutput");
MichaelW 0:839ba4bb1be1 23 RPCVariable<float> RPCPercentage(&Percentage, "Percentage");
MichaelW 0:839ba4bb1be1 24
MichaelW 0:839ba4bb1be1 25 int main(){
MichaelW 0:839ba4bb1be1 26
MichaelW 0:839ba4bb1be1 27 Encoder.reset();
MichaelW 0:839ba4bb1be1 28 float NoPulses;
MichaelW 0:839ba4bb1be1 29
MichaelW 0:839ba4bb1be1 30 while(1){
MichaelW 2:439a3a118526 31 NoPulses = Encoder.getPulses();
MichaelW 0:839ba4bb1be1 32 Percentage = ((NoPulses / 48) * 100);
MichaelW 2:439a3a118526 33 //RPC will be used to set the value of MotorOutput.
MichaelW 0:839ba4bb1be1 34 Wheel.speed((MotorOutput - 50) * 2 / 100);
MichaelW 0:839ba4bb1be1 35 wait(0.005);
MichaelW 0:839ba4bb1be1 36 }
MichaelW 0:839ba4bb1be1 37 }