def __init__(self, extract_from_bags=True): self.setup_openrave() self.use_bags = extract_from_bags self.traj_proc = TrajectoryProcessor(self.env) self.analyzer = TrajectoryAnalyzer(self.env) self.num_samples = 100 # number of points to resample the trajectories # TODO IMPORT FILENAMES AS PARAMETERS self.bag_name = "UnhangHangWithoutHandArtem1" # filename of a bag with demonstration self.action_seg_name = "action_segmentation.txt" # filename with segmentation points between actions self.hold_seg_name_postfix = "_segmentation_holding.txt" # part of a filename (postfix) for each action holding/not holding segmentation points
def __init__(self, extract_from_bags = True): self.setup_openrave() self.use_bags = extract_from_bags self.traj_proc = TrajectoryProcessor(self.env) self.analyzer = TrajectoryAnalyzer(self.env) self.num_samples = 100 # number of points to resample the trajectories # TODO IMPORT FILENAMES AS PARAMETERS self.bag_name = "UnhangHangWithoutHandArtem1" # filename of a bag with demonstration self.action_seg_name = "action_segmentation.txt" # filename with segmentation points between actions self.hold_seg_name_postfix = "_segmentation_holding.txt" # part of a filename (postfix) for each action holding/not holding segmentation points
class TSRExtractor(): def __init__(self, extract_from_bags=True): self.setup_openrave() self.use_bags = extract_from_bags self.traj_proc = TrajectoryProcessor(self.env) self.analyzer = TrajectoryAnalyzer(self.env) self.num_samples = 100 # number of points to resample the trajectories # TODO IMPORT FILENAMES AS PARAMETERS self.bag_name = "UnhangHangWithoutHandArtem1" # filename of a bag with demonstration self.action_seg_name = "action_segmentation.txt" # filename with segmentation points between actions self.hold_seg_name_postfix = "_segmentation_holding.txt" # part of a filename (postfix) for each action holding/not holding segmentation points def setup_openrave(self): print "Setting up the environment..." self.env = openravepy.Environment() self.env.SetViewer('qtcoin') self.env.Reset() self.env.Load('robots/pr2-beta-static.zae') self.robot = self.env.GetRobots()[0] self.robot.SetActiveManipulator("rightarm") T = self.robot.GetTransform() T[0, 3] -= 2 self.robot.SetTransform(T) time.sleep(0.1) def extract_TSR(self, action): nut_points, nut_trans = self.traj_proc.get_positions_and_transforms_from_csv_bag( "bags_csv/" + self.bag_name + "/" + action + "_nut_" + self.bag_name + ".csv") hand_points, hand_trans = self.traj_proc.get_positions_and_transforms_from_csv_bag( "bags_csv/" + self.bag_name + "/" + action + "_hand_" + self.bag_name + ".csv") extractor.traj_proc.draw_points(nut_points, by_point=False) extractor.traj_proc.draw_points(hand_points, by_point=False) sys.stdin.readline() extractor.traj_proc.clear_drawing() if False: holding = self.traj_proc.get_holding_info( "bags_csv/" + self.bag_name + "/" + action + self.hold_seg_name_postfix) # resample trajectories nut_points_resampled, nut_matching = self.traj_proc.resampling_3D_curve( nut_points, self.num_samples) hand_points_resampled, hand_matching = self.traj_proc.resampling_3D_curve( hand_points, self.num_samples) # print nut_matching # print hand_matching # print len(holding) # sys.stdin.readline() # TODO use matching to find these vars nut_trans_resampled = [ nut_trans[nut_matching[i]] for i in range(self.num_samples) ] hand_trans_resampled = [ hand_trans[hand_matching[i]] for i in range(self.num_samples) ] holding_resampled_1 = [ holding[nut_matching[i]] for i in range(self.num_samples) ] holding_resamled_2 = [ holding[hand_matching[i]] for i in range(self.num_samples) ] extractor.traj_proc.draw_points(nut_points_resampled) extractor.traj_proc.draw_points(hand_points_resampled) #extractor.traj_proc.clear_drawing() # run PCA to find segmentation points #self.analyzer.find_segmentation_points(nut_points_resampled, to_plot = True) self.analyzer.find_segmentation_points(hand_points_resampled, to_plot=True) print "segmentation graphs plotted" sys.stdin.readline()
class TSRExtractor(): def __init__(self, extract_from_bags = True): self.setup_openrave() self.use_bags = extract_from_bags self.traj_proc = TrajectoryProcessor(self.env) self.analyzer = TrajectoryAnalyzer(self.env) self.num_samples = 100 # number of points to resample the trajectories # TODO IMPORT FILENAMES AS PARAMETERS self.bag_name = "UnhangHangWithoutHandArtem1" # filename of a bag with demonstration self.action_seg_name = "action_segmentation.txt" # filename with segmentation points between actions self.hold_seg_name_postfix = "_segmentation_holding.txt" # part of a filename (postfix) for each action holding/not holding segmentation points def setup_openrave(self): print "Setting up the environment..." self.env = openravepy.Environment() self.env.SetViewer('qtcoin') self.env.Reset() self.env.Load('robots/pr2-beta-static.zae') self.robot = self.env.GetRobots()[0] self.robot.SetActiveManipulator("rightarm") T = self.robot.GetTransform() T[0, 3] -= 2 self.robot.SetTransform(T) time.sleep(0.1) def extract_TSR(self, action): nut_points, nut_trans = self.traj_proc.get_positions_and_transforms_from_csv_bag("bags_csv/" + self.bag_name + "/" + action + "_nut_" + self.bag_name + ".csv") hand_points, hand_trans = self.traj_proc.get_positions_and_transforms_from_csv_bag("bags_csv/" + self.bag_name + "/" + action + "_hand_" + self.bag_name + ".csv") extractor.traj_proc.draw_points(nut_points, by_point=False) extractor.traj_proc.draw_points(hand_points, by_point=False) sys.stdin.readline() extractor.traj_proc.clear_drawing() if False: holding = self.traj_proc.get_holding_info("bags_csv/" + self.bag_name + "/" + action + self.hold_seg_name_postfix) # resample trajectories nut_points_resampled, nut_matching = self.traj_proc.resampling_3D_curve(nut_points, self.num_samples) hand_points_resampled, hand_matching = self.traj_proc.resampling_3D_curve(hand_points, self.num_samples) # print nut_matching # print hand_matching # print len(holding) # sys.stdin.readline() # TODO use matching to find these vars nut_trans_resampled = [nut_trans[nut_matching[i]] for i in range(self.num_samples)] hand_trans_resampled = [hand_trans[hand_matching[i]] for i in range(self.num_samples)] holding_resampled_1 = [holding[nut_matching[i]] for i in range(self.num_samples)] holding_resamled_2 = [holding[hand_matching[i]] for i in range(self.num_samples)] extractor.traj_proc.draw_points(nut_points_resampled) extractor.traj_proc.draw_points(hand_points_resampled) #extractor.traj_proc.clear_drawing() # run PCA to find segmentation points #self.analyzer.find_segmentation_points(nut_points_resampled, to_plot = True) self.analyzer.find_segmentation_points(hand_points_resampled, to_plot = True) print "segmentation graphs plotted" sys.stdin.readline()