Pendulum simulation with friction
Command
c = 2; d = .1; e = 1000; f = 100; vlim=1;
//stepmodel() tiltsens = tilt + .001; tiltslow = tiltslow + trate*dt trate = 20*(tiltsens - tiltslow) xslow = xslow + vest*dt; vest = 10*(x - xslow); vdem=c*(command-x) if(vdem>vlim){vdem=vlim;} if(vdem<-vlim){vdem=-vlim;} tiltdem=d*(vdem-vest); if(tiltdem>.2){tiltdem=.2;} if(tiltdem<-.2){tiltdem=-.2;} u=e*(tilt-tiltdem)+f*trate; if(u>1){u=1;} if(u<-1){u=-1;} var accel=10*u; if(v>0){accel=accel-.5;} if(v<0){accel=accel+.5;} x=x+v*dt; v=v+accel*dt; tilt=tilt+tiltrate*dt tiltrate+=(10*Math.sin(tilt)-accel*Math.cos(tilt))*dt; Move(trolley, x, 0); Move(bob, x + Math.sin(tilt), Math.cos(tilt)); //round again if (running){setTimeout("stepmodel()",10);}