Facebook
From Denim Kitten, 8 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 341
  1.  
  2. profil_cena = [0.17, 0.17, 0.17, 0.17, 0.17, 0.2999, 0.2999, 0.2999, 0.2999, 0.2999, 0.2999, 0.2999, 0.2999, 0.17, 0.17,  0.2999, 0.2999, 0.2999, 0.2999, 0.2999, 0.2999, 0.2999, 0.17, 0.17];
  3. profil_poboru = [40, 30, 30, 40, 60, 80, 140, 180, 160, 110, 90, 80, 70, 80, 80, 110, 120, 110, 110, 90, 80, 70, 60, 50];
  4.  
  5. Hs = 24;
  6. Hp = 24;
  7. w_u = 1;
  8. w_q = 100;
  9. v0 = 100;
  10. eps_v0 = 50;
  11. v_min_max = [50 500];
  12. u_min_max = [0 100 100; -100 100 100];
  13.  
  14.  
  15. da = opcda('192.168.1.11', 'Kepware.KEPServerEX.V5');
  16. connect(da);
  17. grp = addgroup(da, 'Fanuc')
  18. itm1 = additem(grp, {'Channel1.Fanuc.pompa'});
  19. itm2 = additem(grp, {'Channel1.Fanuc.kat'});
  20. itm3 = additem(grp, {'Channel1.Fanuc.flaga3'});
  21.  
  22. i=1;
  23. while(1)
  24.    
  25.     profil_poboru_new = 0;
  26.     profil_cena_new = 0;
  27.    
  28.     flaga = read(itm3);
  29.    
  30.     pause(1);
  31.  
  32.    if flaga.Value == 1
  33.    
  34.    
  35.    
  36.     for j = 1:Hs
  37.             profil_poboru_new(j) = profil_poboru(j+i-1);
  38.             profil_cena_new(j) = profil_cena(j+i-1);
  39.     end
  40.    
  41.    
  42.  [U tr_zb koszt Q] = MPC_SW(Hs, Hp, w_u, w_q, v0, eps_v0, v_min_max, u_min_max, profil_cena_new, profil_poboru_new);
  43.  
  44.     for k = 1:Hs
  45.       U(k,2) = 1.1436789*atand(0.05*U(k,2)) + 90;
  46.     end
  47.    
  48.    profil_poboru_new
  49.     profil_cena_new
  50.     Hs
  51.     Hp
  52.     U
  53.     i
  54.  
  55.  
  56.  
  57.  
  58.      Hp = Hp - 1;
  59.      Hs = Hs - 1;
  60.     write(itm1, int16(U(1,1)*320))
  61.     write(itm2, int16(U(1,2)*32000/180))
  62.    
  63.    
  64.  
  65.    
  66.      i = i + 1;
  67.      if i == 24
  68.          i = 1;
  69.          Hp = 24;
  70.          Hs = 24;
  71.      end
  72.      
  73.    end
  74.     write(itm3, 0);
  75. end
  76.