Exemplo n.º 1
0
 def control_loop(self):
     steer, gas = 0,0
     if self.feed_u is None:
         for car in reversed(self.cars):
             car.control(steer, gas)
     else:
         for car, fu, hu in zip(self.cars, self.feed_u, self.history_u):
             car.u = fu[len(hu)]
     for car, hist in zip(self.cars, self.history_u):
         hist.append(car.u)
     for car in self.cars:
         self.prev_x[car] = car.x
     for car in self.cars:
         print("CAR: {}".format(car.x))
         car.move()
     for car, hist in zip(self.cars, self.history_x):
         hist.append(car.x)
     self.prev_t = time.time()
     self.termination_counter += 1
     if self.termination_counter >= self.MAX_ITER:
         data2_filename = "data2/CDC_RUN_NUM_CARS{0}_AUTLEVEL{1}_TIME{2}.txt".\
                 format(len(self.cars), self.aut_level, time.time())
         write_string = ""
         for car in self.cars:
             cur_write = {'lane': car.x[0], 'pos': car.x[1], 'isRobot': car.iamrobot}
             write_string += str(cur_write)
             write_string += "\n"
         
         with open(data2_filename, 'w') as f:
             f.write(write_string)
     #increment the counter of how many control loop iterations since the last midlevel iteration
     self.cntrl_loop_counter += 1
Exemplo n.º 2
0
    def control_loop(self, _=None):
        #if not self.paused:
            #pyglet.image.get_buffer_manager().get_color_buffer().save('screenshots/screenshot-%.2f.png'%time.time())
        if self.paused:
            return
        if self.iters is not None and len(self.history_x[0])>=self.iters:
            if self.autoquit:
                self.event_loop.exit()
            return
        if self.feed_u is not None and len(self.history_u[0])>=len(self.feed_u[0]):
            if self.autoquit:
                self.event_loop.exit()
            return
        if self.pause_every is not None and self.pause_every>0 and len(self.history_u[0])%self.pause_every==0:
            self.paused = True
        steer = 0.
        gas = 0.
        if self.keys[key.UP]:
            gas += 1.
        if self.keys[key.DOWN]:
            gas -= 1.
        if self.keys[key.LEFT]:
            steer += 1.5
        if self.keys[key.RIGHT]:
            steer -= 1.5
        if self.joystick:
            print(self.joystick.y)
            steer -= self.joystick.x*4.
            gas -= (self.joystick.y - 1)/2
        self.heatmap_valid = False
        for car in self.cars:
            self.prev_x[car] = car.x
        if self.feed_u is None:
            for car in reversed(self.cars):
                car.control(steer, gas)
        else:
            for car, fu, hu in zip(self.cars, self.feed_u, self.history_u):
                car.u = fu[len(hu)]
        copy_cars = set([c for c in self.cars if type(c) is CopyCar])
        for car, hist in zip(self.cars, self.history_u):
            hist.append(car.u)
            if car not in copy_cars:
                for cc in copy_cars:
                    cc.use_also(car.x, car.u)

        for car in self.cars:
            car.move()
        for car, hist in zip(self.cars, self.history_x):
            print(car.x)
            hist.append(car.x)
        for car, hist in zip(self.cars, self.history_belief):
            if hasattr(car, 'log_ps'):
                hist.append(np.asarray([np.exp(log_p.get_value()) for log_p in car.log_ps]))
        self.prev_t = time.time()
Exemplo n.º 3
0
    def control_loop(self, _=None):
        #print "Time: ", time.time()
        if self.paused:
            return
        if self.iters is not None and len(self.history_x[0]) >= self.iters:
            if self.autoquit:
                self.event_loop.exit()
            return
        if self.feed_u is not None and len(self.history_u[0]) >= len(
                self.feed_u[0]):
            if self.autoquit:
                self.event_loop.exit()
            return
        if self.pause_every is not None and self.pause_every > 0 and len(
                self.history_u[0]) % self.pause_every == 0:
            self.paused = True
        steer = 0.
        gas = 0.
        if self.keys[key.UP]:
            gas += 1.
        if self.keys[key.DOWN]:
            gas -= 1.
        if self.keys[key.LEFT]:
            steer += 1.5
        if self.keys[key.RIGHT]:
            steer -= 1.5
        if self.joystick:
            steer -= self.joystick.x * 3.
            gas -= self.joystick.y
        self.heatmap_valid = False
        for car in self.cars:
            self.prev_x[car] = car.x
        if self.feed_u is None:
            for car in reversed(self.cars):
                car.control(steer, gas)
        else:
            for car, fu, hu in zip(self.cars, self.feed_u, self.history_u):
                car.u = fu[len(hu)]
        for car, hist in zip(self.cars, self.history_u):
            hist.append(car.u)
        for car in self.cars:
            car.move()
        for car, hist in zip(self.cars, self.history_x):
            hist.append(car.x)

        if self.show_feature_sums:
            self.prev_t = time.time()
            self.ticks_run += 1
            self.feature_sum = np.add(
                self.feature_sum,
                self.feature_function(0, self.main_car.x, self.main_car.u,
                                      self.main_car))
            print self.ticks_run
            print self.feature_sum
