Help - Search - Members - Calendar
Full Version: Bouncing ball model
Modelica Forum > Modelica > Modelica
sercan
I am a newbie and trying to model a bouncing ball.
The ball is thrown with an initial speed both in the x,y directions.The system has acceleration in the y axis. Think the system in 2D. The ball first hits to ground and then hits the wall which is standing at 90 degrees then returns and hits the ground for second time... For easiness I take coeff. of restitution same everywhere... The problem is i couldn't find a 5th equation...

here is my code

model Bounce

parameter Modelica.SIunits.Mass m=1.0;
parameter Real cr=0.725;
parameter Modelica.SIunits.Radius r=0.02;

Modelica.SIunits.Distance x(start=5);
Modelica.SIunits.Height y(start=5);
Modelica.SIunits.Velocity Vx(start=-10);
Modelica.SIunits.Velocity Vy(start=-5);
Modelica.SIunits.Acceleration ay(start=0);


equation

Vx=der(x);
Vy=der(y);
ay=der(Vy);

m*ay=-m*Modelica.Constants.g_n;
when y<=r then
reinit(Vy,-cr*pre(Vy));
end when;
when x<=r then
reinit(Vx,-cr*pre(Vx));
end when;

end Bounce;
sercan
since the magnitude of velocity in the x direction stays constant defining Vx as a parameter may seem to be a solution. But it changes its direction as it strikes the wall... So i cannot use reinit function with a parameter...

Carsten
Hey Sercan,

if you do not have a force of the flying ball in x-direction (e.g. aerodynamic drag) you should add the equation

der(Vx)=0

as there is no acceleration in x direction (only in the moment of hitting the wall).

regards
Carsten
sercan
where is my mind... where is my mind......


thanx Carsten
sercan
2nd issue

The model should stop at the instant when the ball strikes the ground for second time. How I am going to do that??
wagner
Hello sercan,

for this porpuse I'd propose a new counter variable of type Integer. If the value of the counter equals two you can use the terminate() function to quit simulation. Just introduce a new algorithm section and declare an Integer variable (BounceCounter).

CODE

algorithm
when(der(y)>0) then
  BounceCounter=BounceCounter+1;
end when;

if (BounceCounter==2) then
  terminate("2nd bounce");
end if;


As counting event I chose the derivative in y direction becoming positive.

Regards

Florian


sercan
thanks Florian
wagner
Hello sercan,

which simulator are you using? In Dymola I get the simulation result attached to this post.

Regards

FlorianClick to view attachment
sercan
Dymola ...

I get same result thanks...
sercan
I don't have the animation part of Dymola. And I wanted to see how the ball goes. ( I mean see the ball's route like i have drawn in the pic. at the first post). If I can get numerical data like
at t=0.001 x=5.41 y=6.54
I can put these into Excel and draw a 2D graph...

So how can I take position data of the ball?
Carsten
What you can do easily is click on x with right mouse button and the choose x as independend variable. Further you check y as variable to plot. After simulation you can, even without having the animation option, go to the menu Animation and choose run.

Regards
Carsten
sercan
But I work in 3D.. So my code is a bit different than above... It is 2D upwards...
Carsten
Sorry, the animation do not work this way, but you can use a model of the user interaction library. Add the following component to you model:
QUELLTEXT

  UserInteraction.Outputs.DynamicTrace dynamicTrace(
    xmin=0,
    xmax=10,
    ymin=0,
    ymax=10,
    Valuey=x,
    Valuex=y) annotation (extent=[-100,-100; 100,100]);



In the simulation tab you click after simulation on diagram symbol and then on animation..


regards
Carsten
wagner
Hello sercan,

in Dymola you can export simulation results in csv-format. Just make a plot window, draw x,y,z in the window and go to the variable tree, right click->save as and choose csv as file format. In the stored file you'll have 4 columns with time,x,y,z which you can import in excel.

Regards

Florian
sercan
thank you but they are separated by commas it is hard to export in this way..
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.