Target position vmax = thetamax =
function stepmodel(){ //Calculate the input vdem=limit(1.5*(xdem-x), vmax); thetadem=limit(0.2*(vdem-v), thetamax); u=limit(150*(theta-thetadem)+50*dtheta,1.0); //ready for the step //Simulation of the machine omega=omega+(25*u-4*omega)*dt; phi=phi+omega*dt; dtheta=dtheta+(6*Math.sin(theta)+.9*omega-6*u)*dt; theta=theta+dtheta*dt; //Position the parts x=0.25*(theta+phi); //distance rolled v=0.25*(dtheta+omega); //rolling velocity y=Math.sin(theta); //rider x z=Math.cos(theta); //rider height xspoke=r*Math.sin(theta+phi); zspoke=r*Math.cos(theta+phi); // Move the picture Move(wheel, yscale*x + middle, bbase); Move(rider, yscale*(x+y) +middle, bbase-yscale*z); Move(spoke, yscale*x +xspoke +middle, bbase-zspoke); //round again if (running){setTimeout("stepmodel()",20);} }