Exemplo n.º 4
0
 def control_loop(self, _=None):
     if self.paused:
         return
     if self.iters is not None and len(self.history_x[0]) >= self.iters:
         if self.autoquit:
             self.event_loop.exit()
         return
     if self.feed_u is not None and len(self.history_u[0]) >= len(
             self.feed_u[0]):
         if self.autoquit:
             self.event_loop.exit()
         return
     if self.pause_every is not None and self.pause_every > 0 and len(
             self.history_u[0]) % self.pause_every == 0:
         self.paused = True
     steer = 0.
     gas = 0.
     if self.keys[key.UP]:
         gas += 1.
     if self.keys[key.DOWN]:
         gas -= 1.
     if self.keys[key.LEFT]:
         steer += 1.5
     if self.keys[key.RIGHT]:
         steer -= 1.5
     if self.joystick:
         steer -= self.joystick.x * 3.
         gas -= self.joystick.y
     self.heatmap_valid = False
     for car in self.cars:
         self.prev_x[car] = car.x
     if self.feed_u is None:
         for car in reversed(self.cars):
             car.control(steer, gas)
     else:
         for car, fu, hu in zip(self.cars, self.feed_u, self.history_u):
             car.u = fu[len(hu)]
     for car, hist in zip(self.cars, self.history_u):
         hist.append(car.u)
     for car in self.cars:
         car.move()
     for car, hist in zip(self.cars, self.history_x):
         hist.append(car.x)
     for car, hist in zip(self.cars, self.history_belief):
         if hasattr(car, 'log_ps'):
             hist.append(
                 np.asarray(
                     [np.exp(log_p.get_value()) for log_p in car.log_ps]))
     self.prev_t = time.time()
Exemplo n.º 5
0
    def control_loop(self, _=None):
        #print "Time: ", time.time()
        if self.paused:
            return
        if self.iters is not None and len(self.history_x[0])>=self.iters:
            if self.autoquit:
                self.event_loop.exit()
            return
        if self.feed_u is not None and len(self.history_u[0])>=len(self.feed_u[0]):
            if self.autoquit:
                self.event_loop.exit()
            return
        if self.pause_every is not None and self.pause_every>0 and len(self.history_u[0])%self.pause_every==0:
            self.paused = True
        steer = 0.
        gas = 0.
        if self.keys[key.UP]:
            gas += 1.
        if self.keys[key.DOWN]:
            gas -= 1.
        if self.keys[key.LEFT]:
            steer += 1.5
        if self.keys[key.RIGHT]:
            steer -= 1.5
        if self.joystick:
            steer -= self.joystick.x*3.
            gas -= self.joystick.y
        self.heatmap_valid = False
        for car in self.cars:
            self.prev_x[car] = car.x
        if self.feed_u is None:
            for car in reversed(self.cars):
                car.control(steer, gas) # IMPORTANT: very slow when using the nested optimizr
        else:
            for car, fu, hu in zip(self.cars, self.feed_u, self.history_u):
                car.u = fu[len(hu)]
        for car, hist in zip(self.cars, self.history_u):
            hist.append(car.u)
        for car in self.cars:
            car.move()
        for car, hist in zip(self.cars, self.history_x):
            hist.append(car.x)
        self.prev_t = time.time()

        # use this to get all pictures
        pyglet.image.get_buffer_manager().get_color_buffer().save('screenshots/screenshot-%.2f.png'%time.time())
Exemplo n.º 6
0
 def control_loop(self, _=None):
     #print "Time: ", time.time()
     if self.paused:
         return
     if self.iters is not None and len(self.history_x[0])>=self.iters:
         if self.autoquit:
             self.event_loop.exit()
         return
     if self.feed_u is not None and len(self.history_u[0])>=len(self.feed_u[0]):
         if self.autoquit:
             self.event_loop.exit()
         return
     if self.pause_every is not None and self.pause_every>0 and len(self.history_u[0])%self.pause_every==0:
         self.paused = True
     steer = 0.
     gas = 0.
     if self.keys[key.UP]:
         gas += 1.
     if self.keys[key.DOWN]:
         gas -= 1.
     if self.keys[key.LEFT]:
         steer += 1.5
     if self.keys[key.RIGHT]:
         steer -= 1.5
     if self.joystick:
         steer -= self.joystick.x*3.
         gas -= self.joystick.y
     self.heatmap_valid = False
     for car in self.cars:
         self.prev_x[car] = car.x
     if self.feed_u is None:
         for car in reversed(self.cars):
             car.control(steer, gas)
     else:
         for car, fu, hu in zip(self.cars, self.feed_u, self.history_u):
             car.u = fu[len(hu)]
     for car, hist in zip(self.cars, self.history_u):
         hist.append(car.u)
     for car in self.cars:
         car.move()
     for car, hist in zip(self.cars, self.history_x):
         hist.append(car.x)
     self.prev_t = time.time()
