helpers.py
Go to the documentation of this file.
00001 import rospy
00002 import hrl_lib
00003 import yaml
00004 import os
00005 node_name = "overhead_grasping"
00006 
00007 ARM = 0 # right arm
00008 
00009 PRESSURE_LIST =["r_finger_periph_pressure", 
00010                 "r_finger_pad_pressure", 
00011                 "l_finger_periph_pressure",
00012                 "l_finger_pad_pressure"]
00013 
00014 class FileOperations():
00015     def __init__(self):
00016         grep = os.popen("rospack find pr2_overhead_grasping|grep pr2_overhead_grasping")
00017         self.package_loc = grep.readlines()[0].rstrip()
00018     
00019     def load_pickle(self, fn):
00020         return hrl_lib.util.load_pickle(self.package_loc + "//pickles//" + fn)
00021 
00022     def save_pickle(self, p, fn):
00023         hrl_lib.util.save_pickle(p, self.package_loc + "//pickles//" + fn)
00024 
00025     def get_pickle_name(self, fn):
00026         return self.package_loc + "//pickles//" + fn
00027 
00028     def file_exists(self, fn):
00029         return os.path.exists(self.package_loc + "//pickles//" + fn)
00030     
00031     def get_plot_name(self, directory, gfn):
00032         filename = (self.package_loc + "//plots//" + directory + "//" +
00033                     gfn.split(".")[0].split("//")[-1] + ".pdf")
00034         return filename
00035 
00036     def load_coll_times(self, loc):
00037         ct_index_fn = (self.package_loc + "//pickles//" + 
00038                        loc + "//collision_times.yaml")
00039         stream = file(ct_index_fn, "r")
00040         coll_times = yaml.load(stream)
00041         return coll_times
00042 
00043     def save_coll_times(self, coll_times, loc):
00044         ct_index_fn = (self.package_loc + "//pickles//" + 
00045                        loc + "//collision_times.yaml")
00046         stream = file(ct_index_fn, "w")
00047         yaml.dump(coll_times, stream)
00048 
00049     def load_yaml_file(self, fn):
00050         ct_index_fn = (self.package_loc + "//yaml//" + fn)
00051         stream = file(ct_index_fn, "r")
00052         coll_times = yaml.load(stream)
00053         return coll_times
00054 
00055     def make_directories(self, directory):
00056         try:
00057             os.mkdir(self.package_loc + "//plots")
00058         except:
00059             pass
00060         try:
00061             os.mkdir(self.package_loc + "//plots//" + directory)
00062         except:
00063             pass
00064         try:
00065             os.mkdir(self.package_loc + "//pickles")
00066         except:
00067             pass
00068         try:
00069             os.mkdir(self.package_loc + "//pickles//collision_data")
00070         except:
00071             pass
00072         try:
00073             os.mkdir(self.package_loc + "//pickles//collision_data//" + directory)
00074         except:
00075             pass
00076         try:
00077             os.mkdir(self.package_loc + "//arff_files")
00078         except:
00079             pass
00080         try:
00081             os.mkdir(self.package_loc + "//pickles//classifiers")
00082         except:
00083             pass
00084  
00085 
00086 def log(*strs):
00087     prstrs = ""
00088     for s in strs:
00089         prstrs += str(s) + " "
00090     rospy.loginfo(node_name + ": " + prstrs)
00091 
00092 def err(*strs):
00093     prstrs = ""
00094     for s in strs:
00095         prstrs += str(s) + " "
00096     rospy.logerr(node_name + ": " + prstrs)
00097 
00098 def wait_for_key(ki, key='c'):
00099     ch = None
00100     while not rospy.is_shutdown() and ch != key:
00101         ch = ki.getch()
00102         rospy.sleep(0.1)
00103     log("CONTINUING")


kelsey_sandbox
Author(s): kelsey
autogenerated on Wed Nov 27 2013 11:52:03