Vorlage für Projekt

Dependencies:   CD4052 COUNTER RC_PWM Telemetrie_eth_h2m1 mbed

Files at this revision

API Documentation at this revision

Comitter:
HMFK03LST1
Date:
Thu Nov 09 13:46:46 2017 +0000
Child:
1:8466c8592a5e
Commit message:
Projektarbeit Schubmesstand 2017

Changed in this revision

CD4052.lib Show annotated file Show diff for this revision Revisions of this file
COUNTER.lib Show annotated file Show diff for this revision Revisions of this file
RC_PWM.lib Show annotated file Show diff for this revision Revisions of this file
Telemetrie_eth_h2m.lib Show annotated file Show diff for this revision Revisions of this file
components.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CD4052.lib	Thu Nov 09 13:46:46 2017 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/HMFK03LST1/code/CD4052/#2fd218b3f449
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/COUNTER.lib	Thu Nov 09 13:46:46 2017 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/HMFK03LST1/code/COUNTER/#356385f2d5c9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RC_PWM.lib	Thu Nov 09 13:46:46 2017 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/HMFK03LST1/code/RC_PWM/#608a9f61c2d7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Telemetrie_eth_h2m.lib	Thu Nov 09 13:46:46 2017 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/HMFK03LST1/code/Telemetrie_eth_h2m/#afa11d0640bb
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/components.h	Thu Nov 09 13:46:46 2017 +0000
@@ -0,0 +1,117 @@
+#include "stdio.h"
+
+struct struct_system
+{
+    uint8_t  length              ;//1
+    uint8_t  ID                  ;//2
+    uint8_t  do_time     : 1     ;//3.0
+    uint8_t  do_measure  : 1     ;//3.1
+    uint8_t  C_limit     : 1     ;//3.2
+    uint8_t  RPM_limit   : 1     ;//3.3
+    uint8_t  T_limit     : 1     ;//3.4
+    uint8_t  run         : 1     ;//3.5
+    uint8_t  flag7       : 1     ;//3.6
+    uint8_t  flag8       : 1     ;//3.7
+    uint8_t  blade               ;//4
+    uint16_t Amax                ;//6    
+    uint16_t RPMmax              ;//8
+    uint16_t PWMmax              ;//10 @rule: name=Max.PWM; expr=1200+PWMmax*3; unit=us
+    uint16_t PWMmin              ;//12 @rule: name=Min.PWM; expr=900+PWMmin*2; unit=us
+    uint16_t air_ro              ;//14 @rule: name=Air Density; expr=air_ro/10000; unit=kg/m³
+    uint8_t  t_eng_max           ;//15 @rule: name=Max. Eng. Temp; expr=t_max; unit=C    
+    uint8_t  fast                ;//16
+    uint8_t  slow                ;//17
+    uint8_t  measure             ;//18
+    uint8_t  pwm                 ;//19
+    uint8_t  version             ;//20
+    float    open7               ;//24
+    uint8_t  ck                  ;//25
+} sys = {25,0};
+
+struct struct_value        
+{
+    uint8_t  length              ;//1
+    uint8_t  ID                  ;//2
+    uint8_t  flag1               ;//3
+    uint8_t  flag2               ;//4
+    int16_t  rpm                 ;//6   @rule: name=RPM; expr=rpm; unit=1/min
+    float    thrust              ;//10  @rule: name=F_Thrust; expr=thrust; unit=N
+    float    torque              ;//14  @rule: name=M_Torque; expr=torque; unit=Nm  
+    float    voltage             ;//18  @rule: name=Volt; expr=voltage; unit=V
+    float    current             ;//22  @rule: name=Current; expr=current; unit=V
+    float    power_in            ;//26  @rule: name=Power_In; expr=power_in; unit=W
+    float    power_out           ;//30  @rule: name=Power_Out; expr=power_out; unit=W
+    float    eta                 ;//34  @rule: name=effectivity; expr=effectivity; unit=%
+    float    thrust_eff          ;//38  @rule: name=Thrust/W; expr=thrust_eff; unit=mN/W
+    float    p_prop              ;//42  @rule: name=Pressure; expr=p_prop; unit=Pa
+    float    p_tunnel            ;//46  @rule: name=Pressure; expr=p_tunnel; unit=Pa
+    float    p_abs               ;//50  @rule: name=Pressure; expr=p_abs; unit=Pa
+    float    v_prop              ;//54  @rule: name=Propeller_Windspeed; expr=v_prop; unit=m/s
+    float    v_tunnel            ;//58  @rule: name=Tunnel_Windspeed; expr=v_tunne; unit=m/s
+    float    temp_eng            ;//62  @rule: name=Temperatur_1; expr=temp_eng; unit=C
+    float    temp_air            ;//66  @rule: name=Temperatur_2; expr=temp_air; unit=C
+    float    air_ro              ;//70  @rule: name=Air Density; expr=air_ro; unit=kg/m³
+    int16_t  pwm_act             ;//74  @rule: name=PWM_Output; expr=pwm_act; unit=C                
+    uint8_t  ck                  ;//75
+} values ={41, 1};
+
+struct struct_value_raw        
+{
+    uint8_t  length              ;//1
+    uint8_t  ID                  ;//2
+    uint8_t  flag1               ;//3
+    uint8_t  flag2               ;//4
+    int16_t  rpm                 ;//6   @rule: name=RPM; expr=rpm; unit=1/min
+    int16_t  thrust              ;//8   @rule: name=F_Thrust; expr=thrust/100; unit=N
+    int16_t  torque              ;//10  @rule: name=M_Torque; expr=torque/1000; unit=Nm  
+    uint16_t voltage             ;//12  @rule: name=Volt; expr=voltage/1000; unit=V
+    uint16_t current             ;//14  @rule: name=Current; expr=current/1000; unit=A
+    uint16_t power_in            ;//16  @rule: name=Power_In; expr=power_in/100; unit=W
+    uint16_t power_out           ;//18  @rule: name=Power_Out; expr=power_out/100; unit=W
+    uint16_t eta                 ;//20  @rule: name=effectivity; expr=effectivity/10; unit=%
+    int16_t  thrust_eff          ;//22  @rule: name=Thrust/W; expr=thrust_eff/100; unit=mN/W
+    uint16_t  p_prop             ;//24  @rule: name=Pressure; expr=p_prop; unit=Pa
+    uint16_t  p_tunnel           ;//26  @rule: name=Pressure; expr=p_tunnel; unit=Pa
+    int16_t  p_abs               ;//28  @rule: name=Pressure; expr=p_abs; unit=Pa
+    int16_t  v_prop              ;//30  @rule: name=Propeller_Windspeed; expr=v_prop/10; unit=m/s
+    int16_t  v_tunnel            ;//32  @rule: name=Tunnel_Windspeed; expr=v_tunnel/10; unit=m/s
+    int16_t  temp_eng            ;//34  @rule: name=Temp Engine; expr=temp_eng/10; unit=C
+    int16_t  temp_air            ;//36  @rule: name=Temp Air; expr=temp_air/10; unit=C
+    uint16_t air_ro              ;//38  @rule: name=Air Density; expr=air_ro/10000; unit=kg/m³
+    int16_t  pwm_act             ;//40  @rule: name=PWM_Output; expr=pwm_act; unit=C                
+    uint8_t  ck                  ;//41
+} raw ={41, 2};
+
+struct struct_scaling        
+{
+    uint8_t  length              ;//1
+    uint8_t  ID                  ;//2
+    uint8_t  flag1       : 1     ;//3
+    uint8_t  flag2       : 1     ;//4
+    int      thrust_o            ;//8
+    float    thrust_s            ;//12
+    int      torque_o            ;//16
+    float    torque_s            ;//20
+    int      voltage_o           ;//24
+    float    voltage_s           ;//28
+    int      current_o           ;//32
+    float    current_s           ;//36
+    int      p_prop_o            ;//40
+    float    p_prop_s            ;//44
+    int      p_tunnel_o          ;//48
+    float    p_tunnel_s          ;//52
+    int      temp_eng_o            ;//56
+    float    temp_eng_s            ;//60
+    int      temp_air_o            ;//64
+    float    temp_air_s            ;//68
+     uint8_t  ck                  ;//37 
+} cal ={69, 3};
+
+
+
+uint8_t* struct_id[]  = {
+                           &sys.length,     //ID0
+                           &values.length,   //ID1
+                           &raw.length,      //ID2
+                           &cal.length,      //ID3
+                        };  
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Nov 09 13:46:46 2017 +0000
@@ -0,0 +1,284 @@
+#include "mbed.h"
+#include "components.h"
+#include "CD4052.h"
+#include "Telemetry.h"
+#include "counter.h"
+#include "rc_pwm.h"
+ 
+#define M_PI 3.1415926 
+
+DigitalOut myled(LED1);
+CD4052     mp(p22, p21, p19, p20);
+Serial     debug(USBTX, USBRX);
+Telemetry  Network(p29,p30);
+Ticker     data_out;
+Ticker     slow_timer;
+Ticker     fast_timer;
+Counter    rpm_c(p23);
+RC_PWM     emc(p21);
+
+
+
+char CTL_SRV[]         = "192.168.0.15";
+int  CTL_PORT          = 42042;
+char DB_SERVER[]       = "141.39.249.90";
+int  DB_PORT           = 8887;
+
+Endpoint CTL_Server;
+Endpoint DB_Server;
+
+
+int count;
+
+
+
+void set_sys(void)
+{
+    sys.version    =   10;
+    sys.blade      =    2;
+    sys.Amax       =   25;
+    sys.RPMmax     = 2000;
+    sys.PWMmax     = 1900;
+    sys.PWMmin     =  900;
+    sys.t_eng_max  =   68;
+    sys.air_ro     = 1.185 * 10000;
+    sys.pwm        =    0; 
+    
+    emc.min = sys.PWMmin;
+    emc.max = sys.PWMmax;  
+}
+
+void set_cal(void)
+{
+  cal.thrust_o   = -4        ;
+  cal.thrust_s   = 0.080     ;
+  cal.torque_o   = -4        ;
+  cal.torque_s   = 0.080     ;
+  cal.voltage_o  = -52       ;
+  cal.voltage_s  = 0.4290    ;
+  cal.current_o  = -10650    ;
+  cal.current_s  = 1.352     ;
+  cal.p_prop_o   = -8700     ;
+  cal.p_prop_s   = 0.263     ;
+  cal.p_tunnel_o = -8690     ;
+  cal.p_tunnel_s = 0.263     ;
+  cal.temp_eng_o = -3435     ;
+  cal.temp_eng_s = 0.081     ;
+  cal.temp_air_o = -3490     ;
+  cal.temp_air_s = 0.081     ;  
+}
+
+
+
+
+
+//Helpscreen output
+void help()
+{
+ debug.printf("\n*** V %.1f ***\r\n",(float)sys.version/10);
+ debug.printf("*** Motor Test command***\r\n\n");
+ debug.printf("M  = Messure ON\r\n");
+ debug.printf("A  = Messure OFF\r\n");
+ debug.printf("R  = Run\r\n");
+ debug.printf("S  = Stop\r\n");
+}
+
+
+void get_input()
+{
+ char wert;
+
+    while (debug.readable() == true)     
+    { 
+          wert = debug.getc();
+    switch(wert)
+            {        
+                case 'M': sys.do_measure = true;
+                          break;       
+                case 'A': sys.do_measure = false;  
+                          break;
+                case 'R': sys.run        = true;
+                          break;
+                case 'S': sys.run        = false;
+                          sys.pwm        = 0;
+                          break;
+                case '0': cal.thrust_o   = cal.thrust_o - raw.thrust;
+                          break;
+                case '9': cal.thrust_s   = cal.thrust_s * (850 / raw.thrust);
+                          break; 
+                case 'c':        //save sys
+                          break; 
+                default : help();         
+                                      
+            }
+    }
+}
+
+
+void read_values(void)
+{
+    mp.channel(0);
+    raw.thrust    = (mp.x_i() * cal.thrust_s  ) + cal.thrust_o  ;
+    raw.p_prop    = (mp.y_i() * cal.p_prop_s  ) + cal.p_prop_o  ;
+    wait_us(50);
+    mp.channel(1);
+    raw.torque    = (mp.x_i() * cal.torque_s  ) + cal.torque_o  ;
+    raw.p_tunnel  = (mp.y_i() * cal.p_tunnel_s) + cal.p_tunnel_o;
+    wait_us(50);
+    mp.channel(2);
+    raw.current   = (mp.x_i() * cal.current_s ) + cal.current_o ;
+    raw.temp_air  = (mp.y_i() * cal.temp_air_s) + cal.temp_air_o  ;
+    wait_us(50);
+    mp.channel(3);
+    raw.voltage   = (mp.x_i() * cal.voltage_s ) + cal.voltage_o ;
+    raw.temp_eng  = (mp.y_i() * cal.temp_eng_s) + cal.temp_eng_o  ;
+     
+}
+
+void calc_values(void)
+{
+    raw.power_in  = (float)raw.voltage   /  100 * (float)raw.current  / 100  ;
+    if (raw.power_in == 0) raw.power_in = 1;
+    raw.power_out = (float)raw.torque    /  500 * (float)raw.rpm      /  60  * M_PI ;   // P = 2*Pi* RPS * M
+    raw.eta       = (float)raw.power_out /        (float)raw.power_in * 1000 ;
+    raw.thrust_eff= (float)raw.thrust    /        (float)raw.power_in * 100  ;
+    raw.air_ro    = sys.air_ro                                               ;
+    raw.v_prop    = sqrt((float)raw.p_prop)     *  20000 / raw.air_ro        ;
+    raw.v_tunnel  = sqrt((float)raw.p_tunnel)   *  20000 / raw.air_ro        ;        
+}
+
+void midd_values(void)
+{
+    values.thrust     =  values.thrust     + ((float)raw.thrust     /  100 - values.thrust    ) / 100;
+    values.torque     =  values.torque     + ((float)raw.torque     / 1000 - values.torque    ) / 100;
+    values.voltage    =  values.voltage    + ((float)raw.voltage    / 1000 - values.voltage   ) / 100;
+    values.current    =  values.current    + ((float)raw.current    / 1000 - values.current   ) / 100;
+    values.power_in   =  values.power_in   + ((float)raw.power_in   /  100 - values.power_in  ) / 100;
+    values.power_out  =  values.power_out  + ((float)raw.power_out  /  100 - values.power_out ) / 100;
+    values.eta        =  values.eta        + ((float)raw.eta        /   10 - values.eta       ) / 100;
+    values.thrust_eff =  values.thrust_eff + ((float)raw.thrust_eff /  100 - values.thrust_eff) / 100;
+    values.p_prop     =  values.p_prop     + ((float)raw.p_prop            - values.p_prop    ) / 100;
+    values.p_tunnel   =  values.p_tunnel   + ((float)raw.p_tunnel          - values.p_tunnel  ) / 100;
+    values.v_prop     =  values.v_prop     + ((float)raw.v_prop     /   10 - values.v_prop    ) / 100;
+    values.v_tunnel   =  values.v_tunnel   + ((float)raw.v_tunnel   /   10 - values.v_tunnel  ) / 100;
+    values.temp_eng   =  values.temp_eng   + ((float)raw.temp_eng   /   10 - values.temp_eng  ) / 100;
+    values.temp_air   =  values.temp_air   + ((float)raw.temp_air   /   10 - values.temp_air  ) / 100;
+    values.rpm        =  values.rpm        + ((float)raw.rpm               - values.rpm       ) / 8;
+}
+
+
+void tick_fast(void){
+    sys.do_time = true;
+}
+    
+    
+void get_data(void){
+    if (sys.do_measure == 1)
+    {
+     sys.measure++;  
+     switch(sys.measure%4){
+              case 0:      break;
+              case 1:      break;  //stabilize
+              case 2:      break;  //stabilize
+              case 3:      sys.measure = 0;
+                           sys.pwm = sys.pwm + 1;
+                           break;
+                          }
+    }
+    else {sys.measure = 0;}
+}
+
+
+void do_limit(void){
+            
+    if (values.current > sys.Amax){                     //Limit current
+      if (sys.C_limit == 1){
+         sys.do_measure = 0;
+         sys.pwm = 16; 
+         debug.printf("\n\r!!Overcurrent Shutdown!!\n\r");
+        }
+      sys.C_limit = 1;
+     }  
+    else
+     {sys.C_limit = 0;}
+    
+    
+    if (values.rpm > sys.RPMmax){                       //Limit RPM
+      if (sys.RPM_limit == 1){
+         sys.do_measure = 0;
+         sys.pwm = 16; 
+         debug.printf("\n\r!!Overrun Shutdown!!\n\r");
+        }
+      sys.RPM_limit = 1;
+     }  
+    else
+     {sys.RPM_limit = 0;}
+
+    
+    if (values.temp_eng > sys.t_eng_max){                       //Limit Temp
+      if (sys.T_limit == 1){
+         sys.do_measure = 0;
+         sys.pwm = 16; 
+         debug.printf("\n\r!!Overtemp Shutdown!!\n\r");
+        }
+      sys.T_limit = 1;
+     }  
+    else
+     {sys.T_limit = 0;}   
+    
+}
+
+    
+
+void timetable(void){
+     sys.fast++;  
+     switch(sys.fast%4){        // every 1 ms
+           case 1:      read_values();
+                        break;
+           case 2:      calc_values();
+                        break;
+           case 3:      midd_values();
+                        break;
+                        }
+                        
+     if (0 == sys.fast%100){   // every 100 ms
+      sys.slow++;
+     
+      do_limit();               //Limit RPM and Current on every slow loop
+      
+      switch(sys.slow%10){
+           case 0:      emc.set(sys.pwm); 
+                        break;
+           case 1:      raw.rpm       = rpm_c.cps * 60 / sys.blade ;
+                        break;
+           case 2:      debug.printf("RPM: %05d  mid: %05d\n\r",raw.rpm,values.rpm);
+                        break;
+           case 3:      if ( sys.run == true){if ((values.rpm < 200) && (sys.pwm < 16)) sys.pwm++;}          //
+                        if ((sys.run == true) && (sys.do_measure == false)){if (values.rpm > 240) sys.pwm--;}
+                        break;
+           case 9:      get_data();
+                        break;             
+                        
+                        }
+     }
+}
+    
+    
+int main() {
+ debug.baud(115200);
+ //Network.InitEthernetConnection();
+ //Network.ConnectSocket_UDP_Client();
+ CTL_Server.set_address(CTL_SRV, CTL_PORT);
+ DB_Server.set_address(DB_SERVER, DB_PORT);
+ fast_timer.attach(&tick_fast,0.001);
+ set_sys();
+ set_cal();
+ 
+ while(1) {
+           
+           if(sys.do_time){
+                           timetable();
+                           sys.do_time = false;
+                          }
+          }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Nov 09 13:46:46 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/165afa46840b
\ No newline at end of file