示例#1
0
wight = len(fc.get_car_sight('0')[0])
hight = len(fc.get_car_sight('0'))
fc.set_time_speed(1)
fc.start()

ddpg = DDPG.DDPG(10, 1, np.array([np.pi / 3]))
var = np.pi / 3

times = 1

while times:

    break_count = 0
    s, a, r, s_, pointer = [], [], [], [], 0

    fc.sleep(100)
    start_time = fc.get_time()
    s += [get_s('0')]

    while break_count < 5:

        a += [ddpg.predict(s[-1])]
        print('a', *a[-1])
        a[-1] += np.random.normal(a[-1], var)

        fc.ctrl('0', *a[-1], 100)

        run_time = fc.get_time()
        while fc.get_time() - run_time < 100:
            if ddpg.frame > 500:
                ddpg.fit()
示例#2
0
                  normal_working * fc.get_velocity('0') / 100000) < 60:
        p = ddpg.predict(s[-1])
        a += [p[0]]
        if ddpg.frame < ddpg.REPLAY_CAPACITY / 8:
            a[-1] = np.array([0., 100.])
        a[-1] = np.random.normal(
            a[-1] * np.random.uniform(max(1 - np.sqrt(var[0]), 0), 2), var, 2)

        fc.ctrl('0', *(a[-1]))
        run_time = fc.get_time()
        while fc.get_time() - run_time < FRAME_SPACING:
            if ddpg.frame > ddpg.REPLAY_CAPACITY / 8:
                ddpg.fit()
                var *= 0.9999
            else:
                fc.sleep(1)

        r += [get_r('0')]
        s_ += [get_s('0')]

        if r[-1] > -30:
            normal_working = fc.get_time() - start_time

        s += [s_[-1]]

    at = np.mean(np.array(s)[:min(len(s), 40), 10])
    mv = np.mean(np.array(s)[:, 10])

    LAST_FRAME = 100
    if ddpg.frame > ddpg.REPLAY_CAPACITY / 8:
        s, a, r, s_ = s[max(0,
示例#3
0
    train_velocity += [np.array([velocity])]

    # train_time=fc.get_time()
    # if(reset_time>1000):
    #     while fc.get_time()-train_time<20:
    #         model.fit({input_map:train_sight[:len(train_y)-1],
    #         input_degree:train_degree[:len(train_y)-1],
    #         input_velocity:train_velocity[:len(train_y)-1]},
    #         {y:train_y[:len(train_y)-1]},
    #         n_epoch=1,batch_size=512,show_metric=True,shuffle=True)
    # else:
    #     while fc.get_time()-train_time<20:
    #         fc.sleep(1)
    train_time = fc.get_time()
    while fc.get_time() - train_time < 20:
        fc.sleep(1)

    print(fc.get_time() - train_time)

    mid = fc.get_ti("0")["mid"]

    delta = 0
    if len(mid) > 8:
        delta = mid[0][0] - (wight - 1) / 2
    else:
        delta = (wight - 1) / 2

    #r = np.exp(-np.power(delta,2)/36)/(1+np.exp(-(velocity-100)))
    r = np.exp(-np.power(delta, 2) / 64) * np.exp(
        -np.power(velocity - 100, 2) / 2000)
    print(r)