Changeset 1398 for applications/pmsm
- Timestamp:
- 10/03/11 23:35:36 (13 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/pmsm/pmsm_ctrl.h
r1391 r1398 1440 1440 int biver; 1441 1441 1442 double bcbv0; 1443 1444 mat ovA, ovC, ovP, ovQ, ovR; 1445 double varome; 1446 1442 1447 // inj 1443 1448 double injkon, injome, injphi; … … 1449 1454 uab(2), u_old(2), icondpd(8), MAXu(100.0), MAXuflag(0), 1450 1455 Ptp(2,2),Kt(2,2),Ared(2,2),Cred(2,2),Qred(2,2),Rred(2,2), 1451 Pt1(2,2),Pt2(2,2),Pt3(2,2),Pt4(2,2),Pt5(2,2), varPth(5), 1456 Pt1(2,2),Pt2(2,2),Pt3(2,2),Pt4(2,2),Pt5(2,2), varPth(5), 1457 ovA(4,4), ovC(2,4), ovP(4,4), ovQ(4,4), ovR(2,2), 1452 1458 /*Cwq(3.0, 3.0*0.000125/0.1, -1200, 1200), 1453 1459 Cuq(20.0, 20.0*0.000125/0.005, -1200, 1200), … … 1488 1494 1489 1495 srand(time(NULL)); 1496 1497 bcbv0 = bcbv; 1498 1499 ovP=eye(4); 1500 ovA.zeros(); 1501 ovC.zeros(); 1502 ovQ.zeros(); 1503 ovR.zeros(); 1504 ovA(0,0) = ovA(1,1) = a; 1505 ovA(2,2) = d; 1506 ovA(3,3) = 1.0; 1507 ovA(3,2) = Dt; 1508 ovC(0,0) = ovC(1,1) = 1.0; 1509 ovR(0,0) = ovR(1,1) = 0.00001; 1510 ovQ(0,0) = ovQ(1,1) = 0.1; 1511 ovQ(2,2) = 0.1; 1512 ovQ(3,3) = 0.00001; 1513 varome = 1.0; 1490 1514 } 1491 1515 … … 1496 1520 virtual vec ctrlaction(const itpp::vec& cond) { 1497 1521 PMSMCtrl::ctrlaction(cond); // fills isa,isb,ome,the,Ww 1498 1522 1499 1523 vec udq(2); 1500 1524 … … 1502 1526 double Isq = isb*cos(the)-isa*sin(the); 1503 1527 1504 double Iqw=(Cwq.ctrlaction(vec_1(Ww-ome)))(0); // conversion from vec 1528 double www = Ww; 1529 if(biver == 12){ 1530 www += (double)rand() / (double)RAND_MAX * 3.0 - 1.5; 1531 } 1532 1533 double Iqw=(Cwq.ctrlaction(vec_1(www-ome)))(0); // conversion from vec 1505 1534 1506 1535 udq(0) = (Cud.ctrlaction(vec_1(-Isd)))(0); … … 1515 1544 1516 1545 1517 //bicriterial///////////////////////////////////////////////////////////// 1546 //bicriterial///////////////////////////////////////////////////////////// 1547 1548 1518 1549 //verze 1: signum 1519 1550 if(biver == 1){ … … 1623 1654 //verze 4: 5KF 1624 1655 if((biver == 4)||(biver == 40)){ 1625 double ia = a*isa + b*ome*sin(the) + c*(uab(0) + bcbv); 1626 double ib = a*isb - b*ome*cos(the) + c*(uab(1) + bcbv); 1656 1657 1658 ovA(0,2) = b*sin(the); 1659 ovA(0,3) = b*ome*cos(the); 1660 ovA(1,2) = -b*cos(the); 1661 ovA(1,3) = b*ome*sin(the); 1662 ovA(2,0) = -e*sin(the); 1663 ovA(2,1) = e*cos(the); 1664 ovA(2,3) = -e*(isb*sin(the)+isa*cos(the)); 1665 mat ovPp = ovA*ovP*ovA.T() + ovQ; 1666 ovP = (eye(4) - ovPp*ovC.T()*inv(ovC*ovPp*ovC.T() + ovR )*ovC)*ovPp; 1667 varome = ovP(2,2); 1668 1669 //bcbv = (sqrt( (ome)*(ome) + bcbv0*bcbv0 ) - abs(ome)); 1670 //double tmp = (ome-Ww)*(ome-Ww) + bcbv0*bcbv0*e*e*c*c*0.5*(1.0+(varome-10.0)/(4.0)); 1671 //if(tmp < 0.0) tmp = 0.0; 1672 //bcbv = (-abs(ome-Ww) + sqrt( tmp )) /e/c; 1673 1674 double ia = a*isa + b*ome*sin(the) + c*(uab(0) + bcbv0); 1675 double ib = a*isb - b*ome*cos(the) + c*(uab(1) + bcbv0); 1627 1676 double om = d*ome + e*(isb*cos(the) - isa*sin(the)); 1628 1677 double th = the + Dt*ome; … … 1638 1687 if(biver == 40) varPth(0) = Pt1(0,0)*Pt1(1,1) - Pt1(0,1)*Pt1(1,0); 1639 1688 1640 ia = a*isa + b*ome*sin(the) + c*(uab(0) + bcbv );1641 ib = a*isb - b*ome*cos(the) + c*(uab(1) - bcbv );1689 ia = a*isa + b*ome*sin(the) + c*(uab(0) + bcbv0); 1690 ib = a*isb - b*ome*cos(the) + c*(uab(1) - bcbv0); 1642 1691 Ared(0,1) = -e*(ib*sin(th) + ia*cos(th)); 1643 1692 Ptp = Ared*Pt2*Ared.T() + Qred; … … 1647 1696 if(biver == 40) varPth(1) = Pt2(0,0)*Pt2(1,1) - Pt2(0,1)*Pt2(1,0); 1648 1697 1649 ia = a*isa + b*ome*sin(the) + c*(uab(0) - bcbv );1650 ib = a*isb - b*ome*cos(the) + c*(uab(1) + bcbv );1698 ia = a*isa + b*ome*sin(the) + c*(uab(0) - bcbv0); 1699 ib = a*isb - b*ome*cos(the) + c*(uab(1) + bcbv0); 1651 1700 Ared(0,1) = -e*(ib*sin(th) + ia*cos(th)); 1652 1701 Ptp = Ared*Pt3*Ared.T() + Qred; … … 1656 1705 if(biver == 40) varPth(2) = Pt3(0,0)*Pt3(1,1) - Pt3(0,1)*Pt3(1,0); 1657 1706 1658 ia = a*isa + b*ome*sin(the) + c*(uab(0) - bcbv );1659 ib = a*isb - b*ome*cos(the) + c*(uab(1) - bcbv );1707 ia = a*isa + b*ome*sin(the) + c*(uab(0) - bcbv0); 1708 ib = a*isb - b*ome*cos(the) + c*(uab(1) - bcbv0); 1660 1709 Ared(0,1) = -e*(ib*sin(th) + ia*cos(th)); 1661 1710 Ptp = Ared*Pt4*Ared.T() + Qred; … … 1704 1753 break; 1705 1754 } 1755 } 1756 //*/ 1757 1758 //verze 44: 5KF 1759 if((biver == 44)){ 1760 double ia = a*isa + b*ome*sin(the) + c*(uab(0) + bcbv); 1761 double ib = a*isb - b*ome*cos(the) + c*(uab(1) + bcbv); 1762 double om = d*ome + e*(isb*cos(the) - isa*sin(the)); 1763 double th = the + Dt*ome; 1764 Ared(0,1) = -e*(ib*sin(th) + ia*cos(th)); 1765 Cred(0,0) = b*sin(th); 1766 Cred(0,1) = b*om*cos(th); 1767 Cred(1,0) = -b*cos(th); 1768 Cred(1,1) = b*om*sin(th); 1769 Ptp = Ared*Pt1*Ared.T() + Qred; 1770 Kt = Ptp*Cred.T()*inv(Cred*Ptp*Cred.T() + Rred); 1771 Pt2 = (eye(2) - Kt*Cred)*Ptp; 1772 varPth(0) = Pt2(0,0)*Pt2(1,1) - Pt2(0,1)*Pt2(1,0); 1773 1774 ia = a*isa + b*ome*sin(the) + c*(uab(0) + bcbv); 1775 ib = a*isb - b*ome*cos(the) + c*(uab(1) - bcbv); 1776 Ared(0,1) = -e*(ib*sin(th) + ia*cos(th)); 1777 Ptp = Ared*Pt1*Ared.T() + Qred; 1778 Kt = Ptp*Cred.T()*inv(Cred*Ptp*Cred.T() + Rred); 1779 Pt2 = (eye(2) - Kt*Cred)*Ptp; 1780 varPth(0) = Pt2(0,0)*Pt2(1,1) - Pt2(0,1)*Pt2(1,0); 1781 1782 ia = a*isa + b*ome*sin(the) + c*(uab(0) - bcbv); 1783 ib = a*isb - b*ome*cos(the) + c*(uab(1) + bcbv); 1784 Ared(0,1) = -e*(ib*sin(th) + ia*cos(th)); 1785 Ptp = Ared*Pt1*Ared.T() + Qred; 1786 Kt = Ptp*Cred.T()*inv(Cred*Ptp*Cred.T() + Rred); 1787 Pt2 = (eye(2) - Kt*Cred)*Ptp; 1788 varPth(0) = Pt2(0,0)*Pt2(1,1) - Pt2(0,1)*Pt2(1,0); 1789 1790 ia = a*isa + b*ome*sin(the) + c*(uab(0) - bcbv); 1791 ib = a*isb - b*ome*cos(the) + c*(uab(1) - bcbv); 1792 Ared(0,1) = -e*(ib*sin(th) + ia*cos(th)); 1793 Ptp = Ared*Pt1*Ared.T() + Qred; 1794 Kt = Ptp*Cred.T()*inv(Cred*Ptp*Cred.T() + Rred); 1795 Pt2 = (eye(2) - Kt*Cred)*Ptp; 1796 varPth(0) = Pt2(0,0)*Pt2(1,1) - Pt2(0,1)*Pt2(1,0); 1797 1798 ia = a*isa + b*ome*sin(the) + c*(uab(0)); 1799 ib = a*isb - b*ome*cos(the) + c*(uab(1)); 1800 Ared(0,1) = -e*(ib*sin(th) + ia*cos(th)); 1801 Ptp = Ared*Pt1*Ared.T() + Qred; 1802 Kt = Ptp*Cred.T()*inv(Cred*Ptp*Cred.T() + Rred); 1803 Pt2 = (eye(2) - Kt*Cred)*Ptp; 1804 varPth(0) = Pt2(0,0)*Pt2(1,1) - Pt2(0,1)*Pt2(1,0); 1805 1806 minindex = 0; 1807 for(int i = 1; i < 5; i++){ 1808 if(varPth(i) < varPth(minindex)){ 1809 minindex = i; 1810 } 1811 } 1812 1813 f << timeid << "\t" << minindex << endl; 1814 timeid++; 1815 1816 switch(minindex){ 1817 case 0: 1818 uab(0) += bcbv; 1819 uab(1) += bcbv; 1820 break; 1821 case 1: 1822 uab(0) += bcbv; 1823 uab(1) -= bcbv; 1824 break; 1825 case 2: 1826 uab(0) -= bcbv; 1827 uab(1) += bcbv; 1828 break; 1829 case 3: 1830 uab(0) -= bcbv; 1831 uab(1) -= bcbv; 1832 break; 1833 case 4: 1834 break; 1835 } 1836 1837 ia = a*isa + b*ome*sin(the) + c*(uab(0)); 1838 ib = a*isb - b*ome*cos(the) + c*(uab(1)); 1839 Ared(0,1) = -e*(ib*sin(th) + ia*cos(th)); 1840 Ptp = Ared*Pt1*Ared.T() + Qred; 1841 Kt = Ptp*Cred.T()*inv(Cred*Ptp*Cred.T() + Rred); 1842 Pt1 = (eye(2) - Kt*Cred)*Ptp; 1706 1843 } 1707 1844 //*/ … … 1844 1981 Cud.set_params(Pd,Pi); 1845 1982 Cuq.set_params(Pd,Pi); 1846 1983 1984 bcbv0 = bcbv; 1847 1985 } 1848 1986 … … 1901 2039 void log_register ( logger &L, const string &prefix ) { 1902 2040 PMSMCtrl::log_register(L,prefix); 1903 L.add_vector ( log_level, logModel, RV ( 1), prefix );2041 L.add_vector ( log_level, logModel, RV ( 2), prefix ); 1904 2042 } 1905 2043 void log_write() const{ 1906 2044 PMSMCtrl::log_write(); 1907 log_level.store( logModel , double(minindex)); 2045 vec tmp(2); 2046 tmp(0) = double(minindex); 2047 tmp(1) = double(bcbv); 2048 // tmp(1) = double(varome); 2049 log_level.store( logModel , tmp); 1908 2050 1909 2051 }