Advertisement
jakobwelner

Virtual Coach NRP simulation setup

Sep 8th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.48 KB | None | 0 0
  1. import rospy
  2. import time
  3. from hbp_nrp_virtual_coach.virtual_coach import VirtualCoach
  4. from ipywidgets import FloatProgress
  5. from IPython.display import display
  6.  
  7. ### Importing custom tools (outcommented as they are not included here)
  8. #import assemble_data_package as adp
  9. #import common_utils as cu
  10.  
  11.  
  12. ############## Logging In to local NRP ##############
  13. vc = VirtualCoach(environment='local', storage_username='nrpuser')
  14.  
  15.  
  16. ################ Simulation Settings ################
  17. # Which experiment to run
  18. configName = "name_of_your_experiment_to_clone"
  19.  
  20. # How many seconds to run simulation
  21. run_time = 20
  22.  
  23. # Determining which folder the simulation data is saved
  24. data_package_label = "latest_sim"
  25.  
  26.  
  27.  
  28. ################# Running simulation #################
  29. experiment = vc.clone_experiment_to_storage(configName)
  30. print("\nLaunching Experiment: ",experiment)
  31. sim = vc.launch_experiment(experiment)
  32.  
  33.  
  34. ################# Starting experiment ################
  35. sim.start()
  36. walltime_start = time.time()
  37. print("\nExperiment started")
  38.  
  39. time_started = rospy.Time.now()
  40. delta_t = rospy.Time.now() - time_started
  41.  
  42. f = FloatProgress(min=0, max=run_time) # instantiate the bar
  43.  
  44. print("\nSimulating " + str(run_time) + " seconds. \n\n###### Simulation Progress: ######")
  45. display(f) # display the bar
  46.  
  47. offset = rospy.Duration(0)
  48. first_run = True
  49. try:
  50.     while delta_t.to_sec() < run_time:
  51.         delta_t = rospy.Time.now() - time_started - offset
  52.        
  53.         if first_run:
  54.             if delta_t.to_sec() < 0:
  55.                 offset = delta_t
  56.             first_runt = False
  57.            
  58.         #print delta_t.to_sec(), "(Time offset: ",offset.to_sec(), ")"
  59.         f.value = delta_t.to_sec()
  60.         time.sleep(3)
  61. except KeyboardInterrupt:
  62.     pass
  63.  
  64.  
  65. ##### Pausing and saving CSV files to nrpStorage #####
  66. sim.pause()
  67. walltime_end = time.time()
  68.  
  69. sim.save_csv()
  70. sim.stop()
  71.  
  72.  
  73. ########## Saving out data files to package ##########
  74. # Outcommented use of custom tools as they are not included
  75. # Purpose here is to save data somewhere else before deleting the cloned directory
  76. #adp.merge_threads()
  77. #adp.save_package(experiment, data_package_label, force_overwrite=True)
  78.  
  79. ############# Deleting cloned experiment #############
  80. vc.delete_cloned_experiment(experiment)
  81. vc.print_cloned_experiments()
  82.  
  83. ############ Printing out simulation stats ###########
  84. 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