Skip to content

Commit

Permalink
adding mpc
Browse files Browse the repository at this point in the history
  • Loading branch information
urosolia committed Oct 1, 2020
1 parent 09211a5 commit b49c95e
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,30 @@ def main():
# ======================================================================================================================
# ====================================== LINEAR REGRESSION ============================================================
# ======================================================================================================================
# print("Starting MPC")
# # Estimate system dynamics
# lamb = 0.0000001
# A, B, Error = Regression(xPID_cl, uPID_cl, lamb)
# mpcParam.A = A
# mpcParam.B = B
# # Initialize MPC and run closed-loop sim
# mpc = MPC(mpcParam)
# xMPC_cl, uMPC_cl, xMPC_cl_glob, _ = simulator.sim(xS, mpc)
# print("===== MPC terminated")
print("Starting MPC")
# Estimate system dynamics
lamb = 0.0000001
A, B, Error = Regression(xPID_cl, uPID_cl, lamb)
mpcParam.A = A
mpcParam.B = B
# Initialize MPC and run closed-loop sim
mpc = MPC(mpcParam)
xMPC_cl, uMPC_cl, xMPC_cl_glob, _ = simulator.sim(xS, mpc)
print("===== MPC terminated")

# # ======================================================================================================================
# # =================================== LOCAL LINEAR REGRESSION =========================================================
# # ======================================================================================================================
# print("Starting TV-MPC")
# # Initialized predictive model
# predictiveModel = PredictiveModel(n, d, map, 1)
# predictiveModel.addTrajectory(xPID_cl,uPID_cl)
# #Initialize TV-MPC
# ltvmpcParam.timeVarying = True
# mpc = MPC(ltvmpcParam, predictiveModel)
# # Run closed-loop sim
# xTVMPC_cl, uTVMPC_cl, xTVMPC_cl_glob, _ = simulator.sim(xS, mpc)
# print("===== TV-MPC terminated")
# ======================================================================================================================
# =================================== LOCAL LINEAR REGRESSION =========================================================
# ======================================================================================================================
print("Starting TV-MPC")
# Initialized predictive model
predictiveModel = PredictiveModel(n, d, map, 1)
predictiveModel.addTrajectory(xPID_cl,uPID_cl)
#Initialize TV-MPC
ltvmpcParam.timeVarying = True
mpc = MPC(ltvmpcParam, predictiveModel)
# Run closed-loop sim
xTVMPC_cl, uTVMPC_cl, xTVMPC_cl_glob, _ = simulator.sim(xS, mpc)
print("===== TV-MPC terminated")

# ======================================================================================================================
# ============================== LMPC w\ LOCAL LINEAR REGRESSION ======================================================
Expand Down Expand Up @@ -128,8 +128,8 @@ def main():

print("===== Start Plotting")
plotTrajectory(map, xPID_cl, xPID_cl_glob, uPID_cl, 'PID')
# plotTrajectory(map, xMPC_cl, xMPC_cl_glob, uMPC_cl, 'MPC')
# plotTrajectory(map, xTVMPC_cl, xTVMPC_cl_glob, uTVMPC_cl, 'TV-MPC')
plotTrajectory(map, xMPC_cl, xMPC_cl_glob, uMPC_cl, 'MPC')
plotTrajectory(map, xTVMPC_cl, xTVMPC_cl_glob, uTVMPC_cl, 'TV-MPC')
plotClosedLoopLMPC(lmpc, map)
animation_xy(map, lmpc, Laps-1)
plt.show()
Expand Down

0 comments on commit b49c95e

Please sign in to comment.