force_scale = 10.0 sizes = [2, 1] net = brain.loadBrain() INIT_ANG = 0.3 cart.setAngle(math.pi + INIT_ANG) while not gui.check_for_quit(): # loop until user hits escape # Test for falling over # if fallen then reset with a random angle input = copy.deepcopy(cart.getState()) input[0] = input[0] - math.pi out = net.ffwd(input) force = (out[0] - 0.5) * force_scale # step the car for a single GUI frame cart.step(force, dt) # draw the cart and display info draw(screen, cart, force) # slow the gui down to the given frameRate gui.tick(frameRate)
import cart import math # create an inverted pendulum cart=cart.Cart() PI=math.pi # reset and set the initial angle just off verticle cart.setAngle(PI-0.1) force=0 # Force applied to cart dt=0.1 # Time step for control while True: cart.step(force,dt) state=cart.getState() print "phi= ",state[0], " dphi/dt=",state[1]," x=",state[2]," dx/dt=",state[3] # If we fall over exit if state[0] < PI*0.5 or state[0] > PI*1.5: break
print pool if fit > plug.GOAL or tot_time > TOTAL_TIME_MAX: print " SUCCESS ---------------------------------------------------------------------- " brain.saveBrain(net) break cart.setAngle(math.pi+plug.INIT_ANG) guess=pool.create() net.setWeights(guess) time=0; input = copy.deepcopy(cart.getState()) input[0]=input[0]-math.pi out=net.ffwd(input) force=(out[0]-0.5)*force_scale # step the car for a single GUI frame cart.step(force,dt) time+=dt tot_time+=dt fit=time-cart.getX() ################ RESET CODE ##############################
import cart import math # create an inverted pendulum cart = cart.Cart() PI = math.pi # reset and set the initial angle just off verticle cart.setAngle(PI - 0.1) force = 0 # Force applied to cart dt = 0.1 # Time step for control while True: cart.step(force, dt) state = cart.getState() print "phi= ", state[0], " dphi/dt=", state[1], " x=", state[ 2], " dx/dt=", state[3] # If we fall over exit if state[0] < PI * 0.5 or state[0] > PI * 1.5: break