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

Dependencies:   mbed QEI

Revision:
0:839ba4bb1be1
Child:
2:439a3a118526
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Sep 20 14:19:06 2010 +0000
@@ -0,0 +1,36 @@
+#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);
+    }
+}
\ No newline at end of file