def gen_path(self, trajectory): """Generate the DMPs necessary to follow the specified trajectory. trajectory np.array: the time series of points to follow [DOFs, time], with a column of None wherever the pen should be lifted """ if trajectory.ndim == 1: trajectory = trajectory.reshape(1,len(trajectory)) num_DOF = trajectory.shape[0] # break up the trajectory into its different words # NaN or None signals a new word / break in drawing breaks = np.array(np.where(trajectory[0] != trajectory[0]))[0] self.num_seqs = len(breaks) - 1 self.dmp_sets = [] for ii in range(self.num_seqs): # get the ii'th sequence seq = trajectory[:, breaks[ii]+1:breaks[ii+1]] if self.pattern == 'discrete': dmps = DMP_discrete.DMPs_discrete(dmps=num_DOF, bfs=self.bfs) elif self.pattern == 'rhythmic': dmps = DMP_rhythmic.DMPs_rhythmic(dmps=num_DOF, bfs=self.bfs) else: raise Exception('Invalid pattern type specified. Valid choices \ are discrete or rhythmic.') dmps.imitate_path(y_des=seq) self.dmp_sets.append(dmps) self.dmps = self.dmp_sets[0]
def gen_path(self, trajectory): """Generates the trajectories for the position, velocity, and acceleration to follow during run time to reproduce the given trajectory. trajectory np.array: a list of points to follow """ if trajectory.ndim == 1: trajectory = trajectory.reshape(1, len(trajectory)) dt = 1.0 / trajectory.shape[1] # break up the trajectory into its different words # NaN or None signals a new word / break in drawing breaks = np.where(trajectory != trajectory) # some vector manipulation to get what we want breaks = breaks[1][:len(breaks[1]) / 2] self.num_seqs = len(breaks) - 1 import scipy.interpolate self.seqs_x = [] self.seqs_y = [] for ii in range(self.num_seqs): # get the ii'th sequence seq_x = trajectory[0, breaks[ii] + 1:breaks[ii + 1]] seq_y = trajectory[1, breaks[ii] + 1:breaks[ii + 1]] # generate function to interpolate the desired trajectory vals = np.linspace(0, 1, len(seq_x)) self.seqs_x.append(scipy.interpolate.interp1d(vals, seq_x)) self.seqs_y.append(scipy.interpolate.interp1d(vals, seq_y)) self.trajectory = [self.seqs_x[0], self.seqs_y[0]]
def gen_path(self, trajectory): """Generates the trajectories for the position, velocity, and acceleration to follow during run time to reproduce the given trajectory. trajectory np.array: a list of points to follow """ if trajectory.ndim == 1: trajectory = trajectory.reshape(1,len(trajectory)) dt = 1.0 / trajectory.shape[1] # break up the trajectory into its different words # NaN or None signals a new word / break in drawing breaks = np.where(trajectory != trajectory) # some vector manipulation to get what we want breaks = breaks[1][:len(breaks[1])/2] self.num_seqs = len(breaks) - 1 import scipy.interpolate self.seqs_x = [] self.seqs_y = [] for ii in range(self.num_seqs): # get the ii'th sequence seq_x = trajectory[0, breaks[ii]+1:breaks[ii+1]] seq_y = trajectory[1, breaks[ii]+1:breaks[ii+1]] # generate function to interpolate the desired trajectory vals = np.linspace(0, 1, len(seq_x)) self.seqs_x.append(scipy.interpolate.interp1d(vals, seq_x)) self.seqs_y.append(scipy.interpolate.interp1d(vals, seq_y)) self.trajectory = [self.seqs_x[0], self.seqs_y[0]]
def gen_path(self, trajectory): """Generate the DMPs necessary to follow the specified trajectory. trajectory np.array: the time series of points to follow [DOFs, time], with a column of None wherever the pen should be lifted """ if trajectory.ndim == 1: trajectory = trajectory.reshape(1, len(trajectory)) num_DOF = trajectory.shape[0] # break up the trajectory into its different words # NaN or None signals a new word / break in drawing breaks = np.array(np.where(trajectory[0] != trajectory[0]))[0] self.num_seqs = len(breaks) - 1 self.dmp_sets = [] for ii in range(self.num_seqs): # get the ii'th sequence seq = trajectory[:, breaks[ii] + 1:breaks[ii + 1]] if self.pattern == 'discrete': dmps = DMP_discrete.DMPs_discrete(dmps=num_DOF, bfs=self.bfs) elif self.pattern == 'rhythmic': dmps = DMP_rhythmic.DMPs_rhythmic(dmps=num_DOF, bfs=self.bfs) else: raise Exception( 'Invalid pattern type specified. Valid choices \ are discrete or rhythmic.') dmps.imitate_path(y_des=seq) self.dmp_sets.append(dmps) self.dmps = self.dmp_sets[0]