Example #1
0
    def __init__(self,
                 num_of_cars,
                 lanes,
                 length,
                 speed_limit,
                 init_pos,
                 init_lane,
                 ego_speed_init,
                 dt,
                 r_seed,
                 x_range=10):

        self.n_lanes = lanes
        self.n_cars = num_of_cars
        self.x_range = x_range
        self.length = length
        self.speed_limit = speed_limit / 3.6
        self.T = 1.5
        self.s0 = self.T * self.speed_limit
        self.delta = 4
        self.road_width = 4
        self.lane_init = (init_lane -
                          1) * self.road_width + self.road_width * 0.5
        self.dt = dt
        random.seed(r_seed)
        self.vehicle_list = []
        # Ego Car
        v_init = random.random() * (ego_speed_init / 3.6)
        self.x_base = 0
        self.vehicle_list.append(
            car.Car(init_pos, self.lane_init, v_init, 0, speed_limit, self.dt))
        self.dist_to_front = -1
        self.non_ego_limit = self.speed_limit * 0.4

        ### RL Params
        self.done = False
        self.success = False
        self.reward = 0
        self.timestep = 0
        self.lane = self.lane_init
        self.lane_prev = self.lane_init
        self.x_goal = 3
        self.steering = 0

        self.lateral_controller = lateral_agent.lateral_control(dt)

        s = set()
        while len(s) < num_of_cars:
            s.add(np.random.choice(np.arange(0.3, 1, 0.05)) * self.length)

        alist = list(s)
        for n in range(0, self.n_cars):
            y_random = random.randint(
                0, self.n_lanes - 2) * self.road_width + self.road_width * 0.5
            x_random = alist[n]
            v_random = random.random() * self.non_ego_limit
            self.vehicle_list.append(
                car.Car(x_random, y_random, v_random, 0, speed_limit, self.dt))
Example #2
0
    def __init__(self,num_of_cars, lanes,length,speed_limit,init_pos,init_lane,ego_speed_init,dt,r_seed,x_range=10):

        self.n_lanes = lanes
        self.n_cars = num_of_cars
        self.x_range = x_range
        self.length = length
        self.speed_limit = speed_limit/3.6
        self.T = 2
        self.s0 = self.T * self.speed_limit
        self.delta = 4
        self.road_width = 4
        self.lane_init = (init_lane-1)*self.road_width + self.road_width*0.5
        self.dt = dt
        random.seed(r_seed)
        self.vehicle_list = []
        # Ego Car
        v_init = random.random() * (ego_speed_init/3.6)
        self.x_base = 0
        self.vehicle_list.append(car.Car(init_pos,self.lane_init,v_init,0,speed_limit,self.dt))

        ### RL Params
        self.done = False
        self.success = False
        self.reward = 0
        self.timestep = 0
        self.lane = self.lane_init
        self.lane_prev = self.lane_init
        self.x_goal = 3

        self.lateral_controller = lateral_agent.lateral_control(dt)

        s = set()
        while len(s) < num_of_cars:
            s.add(np.random.choice(np.arange(0.3,1,0.05))*self.length)
        alist = list(s)

        #print("Succesfully generated ",num_of_cars, "unique random numbers")


        for n in range(0,self.n_cars):
            y_random = random.randint(0,self.n_lanes-2)*self.road_width + self.road_width*0.5
            #x_random = np.random.choice(np.arange(0.4,2,0.1))*self.length
            x_random = alist[n]
            v_random = random.random()*self.speed_limit*0.4
            yaw_init = 0 #if lane change scenario
            self.vehicle_list.append(car.Car(x_random,y_random,v_random,0,speed_limit,self.dt))
Example #3
0
estep = 100000

#### Learning Parameters ####

max_train_episodes = 100000
pre_train_steps = 100000
random_sweep = 10
tau = 1

#### Environment ####

done = False
dt = 0.1
timestep = 0

lateral_controller = lateral_agent.lateral_control(dt)
env = world.World(num_of_cars, num_of_lanes, track_length, speed_limit,
                  ego_pos_init, ego_lane_init, ego_speed_init, dt, random_seed,
                  x_range)
goal_lane = (ego_lane_init - 1) * env.road_width + env.road_width * 0.5
goal_lane_prev = goal_lane
action = np.zeros(1)  # acc/steer

tf.reset_default_graph()

mainQN = q_learning.qnetwork(input_dim, output_dim, hidden_units, layers,
                             learning_rate, clip_value)
targetQN = q_learning.qnetwork(input_dim, output_dim, hidden_units, layers,
                               learning_rate, clip_value)

