De hoofdcontroller van het TLS2 project.

Dependencies:   RPCInterface mbed

Files at this revision

API Documentation at this revision

Comitter:
RichardHoekstra
Date:
Fri Nov 18 22:01:22 2016 +0000
Parent:
5:846191af84ae
Child:
7:cb20720dbab9
Commit message:
Added the last commands for the motorcontroller. God, this function is ugly as sin.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Nov 17 18:25:06 2016 +0000
+++ b/main.cpp	Fri Nov 18 22:01:22 2016 +0000
@@ -2,7 +2,7 @@
 #include "mbed_rpc.h"
 #include "SerialRPCInterface.h"
 
-enum command_t{ //SENSORCONTROLLER COMMANDS
+enum command_t{ //MOTORCONTROLLER COMMANDS
                     SET_MODE = 1,
                     SET_CONSTANT_PRESSURE, 
                     SET_CONSTANT_FLOW, 
@@ -12,7 +12,7 @@
                     SET_FREQUENCY, 
                     RECEIVE_PRESSURE, 
                     RECEIVE_FLOW,
-                //MOTORCONTROLLER COMMANDS
+                //SENSORCONTROLLER COMMANDS
                     //Pressure sensor commands
                     SET_SENSOR_PRESSURE_1_SAMPLE_RATE = 13,
                     SET_SENSOR_PRESSURE_1_MVA,
@@ -66,18 +66,21 @@
     RPCVariable<int>  RPCtempsensor2_mva_elements(&tempsensor2_mva_elements, "tempsensor2_mva_elements");
     RPCVariable<int>  RPCflowsensor_mva_elements(&flowsensor_mva_elements, "flowsensor_mva_elements");
     //MOTORCONTROLLER - SETTINGS
-    /*
-    SET_MODE:
-    SET_CONSTANT_PRESSURE:
-    SET_CONSTANT_FLOW:
-    SET_CONSTANT_SPEED:
-    SET_MIN:
-    SET_MAX:
-    SET_FREQUENCY:
-    RECEIVE_PRESSURE:
-    RECEIVE_FLOW:
-    */
+    int motorcontroller_mode = 0,
+        motorcontroller_constant_pressure = 0,
+        motorcontroller_constant_flow = 0,
+        motorcontroller_constant_speed = 0,
+        motorcontroller_min = 0,
+        motorcontroller_max = 0,
+        motorcontroller_frequency = 0;
     
+    RPCVariable<int>  motorcontroller_mode(&motorcontroller_mode, "motorcontroller_mode");
+    RPCVariable<int>  motorcontroller_constant_pressure(&motorcontroller_constant_pressure, "motorcontroller_constant_pressure");
+    RPCVariable<int>  motorcontroller_constant_flow(&motorcontroller_constant_flow, "motorcontroller_constant_flow");
+    RPCVariable<int>  motorcontroller_constant_speed(&motorcontroller_constant_speed, "motorcontroller_constant_speed");
+    RPCVariable<int>  motorcontroller_min(&motorcontroller_min, "motorcontroller_min");
+    RPCVariable<int>  motorcontroller_max(&motorcontroller_max, "motorcontroller_max");
+    RPCVariable<int>  motorcontroller_frequency(&motorcontroller_frequency, "motorcontroller_frequency");   
     
 //UPDATE PERIODS
     float pressure1_update_period_s = 1;
@@ -232,11 +235,11 @@
         tick_flow.attach(&updateFlow,flow_update_period_s);  
         old_flow_update_period_s = flow_update_period_s;
     }
-        static int  old_druksensor1_mva_elements,
-                    old_druksensor2_mva_elements,
-                    old_tempsensor1_mva_elements,
-                    old_tempsensor2_mva_elements,
-                    old_flowsensor_mva_elements;
+    static int  old_druksensor1_mva_elements,
+                old_druksensor2_mva_elements,
+                old_tempsensor1_mva_elements,
+                old_tempsensor2_mva_elements,
+                old_flowsensor_mva_elements;
     //If LabView has changed variables for the motor or sensor settings
     //then send an update over I2C
     if(old_druksensor1_mva_elements != druksensor1_mva_elements){
@@ -274,6 +277,64 @@
         i2c.write(sensor_addr, buffer, 3);
         old_flowsensor_mva_elements = flowsensor_mva_elements;
     }
+    
+    //Motorcontroller
+    static int  old_motorcontroller_mode = 0,
+                old_motorcontroller_constant_pressure = 0,
+                old_motorcontroller_constant_flow = 0,
+                old_motorcontroller_constant_speed = 0,
+                old_motorcontroller_min = 0,
+                old_motorcontroller_max = 0,
+                old_motorcontroller_frequency = 0;
+    if(old_motorcontroller_mode != motorcontroller_mode){
+        char buffer[3] = {0};
+        buffer[0] = SET_MODE;
+        int_to_2char(buffer, motorcontroller_mode, 1);
+        i2c.write(motor_addr, buffer, 3);
+        old_motorcontroller_mode = motorcontroller_mode;
+    }
+    if(old_motorcontroller_constant_pressure != motorcontroller_constant_pressure){
+        char buffer[3] = {0};
+        buffer[0] = SET_CONSTANT_PRESSURE;
+        int_to_2char(buffer, motorcontroller_constant_pressure, 1);
+        i2c.write(motor_addr, buffer, 3);
+        old_motorcontroller_constant_pressure = motorcontroller_mode;
+    }
+    if(old_motorcontroller_constant_flow != motorcontroller_constant_flow){
+        char buffer[3] = {0};
+        buffer[0] = SET_CONSTANT_FLOW;
+        int_to_2char(buffer, motorcontroller_constant_flow, 1);
+        i2c.write(motor_addr, buffer, 3);
+        old_motorcontroller_constant_flow = motorcontroller_constant_flow;
+    }
+    if(old_motorcontroller_constant_speed != motorcontroller_constant_speed){
+        char buffer[3] = {0};
+        buffer[0] = SET_CONSTANT_SPEED;
+        int_to_2char(buffer, motorcontroller_constant_speed, 1);
+        i2c.write(motor_addr, buffer, 3);
+        old_motorcontroller_constant_speed = old_motorcontroller_constant_speed;
+    }
+    if(old_motorcontroller_min != motorcontroller_min){
+        char buffer[3] = {0};
+        buffer[0] = SET_MIN;
+        int_to_2char(buffer, motorcontroller_min, 1);
+        i2c.write(motor_addr, buffer, 3);
+        old_motorcontroller_min = motorcontroller_min;
+    }
+    if(old_motorcontroller_max != motorcontroller_max){
+        char buffer[3] = {0};
+        buffer[0] = SET_MAX;
+        int_to_2char(buffer, motorcontroller_max, 1);
+        i2c.write(motor_addr, buffer, 3);
+        old_motorcontroller_max = motorcontroller_max;
+    }
+    if(old_motorcontroller_frequency != motorcontroller_frequency){
+        char buffer[3] = {0};
+        buffer[0] = SET_FREQUENCY;
+        int_to_2char(buffer, motorcontroller_frequency, 1);
+        i2c.write(motor_addr, buffer, 3);
+        old_motorcontroller_frequency = motorcontroller_frequency;
+    }                         
 }
 
 int main() {