Pendulum simulation with friction
Command
c = 1 d = 2.2 e = 16.1 f = 4.4
//stepmodel() tiltsens = tilt + .001; tiltslow = tiltslow + trate*dt trate = 20*(tiltsens - tiltslow) u=c*(x-command)+d*v+e*tiltsens+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);}