Bug in Tutorial at Modifying XML?

Hey everyone,

I tried to follow the tutorial and came across an error message at the second tutorial in exercise 4 here:
Index is out of range for s_max, while s_min is fine.

# Set up optimization problem
states = []
for k in range(N):
    # cost function
    cost = quad_form(x[:,k+1]-npy.transpose(npy.array([0,v_ref,0,0])),Q) + quad_form(u[:,k],R) 
    # single state and input constraints
    constr = [x[:,k+1] == A*x[:,k] + B*u[:,k]]
    # add obstacle constraint
    constr += [x[0,k+1] <= s_max[k]]
    constr += [x[0,k+1] >= s_min[k]]
    states.append( Problem(Minimize(cost), constr) )

We iterate through the calculated maximum and minimum position s caused by a leading/following vehicle. While the following vehicle is already given in the example XML-File, we created the leading vehicle and predicted the states in the first tutorial exercise two:

# generate the states for the obstacle for time steps 1 to 40 by assuming constant velocity
state_list = []
for i in range(1, 40):
    # compute new position
    new_position = np.array([dynamic_obstacle_initial_state.position[0] + scenario.dt * i * 22, 0])
    # create new state
    new_state = State(position = new_position, velocity = 22,orientation = 0.02, time_step = i)
    # add new state to state_list
    state_list.append(new_state)

And here is the problem that causes my error. We have 40 time steps in this scenario (and 40 time steps for the following vehicle), but only generate 39 states for the leading vehicle by iterating range(1,40). I would suggest to change 40 to 41. Do you agree?

Thanks and regards,
Max

Hello Max,

yes, you’re right, we will correct the tutorial.
Thanks for notifying us.

Best regards,
Moritz