Exemplo n.º 7
0
 def control_loop(self, _=None):
     #print "Time: ", time.time()
     if self.paused:
         return
     if self.iters is not None and len(self.history_x[0]) >= self.iters:
         if self.autoquit:
             self.event_loop.exit()
         return
     if self.feed_u is not None and len(self.history_u[0]) >= len(
             self.feed_u[0]):
         if self.autoquit:
             self.event_loop.exit()
         return
     if self.pause_every is not None and self.pause_every > 0 and len(
             self.history_u[0]) % self.pause_every == 0:
         self.paused = True
     steer_arrows = 0.
     gas_arrows = 0.
     if self.keys[key.UP]:
         gas_arrows += 1.
     if self.keys[key.DOWN]:
         gas_arrows -= 1.
     if self.keys[key.LEFT]:
         steer_arrows += 1.5
     if self.keys[key.RIGHT]:
         steer_arrows -= 1.5
     if self.joystick:
         steer_arrows -= self.joystick.x * 3.
         gas_arrows -= self.joystick.y
     steer_wasd = 0.  # for cars controlled using the 'wasd' keys
     gas_wasd = 0.
     if self.keys[key.W]:
         gas_wasd += 1.
     if self.keys[key.S]:
         gas_wasd -= 1.
     if self.keys[key.A]:
         steer_wasd += 1.5
     if self.keys[key.D]:
         steer_wasd -= 1.5
     if self.joystick:
         steer_wasd -= self.joystick.x * 3.
         gas_wasd -= self.joystick.y
     self.heatmap_valid = False
     for car in self.cars:
         self.prev_x[car] = car.x
     if self.feed_u is None:
         for car in reversed(self.cars):
             if car.controls == 'wasd':
                 car.control(steer_wasd, gas_wasd)
             else:
                 car.control(steer_arrows, gas_arrows)
     else:
         for car, fu, hu in zip(self.cars, self.feed_u, self.history_u):
             car.u = fu[len(hu)]
     for car, hist in zip(self.cars, self.history_u):
         hist.append(car.u)
     for car in self.cars:
         car.move()
     for car, hist in zip(self.cars, self.history_x):
         hist.append(car.x)
     self.prev_t = time.time()
Exemplo n.º 8
0
 def control_loop(self, _=None):
     #print "Time: ", time.time()
     if self.paused:
         return
     if self.iters is not None and len(self.history_x[0])>=self.iters:
         if self.autoquit:
             self.event_loop.exit()
         return
     if self.feed_u is not None and len(self.history_u[0])>=len(self.feed_u[0]):
         if self.autoquit:
             self.event_loop.exit()
         return
     if self.pause_every is not None and self.pause_every>0 and len(self.history_u[0])%self.pause_every==0:
         self.paused = True
     steer = 0.
     gas = 0.
     if self.keys[key.UP]:
         gas += 1.
     if self.keys[key.DOWN]:
         gas -= 1.
     if self.keys[key.LEFT]:
         steer += 1.5
     if self.keys[key.RIGHT]:
         steer -= 1.5
     if self.joystick:
         steer -= self.joystick.x*3.
         gas -= self.joystick.y
     self.heatmap_valid = False
     for car in self.cars:
         self.prev_x[car] = car.x
     if self.feed_u is None:
         for car in reversed(self.cars):
             car.control(steer, gas)
     else:
         for car, fu, hu in zip(self.cars, self.feed_u, self.history_u):
             car.u = fu[len(hu)]
     for car, hist in zip(self.cars, self.history_u):
         hist.append(car.u)
     for car in self.cars:
         print("CAR: {}".format(car.x))
         car.move()
     for car, hist in zip(self.cars, self.history_x):
         hist.append(car.x)
     self.prev_t = time.time()
     self.termination_counter += 1
     if self.termination_counter >= self.MAX_ITER:
         print("Freaky things are happening\n\n")
         #self.paused = True
         data2_filename = "data2/CDC_RUN_NUM_CARS{0}_AUTLEVEL{1}_TIME{2}.txt".\
                 format(len(self.cars), self.aut_level, time.time())
         write_string = ""
         for car in self.cars:
             cur_write = {'lane': car.x[0], 'pos': car.x[1], 'isRobot': car.iamrobot}
             write_string += str(cur_write)
             write_string += "\n"
         
         with open(data2_filename, 'w') as f:
             f.write(write_string)
         self.event_loop.exit()
     #increment the counter of how many control loop iterations since the last midlevel iteration
     self.cntrl_loop_counter += 1