예제 #1
0
    def step(self):
        """
        Called repeatedly by the simulation.   
             
        Advances the physical model by a single step.
        
        If pendulum is out of bounds
            create a new brain  and reset the simulation.
        
        If fitness has reached target value.
           save brain and stop the simulation
       
        """

        out = [0, 0, 0]

        keyinput = gui.get_pressed()
        if keyinput[gui.keys.K_UP]:
            out[0] = 1.0

        if keyinput[gui.keys.K_LEFT]:
            out[1] = 1.0

        if keyinput[gui.keys.K_RIGHT]:
            out[2] = 1.0

        self.ip.step(out, self.dt)

        # print self.out

        if reap(self.ip):
            init_pod(self.ip)
예제 #2
0
    def step(self):
        """
        Called repeatedly by the simulation.   
             
        Advances the physical model by a single step.
        
        If pendulum is out of bounds
            create a new brain  and reset the simulation.
        
        If fitness has reached target value.
           save brain and stop the simulation
       
        """
        
        
         # --- use keypresses to determine control
        force=0.0
        keyinput = gui.get_pressed()  
        if keyinput[gui.keys.K_LEFT]:
            force -= 1.0

        if keyinput[gui.keys.K_RIGHT]:
            force+= 1.0
            
        # Using difference of 2 outputs for symmetry (I don't know if this is a good idea!)      
        self.ip.setForce(force)
        self.rk.step(self.dt)
    
        # print self.inp
           
        if reap(self.ip):
            
            self.rk.reset()
            self.ip.reset(INITIAL_ANG)
예제 #3
0
    def process(self, pod, dt):

        # what happens here is up to you
        # This example looks at  key press to set the control

        control = pods.Control()
        keyinput = gui.get_pressed()

        # print the sensor information
        for sensor in pod.sensors:

            print sensor.name, sensor.val, sensor.wall

        # --- use keypresses to determine control
        if keyinput[gui.keys.K_LEFT]:
            control.left = .4

        if keyinput[gui.keys.K_RIGHT]:
            control.right = .4

        if keyinput[gui.keys.K_UP]:
            control.up = 1

        if keyinput[gui.keys.K_DOWN]:
            control.down = 1

        return control
예제 #4
0
    def process(self,pod,dt):
        
        control=Control()
        #print "1"
        
        keyp = gui.get_pressed()
        
        #print "2"
        
        # gui.get_pressed()
        
        #print pg
       
       
                
        if keyp[gui.keys.K_LEFT]:
            control.left=1

        if keyp[gui.keys.K_RIGHT]:
            control.right=1

        if keyp[gui.keys.K_UP]:
            control.up=1

        if keyp[gui.keys.K_DOWN]:
            control.down=1

        #print control.left,control.right,control.up,control.down
        
        return control
예제 #5
0
    def step(self):
        """
        Called repeatedly by the simulation.   
             
        Advances the physical model by a single step.
        
        If pendulum is out of bounds
            create a new brain  and reset the simulation.
        
        If fitness has reached target value.
           save brain and stop the simulation
       
        """
                  
        out=[0,0,0]
        
      
        keyinput = gui.get_pressed()  
        if keyinput[gui.keys.K_UP]:
            out[0] = 1.0

        if keyinput[gui.keys.K_LEFT]:
            out[1] = 1.0

        if keyinput[gui.keys.K_RIGHT]:
            out[2] = 1.0
            
            
        self.ip.step(out,self.dt)
        
        # print self.out
           
        if reap(self.ip):
            init_pod(self.ip)
