def callback(): if time.time() >= data['next_sim_time']: sim.simulate(0.01) if sim.controller(0).remainingTime() <= 0: print("Executing timed trajectory") trajectory.execute_trajectory(traj,sim.controller(0),smoothing='pause') vis.setItemConfig("robot",sim.controller(0).getCommandedConfig()) data['next_sim_time'] += 0.01
sim = Simulator(world) sim.simulate(0) trajectory.execute_path(traj.milestones,sim.controller(0)) vis.setWindowTitle("Simulating path using trajectory.execute_trajectory") if vis.multithreaded(): #for some tricky Qt reason, need to sleep before showing a window again #Perhaps the event loop must complete some extra cycles? time.sleep(0.01) vis.show() t0 = time.time() while vis.shown(): #print "Time",sim.getTime() sim.simulate(0.01) if sim.controller(0).remainingTime() <= 0: print("Executing timed trajectory") trajectory.execute_trajectory(traj,sim.controller(0),smoothing='pause') vis.setItemConfig("robot",sim.controller(0).getCommandedConfig()) t1 = time.time() time.sleep(max(0.01-(t1-t0),0.0)) t0 = t1 else: data = {'next_sim_time':time.time()} def callback(): if time.time() >= data['next_sim_time']: sim.simulate(0.01) if sim.controller(0).remainingTime() <= 0: print("Executing timed trajectory") trajectory.execute_trajectory(traj,sim.controller(0),smoothing='pause') vis.setItemConfig("robot",sim.controller(0).getCommandedConfig()) data['next_sim_time'] += 0.01 vis.loop(callback=callback,setup=vis.show)