From 5190e3d4efc418b3e2888b8bed2d3a20c34ca615 Mon Sep 17 00:00:00 2001 From: mcarfagno Date: Wed, 8 Apr 2020 14:01:42 +0100 Subject: [PATCH] simulation code cleanup --- mpc_demo/mpc_demo_pybullet.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mpc_demo/mpc_demo_pybullet.py b/mpc_demo/mpc_demo_pybullet.py index e60c417..347207b 100644 --- a/mpc_demo/mpc_demo_pybullet.py +++ b/mpc_demo/mpc_demo_pybullet.py @@ -32,6 +32,8 @@ def set_ctrl(robotId,v,w): p.setJointMotorControl2(robotId,1,p.VELOCITY_CONTROL,targetVelocity=rightWheelVelocity,force=1000) def plot(path,x_history,y_history): + """ + """ plt.style.use("ggplot") plt.figure() plt.title("MPC Tracking Results") @@ -42,20 +44,20 @@ def plot(path,x_history,y_history): plt.legend() plt.show() -def do_sim(): +def run_sim(): + """ + """ p.connect(p.GUI) start_offset = [0,2,0] start_orientation = p.getQuaternionFromEuler([0,0,0]) turtle = p.loadURDF("turtlebot.urdf",start_offset, start_orientation) - plane = p.loadURDF("plane.urdf") + p.setRealTimeSimulation(1) p.setGravity(0,0,-10) - state = get_state(turtle) - - # MPC step + # MPC time step dt = 0.25 # starting guess output @@ -73,6 +75,7 @@ def do_sim(): y_history=[] while (1): + state = get_state(turtle) x_history.append(state[0]) y_history.append(state[1]) @@ -99,4 +102,4 @@ def do_sim(): time.sleep(dt-elapsed) if __name__ == '__main__': - do_sim() + run_sim()