예제 #6
0
    def process(self,pod,dt):

                
        # what happens here is up to you
        # This example looks at  key press to set the control

        control=pods.Control()
        keyinput = gui.get_pressed()    

        # print the sensor information
        for  sensor in pod.sensors:
             
             print sensor.name ,sensor.val, sensor.wall
             
    
        # --- use keypresses to determine control
        if keyinput[gui.keys.K_LEFT]:
            control.left=.4

        if keyinput[gui.keys.K_RIGHT]:
            control.right=.4

        if keyinput[gui.keys.K_UP]:
            control.up=1

        if keyinput[gui.keys.K_DOWN]:
            control.down=1

        return control
    def process(self,pod,dt):

        """       
        what happens here is up to you
        This example looks at  key press to set the control
        """
        
        control=pods.Control()
        keyinput = gui.get_pressed()    

        #  ----  Just to demonstrate what information is available to use for input to the control       
        if True:  
            # -------  This code prints out all the available information about the state of the pod
            for attr, value in pod.state.__dict__.iteritems():
                print str(attr)+ "="+ str(value),
            print
        

        # --- use keypresses to determine control
        if keyinput[gui.keys.K_LEFT]:
            control.left=.4

        if keyinput[gui.keys.K_RIGHT]:
            control.right=.4

        if keyinput[gui.keys.K_UP]:
            control.up=1

        if keyinput[gui.keys.K_DOWN]:
            control.down=1
            
        if keyinput[gui.keys.K_0]:
            myWorld.init_pod(pod)

        return control
예제 #8
0
    def process(self, pod, dt):
        """       
        what happens here is up to you
        This example looks at  key press to set the control
        """

        control = pods.Control()
        keyinput = gui.get_pressed()

        #  ----  Just to demonstrate what information is available to use for input to the control
        if True:
            # -------  This code prints out all the available information about the state of the pod
            for attr, value in pod.state.__dict__.iteritems():
                print str(attr) + "=" + str(value),
            print

        # --- use keypresses to determine control
        if keyinput[gui.keys.K_LEFT]:
            control.left = .4

        if keyinput[gui.keys.K_RIGHT]:
            control.right = .4

        if keyinput[gui.keys.K_UP]:
            control.up = 1

        if keyinput[gui.keys.K_DOWN]:
            control.down = 1

        if keyinput[gui.keys.K_0]:
            myWorld.init_pod(pod)

        return control
예제 #9
0
while not gui.check_for_quit():   #  loop until user hits escape
    
    pwmRatio=0.0
    tau = 0.0
    
    #"""
    #TEST CONTROLLER OPERATION:
    state = robot.getState()
    phiFilt = filter.compFilter(1.0/frameRate,robot)
    sensors = robot.readSensors()
    pwmRatio = controller.PD(state[0],state[1],phiFilt,sensors[0])
    #"""
    
    #  Check for user key press
    keyinput = gui.get_pressed()
      
    if keyinput[gui.keys.K_LEFT]:    # apply anticlockwise pwmRatio to wheels
            tau = -0.8

    if keyinput[gui.keys.K_RIGHT]:   # apply clockwise pwmRatio to wheels
            tau = 0.8
            
    if keyinput[gui.keys.K_DOWN]:    # reset robot
            robot.setAngle(0.2*(random.random()-0.5))
    
    'CHANGE TO INPUT VOLTAGE in PWM format'
    
    # step the car for a single GUI frame        
    robot.step(pwmRatio,tau,1.0/frameRate)
    
예제 #10
0
# create an inverted pendulum
cart = cart.Cart()

# set the initial angle
cart.setAngle(math.pi + 0.02)

frameRate = 10  # slow down to 10 steps per second.

screen = gui.init_surface((800, 200), " CART + IP demo")

while not gui.check_for_quit():  #  loop until user hits escape

    force = 0.0

    #  check for user key press
    keyinput = gui.get_pressed()

    if keyinput[gui.keys.K_LEFT]:  # push left
        force = -1.0

    if keyinput[gui.keys.K_RIGHT]:  # push right
        force = 1.0

    # step the car for a single GUI frame
    cart.step(force, 1.0 / frameRate)

    ################  RESET CODE ##############################

    # Test for falling over
    # if fallen then reset with a random angle