Pendulum simulation with friction
Command
c = .01; d = .04; e = 1.61; f = .44;
//stepmodel() u=c*(x-command)+d*v+e*tilt+f*tiltrate; 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);}