我第一次把东西放在这里,对不起,如果我有任何错误。
我的程序使用两个边界限制来强制我的程序保持在数组中,但他没有比较限制,我没有发现问题。
限制: pos_range = [-1.2,0.60] vel_range = [-0.07,0.07]
速度和位置更新在下面,更新值后我检查结果,因为汽车不能越过pos_range或vel_range,但他总是去。我是否犯了任何错误来比较价值?这种方法错了吗?
感谢。
pos_range = [-1.2, 0.60]
vel_range = [-0.07, 0.07]
def update_position_velocity(a):
# action 0,1,2,3 0 backward 1 forward 2 coast
global simulatev
global simulatep
global newv
global newp
oldv = simulatev # preserve old values
oldp = simulatep
if a == 0: # backward
aval = -1
else:
aval = a # coast = 0, forward = +1, backward = -1;
newv = oldv + (0.001 * aval) + (gravity * cos(3 * oldp)) # update equation for velocity
newp = simulatep + newv # update equation for position
print newp, newv
if newv < vel_range[0]: # clip velocity if necessary to keep it within range
newv = vel_range[0]
if newv > vel_range[1]:
newv = vel_range[1]
if newp < pos_range[0]: # clip position and velocity if necessary to keep it within range
newp = pos_range[0]
newv = 0 # reduce velocity to 0 if position was out of bounds
if newv > pos_range[1]:
newp = pos_range[1]
newv = 0
print newp, newv
simulatep = newp
simulatev = newv # update state to new values
程序在这里失败:
if newv < vel_range[0]: # clip velocity if necessary to keep it within range
newv = vel_range[0]
if newv > vel_range[1]:
newv = vel_range[1]
if newp < pos_range[0]: # clip position and velocity if necessary to keep it within range
newp = pos_range[0]
newv = 0 # reduce velocity to 0 if position was out of bounds
if newv > pos_range[1]:
newp = pos_range[1]
newv = 0