dt, map, 5 * Laps, TimeLMPC,
                                       LMPC_Solver)

# add previously completed trajectories to Safe Set:
LMPController.addTrajectory(ClosedLoopDataPID)
LMPController.addTrajectory(ClosedLoopDataLTV_MPC)

x0 = np.zeros((1, n))
x0_glob = np.zeros((1, n))
x0[0, :] = ClosedLoopLMPC.x[0, :]
x0_glob[0, :] = ClosedLoopLMPC.x_glob[0, :]

if RunLMPC == 1:
    for it in range(2, Laps):

        ClosedLoopLMPC.updateInitialConditions(x0, x0_glob)
        LMPCSimulator.Sim(
            ClosedLoopLMPC, LMPController, LMPCOpenLoopData
        )  #this runs one lap at a time due to initialization!
        LMPController.addTrajectory(ClosedLoopLMPC)
        onlyLMPController.addTrajectory(ClosedLoopLMPC)

        if LMPController.feasible == 0:
            break
        else:
            # Reset Initial Conditions
            x0[0, :] = ClosedLoopLMPC.x[ClosedLoopLMPC.SimTime, :] - np.array(
                [0, 0, 0, 0, map.TrackLength, 0])
            x0_glob[0, :] = ClosedLoopLMPC.x_glob[ClosedLoopLMPC.SimTime, :]

    #file_data = open(sys.path[0]+'/data/LMPController.obj', 'wb')
Example #2
0
else:
    LMPController = ControllerLMPC(numSS_Points, numSS_it, N, Qslack, Q_LMPC,
                                   R_LMPC, dR_LMPC, n, d, shift, dt, map, Laps,
                                   TimeLMPC, LMPC_Solver)
LMPController.addTrajectory(ClosedLoopDataPID)
LMPController.addTrajectory(ClosedLoopDataLTV_MPC)

x0 = np.zeros((1, n))
x0_glob = np.zeros((1, n))
x0[0, :] = ClosedLoopLMPC.x[0, :]
x0_glob[0, :] = ClosedLoopLMPC.x_glob[0, :]

if RunLMPC == 1:
    for it in range(2, Laps):

        ClosedLoopLMPC.updateInitialConditions(x0, x0_glob)
        LMPCSimulator.Sim(ClosedLoopLMPC, LMPController, LMPCOpenLoopData)
        LMPController.addTrajectory(ClosedLoopLMPC)

        if LMPController.feasible == 0:
            break
        else:
            # Reset Initial Conditions
            x0[0, :] = ClosedLoopLMPC.x[ClosedLoopLMPC.SimTime, :] - np.array(
                [0, 0, 0, 0, map.TrackLength, 0])
            x0_glob[0, :] = ClosedLoopLMPC.x_glob[ClosedLoopLMPC.SimTime, :]

    file_data = open(sys.path[0] + '/data/LMPController.obj', 'wb')
    pickle.dump(ClosedLoopLMPC, file_data)
    pickle.dump(LMPController, file_data)
    pickle.dump(LMPCOpenLoopData, file_data)