init = tf.global_variables_initializer()
Example #4
0
    def __init__(self,
                 num_of_cars,
                 lanes,
                 length,
                 speed_limit,
                 init_pos,
                 init_lane,
                 ego_speed_init,
                 dt,
                 r_seed,
                 x_range=10):

        self.n_lanes = lanes
        self.n_cars = num_of_cars
        self.x_range = x_range
        self.length = length
        self.speed_limit = speed_limit / 3.6
        self.T = 1.5
        self.s0 = self.T * self.speed_limit
        self.delta = 4
        self.road_width = 4
        self.lane_init = (init_lane -
                          1) * self.road_width + self.road_width * 0.5
        self.dt = dt
        random.seed(r_seed)
        self.vehicle_list = []
        # Ego Car
        v_init = random.random() * (ego_speed_init / 3.6)
        self.x_base = 0
        self.vehicle_list.append(
            car.Car(init_pos, self.lane_init, v_init, 0, speed_limit, self.dt))
        self.dist_to_front = -1
        self.non_ego_limit = self.speed_limit * 0.4

        #POMDP Params
        self.x_view = 100
        self.y_view = 5
        self.observation_grid = np.zeros(
            (self.x_view * 2 + 1, self.y_view * 2 + 1, 2))

        ### RL Params
        self.done = False
        self.success = False
        self.reward = 0
        self.timestep = 0
        self.lane = self.lane_init
        self.lane_prev = self.lane_init
        self.x_goal = 3
        self.steering = 0

        self.lateral_controller = lateral_agent.lateral_control(dt)
        s = set()
        while len(s) < num_of_cars:
            s.add(np.random.choice(np.arange(0.3, 1, 0.05)) * self.length)

        alist = list(s)
        prev = 0
        for n in range(0, self.n_cars):

            y_random = random.randint(
                0, self.n_lanes - 1) * self.road_width + self.road_width * 0.5
            if prev == y_random and y_random == 2:
                y_random = 6
            elif (prev == y_random and y_random == 6):
                y_random = 2
            x_random = alist[n]
            v_random = random.random() * self.non_ego_limit
            #print(v_random)
            if y_random == 6:
                self.vehicle_list.append(
                    car.Car(x_random + random.random() * 300, y_random,
                            -v_random, 0, -speed_limit, self.dt))
            elif (y_random == 2):
                self.vehicle_list.append(
                    car.Car(x_random, y_random, v_random, 0, speed_limit,
                            self.dt))
            prev = y_random
Example #5
0
    def __init__(self,
                 num_of_cars,
                 lanes,
                 length,
                 speed_limit,
                 init_pos,
                 init_lane,
                 ego_speed_init,
                 dt,
                 r_seed,
                 x_range=10):

        self.n_lanes = lanes
        self.n_cars = num_of_cars
        self.x_range = x_range
        self.length = length
        self.speed_limit = speed_limit / 3.6
        self.T = 1.5
        self.s0 = self.T * self.speed_limit
        self.delta = 4
        self.road_width = 4
        self.lane_init = (init_lane -
                          1) * self.road_width + self.road_width * 0.5
        self.dt = dt
        random.seed(r_seed)
        self.vehicle_list = []
        # Ego Car
        v_init = random.random() * (ego_speed_init / 3.6)
        self.x_base = 0
        self.vehicle_list.append(
            car.Car(init_pos, self.lane_init, v_init, 0, speed_limit, self.dt))
        self.dist_to_front = -1
        self.non_ego_limit = self.speed_limit * 0.4

        #POMDP Params
        self.x_view = 150
        self.y_view = 5
        self.resolution = 10  # 1m = resolution points
        self.observation_grid = np.zeros(
            (self.x_view * 2 + 1, self.y_view * 2, 2))

        # Car Dims
        self.car_x_dim = 4 * self.resolution  # 1x = 1m
        self.car_y_dim = 2 * self.resolution  # 2y = 1m

        ### RL Params
        self.done = False
        self.success = False
        self.reward = 0
        self.timestep = 0
        self.lane = self.lane_init
        self.lane_prev = self.lane_init
        self.x_goal = 3

        ### Occlusion stuff
        x_dim = (self.x_view * 2 + 1) * self.resolution
        y_dim = (self.y_view * 2 + 1) * self.resolution
        self.obs_body = np.zeros((x_dim, y_dim))
        self.grid = np.zeros((x_dim, y_dim))

        self.lateral_controller = lateral_agent.lateral_control(dt)

        ### Debug
        self.x_data = []
        self.y_data = []

        s = set()
        while len(s) < num_of_cars:
            s.add(np.random.choice(np.arange(0.3, 1, 0.05)) * self.length)

        alist = list(s)
        for n in range(0, self.n_cars):
            y_random = random.randint(
                0, self.n_lanes - 2) * self.road_width + self.road_width * 0.5
            x_random = alist[n]
            v_random = random.random() * self.non_ego_limit
            self.vehicle_list.append(
                car.Car(x_random, y_random, v_random, 0, speed_limit, self.dt))