// ************************************************************************** // // // // eses eses // // eses eses // // eses eseses esesese eses Embedded Systems Group // // ese ese ese ese ese // // ese eseseses eseseses ese Department of Computer Science // // eses eses ese eses // // eses eseses eseseses eses University of Kaiserslautern // // eses eses // // // // ************************************************************************** // // This is the classic bouncing ball example. The ball starts at an initial // // height h0 with an initial velocity v0 until its height becomes zero, i.e., // // it hits the ground. At that point of time, the velocity changes its sign // // and is absolute value is halved. Note that we define the release condition // // of the flow statement with height zero and a negative velocity, so that // // the ball will bounce up when we enter the flow statement next time. // // Otherwise, the release condition would be immediately true and the flow // // statement would terminate in zero time without having an effect at all. // // We count the number of bounces in the integer n that is incremented each // // time the ball hits the floor with negative velocity. // // ************************************************************************** // module Ball1D(real ?h0,?v0,int n) { hybrid real h,v; h = h0; v = v0; loop{ flow{ drv(h) <- cont(v); drv(v) <- -9.81; } until(cont(h)<=0.0 and cont(v)<0.0); next(n) = n+1; next(v) = -v*0.5; pause; } }