//Spet. 28, 1999 //hystv12.cn //conforms to the latest version of CHARON grammar macro INF 10000000 mode straight(real lub, real gub, int sign) { entry entryPt; exit exitPt; inv invStraight { lub < x1 < gub } diffEqn dX1 { d(x1) = u } algeEqn X2Straight { x2 = sign * 1 } } mode upDown(real lub, real gub, real c) { entry entryPt; exit exitPt; inv invUpDown { lub <= x1 <= gub } diffEqn dX1 { d(x1) = u } algeEqn X2UpDown { x2 = x1 + c } } agent Hysteresis(real initx1, real initx2, real a) { input analog real u; output analog real x2; mode main() { diff analog real x1; discrete int q; // initialization trans mainInit from main to inc.straightMinusPt when true do { x1 = initx1; x2 = initx2; q = 0 } trans inctoDec from inc.exitPt to dec.straightMinusPt when (u < 0) && (x1 < -(a+2) do { q = 1 } to dec.straightPlusPt when (u < 0) && (x1 > -a ) do { q = 1 } to dec.downPt when (u < 0) && (-(a+2) <= x1 <= -a ) do { q = 1 } trans dectoInc from dec.exitPt to inc.straightMinusPt when (u > 0) && (x1 < a) do { q = 0 } to inc.straightPlusPt when (u > 0) && (x1 > a + 2) do { q = 0 } to inc.upPt when (u > 0) && (a<= x1 <= a+2) do { q = 0 } init mode inc() { entry straightMinusPt,straightPlusPt, upPt; exit exitPt; inv invInc { q == 0 } trans incToStraightMinus from inc.straightMinusPt to straightMinus.entryPt when true trans incToStraightPlus from inc.straightPlusPt to straightPlus.entryPt when true trans incToUp from inc.upPt to up.entryPt when true trans straightMinusToUp from straightMinus.exitPt to up.entryPt when (a <= x1 <= a+2 ) trans upToStraightPlus from up.exitPt to straightPlus.entryPt when ( x1 > a+2 ) init mode straightMinus = straight(-INF,a,-1) mode straightPlus = straight(a+2,INF,1) mode up = upDown(a, a+2, -(a+1)) } mode dec() { entry straightMinusPt,straightPlusPt, downPt; exit exitPt; inv invDec { q == 1 } trans decToStraightMinus from dec.straightMinusPt to straightMinus.entryPt when true trans decToStraightPlus from dec.straightPlusPt to straightPlus.entryPt when true trans decToDown from dec.downPt to down.entryPt when true trans straightPlusToDown from straightPlus.exitPt to down.entryPt when (-(a+2) <= x1 <= -a) trans downToStraightMinus from down.exitPt to straightMinus.entryPt when (x1 < -(a+2)) mode straightMinus = straight(-INF,-(a+2),-1) mode straightPlus = straight(-a,INF,1) mode down = upDown(-(a+2), -a, a+1) } } } hyst1 = Hysteresis(-1.0, -1.0, 0.5); // initx1 = -1.0, initx2 = -1.0, a = 0.5