De hoofdcontroller van het TLS2 project.

Dependencies:   RPCInterface mbed

Files at this revision

API Documentation at this revision

Comitter:
RichardHoekstra
Date:
Sun Nov 13 22:25:48 2016 +0000
Parent:
0:bb1b87ed61e6
Child:
2:c3918fd40472
Commit message:
Mbed <-> Laptop werkt in deze versie. TODO is aangepast. ; Volgende stap is I2C werkend krijgen voordat Mbed <-> Laptop variabelen verder worden uitgewerkt.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Nov 08 18:47:10 2016 +0000
+++ b/main.cpp	Sun Nov 13 22:25:48 2016 +0000
@@ -1,24 +1,80 @@
 #include "mbed.h"
+#include "mbed_rpc.h"
 #include "SerialRPCInterface.h"
- 
- 
- 
-//Mbed <-> LabView protocol werkt over USB
-//Zie: https://developer.mbed.org/cookbook/Interfacing-with-LabVIEW
-//We gaan vooral gebruik maken van het RPC voorbeeld. Wordt super tof
-//Zie: https://developer.mbed.org/cookbook/Interfacing-Using-RPC voor RPC    
+//Example
+//RPCVariable<float>  RPCbrightness(&brightness, "brightness");
+
+//Hoofdcontroller TODO:
+//1. Switch tussen drukgestuurd en flowgestuurd
+//2. Ondersteuning voor meerdere druksensors en temperatuur sensors
+//3. Opvragen van recente sensor data voor het LabView gebruikersinterface
+//4. I2C communicatie met andere controllers
+
+
+//All the settings for the motor controller
+int curveMode = 0;      //curveMode 0: constant 
+                        //curveMode 1: sinusoid 
+                        //curveMode 2: arterial
+float control_frequency = 100;  //Hz The frequency at which the PID scheme is executing
+float curve_frequency = 1;      //Hz The frequency of the curve/pulse
+float min_val = 80;           //mmHg or mL/h
+float max_val = 120;          //mmHg or mL/h
+RPCVariable<int>    RPCcurveMode(&curveMode, "curveMode");
+RPCVariable<float>  RPCcontrol_frequency(&control_frequency, "control_frequency");
+RPCVariable<float>  RPCcurve_frequency(&curve_frequency, "curve_frequency");
+RPCVariable<float>  RPCmin_val(&min_val, "min_val");
+RPCVariable<float>  RPCmax_val(&max_val, "max_val");
+
+//All the variables for the sensor controller
+float sensor_pressure_frequency = 100; //Hz
+float sensor_flow_frequency = 10; //Hz
+RPCVariable<float> RPCsensor_pressure_frequency(&sensor_pressure_frequency, "sensor_pressure_frequency");
+RPCVariable<float> RPCsensor_flow_frequency(&sensor_flow_frequency, "sensor_flow_frequency");
+
+
+
+
+
+Serial pc(USBTX, USBRX);
 
-PwmOut led(LED1);
-float ledDutyCycle = 0;
-RPCVariable<float> RPCMotorOut(&ledDutyCycle, "ledDutyCycle");
+//Handles all the RPC communication. 
+//Taken from the example at developer.mbed.org/cookbook
+void RPC(){
+    static char buf[256], outbuf[256];
+    pc.gets(buf, 256);
+    //Call the static call method on the RPC class
+    RPC::call(buf, outbuf); 
+    pc.printf("%s\n", outbuf);
+}
 
-//DIT IS EEN DEMO
-int main()
-{
-    led.period_ms(1);//1000Hz
-    while(true){
-        led = ledDutyCycle;
-        wait_ms(10);
-    }   
+//Only sends an I2C command if settings have changed.
+void sendUpdate(){
+    static int      prev_curveMode = 0;
+    static float    prev_frequency = 0,
+                    prev_min_press = 0,
+                    prev_max_press = 0;
+    if(curveMode != prev_curveMode){
+        prev_curveMode = curveMode;
+        //TODO: Send I2C command to Motor Controller
+        //i2c(motorController_address,curveMode)    
+    }
+    if(frequency != prev_frequency){
+        prev_frequency = frequency;
+        //TODO: Send I2C command to Motor Controller    
+    }
+    if(min_press != prev_min_press){
+        prev_min_press = min_press;
+        //TODO: Send I2C command to Motor Controller    
+    }
+    if(max_press != prev_max_press){
+        prev_max_press = max_press;
+        //TODO: Send I2C command to Motor Controller    
+    }
 }
- 
+int main() {    
+    while(1) {
+        RPC();
+        sendUpdate();
+        wait_ms(1);
+    }
+}
\ No newline at end of file