Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import rospy
- import time
- from hbp_nrp_virtual_coach.virtual_coach import VirtualCoach
- from ipywidgets import FloatProgress
- from IPython.display import display
- ### Importing custom tools (outcommented as they are not included here)
- #import assemble_data_package as adp
- #import common_utils as cu
- ############## Logging In to local NRP ##############
- vc = VirtualCoach(environment='local', storage_username='nrpuser')
- ################ Simulation Settings ################
- # Which experiment to run
- configName = "name_of_your_experiment_to_clone"
- # How many seconds to run simulation
- run_time = 20
- # Determining which folder the simulation data is saved
- data_package_label = "latest_sim"
- ################# Running simulation #################
- experiment = vc.clone_experiment_to_storage(configName)
- print("\nLaunching Experiment: ",experiment)
- sim = vc.launch_experiment(experiment)
- ################# Starting experiment ################
- sim.start()
- walltime_start = time.time()
- print("\nExperiment started")
- time_started = rospy.Time.now()
- delta_t = rospy.Time.now() - time_started
- f = FloatProgress(min=0, max=run_time) # instantiate the bar
- print("\nSimulating " + str(run_time) + " seconds. \n\n###### Simulation Progress: ######")
- display(f) # display the bar
- offset = rospy.Duration(0)
- first_run = True
- try:
- while delta_t.to_sec() < run_time:
- delta_t = rospy.Time.now() - time_started - offset
- if first_run:
- if delta_t.to_sec() < 0:
- offset = delta_t
- first_runt = False
- #print delta_t.to_sec(), "(Time offset: ",offset.to_sec(), ")"
- f.value = delta_t.to_sec()
- time.sleep(3)
- except KeyboardInterrupt:
- pass
- ##### Pausing and saving CSV files to nrpStorage #####
- sim.pause()
- walltime_end = time.time()
- sim.save_csv()
- sim.stop()
- ########## Saving out data files to package ##########
- # Outcommented use of custom tools as they are not included
- # Purpose here is to save data somewhere else before deleting the cloned directory
- #adp.merge_threads()
- #adp.save_package(experiment, data_package_label, force_overwrite=True)
- ############# Deleting cloned experiment #############
- vc.delete_cloned_experiment(experiment)
- vc.print_cloned_experiments()
- ############ Printing out simulation stats ###########
- print("\nSimulation paused at: " + str(delta_t.to_sec()) + ", executed in " + str(walltime_end - walltime_start) + " sec")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement