def get_s(name): sight = fc.get_car_sight(name) ti = fc.get_ti(name) mid = ti['mid'] while len(mid) < 5: mid.append(mid[len(mid) - 1]) mid = np.array([mid[i * (len(mid) - 1) // 5] for i in range(5)]) mid = mid - np.array([len(fc.get_car_sight(name)[0]) / 2, 0]) s = np.reshape(mid, 10) # right = ti['right'] # left = ti['left'] # if len(left) == 0: # left.append([0,0]) # if len(right) == 0: # right.append([wight-1,hight-1]) # while len(right)<5: # right.append(right[len(right)-1]) # while len(left)<5: # left.append(left[len(left)-1]) # right = np.array([right[i*(len(right)-1)//5] for i in range(5)]) # left = np.array([left[i*(len(left)-1)//5] for i in range(5)]) # s = np.concatenate([np.reshape(right,10), np.reshape(left,10)], 0) return s
def get_r(name): r, ti = 0, fc.get_ti(name) mid = ti['mid'] sight = fc.get_car_sight(name) if sight[mid[0][1]][mid[0][0]] < 0.5: r = -1000 else: r = -np.square(mid[0][0] - len(fc.get_car_sight(name)[0]) / 2) #r -= np.square((100-fc.get_velocity(name))/50) return r
def get_r(name): sight = fc.get_car_sight(name) wight = len(sight[0]) hight = len(sight) r, ti = 0, fc.get_ti(name) mid = ti['mid'] if sight[mid[0][1]][mid[0][0]] < 0.5: r = -35 else: r = -np.abs(mid[0][0] - wight / 2) return r
def get_s(name): sight = fc.get_car_sight(name) wight = len(sight[0]) hight = len(sight) ti = fc.get_ti(name) mid = ti['mid'] while len(mid) < 5: mid.append(mid[len(mid) - 1]) mid = np.array([mid[i * (len(mid) - 1) // 6] for i in range(5)]) mid = mid - np.array([wight / 2, 0]) mid = np.array([0, hight]) - mid s = np.reshape(mid, 10) s = np.concatenate([s, np.array([fc.get_velocity(name)])], 0) return s
# 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) r = r + 0.5 * out[0][2] print(r) if (fc.get_time() - reset_time > 50):
train_right = [] train_state = [] train_example_ctrl = [] train_y = [] degree = 0 velocity = 100 times = 0 fc.set_time_speed(1) fc.start() reset_time = fc.get_time() while True: ti = fc.get_ti("0") right = ti['right'] left = ti['left'] if len(left) == 0: left.append([0, 0]) if len(right) == 0: right.append([wight - 1, hight - 1]) while len(right) < 5: right.append(right[len(right) - 1]) while len(left) < 5: left.append(left[len(left) - 1]) right = np.array([right[i * (len(right) - 1) // 5] for i in range(5)]) left = np.array([left[i * (len(left) - 1) // 5] for i in range(5)])