From c9265d8bfbffcfb4384b82ecf21916bd80896197 Mon Sep 17 00:00:00 2001 From: Eli Stavitski Date: Tue, 20 Sep 2016 21:55:07 -0400 Subject: [PATCH] Added graphic interface to trajectory implementation" --- .gitignore | 1 + .idea/isstools.iml | 11 ++++ .idea/misc.xml | 14 +++++ .idea/modules.xml | 8 +++ isstools/gui.py | 88 ++++++++++++++++++++++--------- isstools/trajectory/trajectory.py | 10 +++- isstools/ui/XLive.ui | 25 +++------ 7 files changed, 110 insertions(+), 47 deletions(-) create mode 100644 .idea/isstools.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml diff --git a/.gitignore b/.gitignore index 72364f99..a04fc858 100644 --- a/.gitignore +++ b/.gitignore @@ -87,3 +87,4 @@ ENV/ # Rope project settings .ropeproject +.DS_Store diff --git a/.idea/isstools.iml b/.idea/isstools.iml new file mode 100644 index 00000000..08bd4824 --- /dev/null +++ b/.idea/isstools.iml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..559ad2b6 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..a933d569 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/isstools/gui.py b/isstools/gui.py index b0637539..69144c78 100644 --- a/isstools/gui.py +++ b/isstools/gui.py @@ -30,22 +30,34 @@ def __init__(self, plan_func, parent=None): super().__init__(parent) self.plan_func = plan_func self.setupUi(self) - self.fig = fig = self.figure_content() - self.addCanvas(fig) + #self.fig = fig = self.figure_content() + self.addCanvas() self.run_start.clicked.connect(self.test) self.push_build_trajectory.clicked.connect(self.build_trajectory) self.push_save_trajectory.clicked.connect(self.save_trajectory) - def addCanvas(self, fig): - self.canvas = FigureCanvas(fig) - - self.toolbar = NavigationToolbar(self.canvas, - self.tab_2, coordinates=True) - self.toolbar.setMaximumHeight(18) + def addCanvas(self): + self.figure = Figure() + self.canvas = FigureCanvas(self.figure) + self.toolbar = NavigationToolbar(self.canvas, self.tab_2, coordinates=True) + self.toolbar.setMaximumHeight(25) self.plots.addWidget(self.toolbar) self.plots.addWidget(self.canvas) self.canvas.draw() + self.figure_single_trajectory = Figure() + self.figure_single_trajectory.set_facecolor(color='0.89') + self.canvas_single_trajectory = FigureCanvas(self.figure_single_trajectory) + self.plot_single_trajectory.addWidget(self.canvas_single_trajectory) + self.canvas_single_trajectory.draw() + + self.figure_full_trajectory= Figure() + self.figure_full_trajectory.set_facecolor(color='0.89') + self.canvas_full_trajectory = FigureCanvas(self.figure_full_trajectory) + self.plot_full_trajectory.addWidget(self.canvas_full_trajectory) + self.plot_full_trajectory.addWidget(self.canvas_full_trajectory) + self.canvas_full_trajectory.draw() + @property def plot_x(self): return self.plot_selection_dropdown.value() @@ -61,33 +73,57 @@ def figure_content(self): def build_trajectory(self): E0 = int(self.edit_E0.text()) - preedge_lo = int(self.edit_preedge_lo.text()) preedge_hi = int(self.edit_preedge_hi.text()) - edge_lo = preedge_hi edge_hi = int(self.edit_edge_hi.text()) - postedge_lo = edge_hi postedge_hi = int(self.edit_postedge_hi.text()) - velocity_preedge = int (self.velocity_preedge.text()) - velocity_edge = int(self.velocity_edge.text()) - velocity_postedge = int(self.velocity_postedge.text()) + velocity_preedge = int (self.edit_velocity_preedge.text()) + velocity_edge = int(self.edit_velocity_edge.text()) + velocity_postedge = int(self.edit_velocity_postedge.text()) - preedge_stitch_lo = int(self.preedge_stitch_lo.text()) - preedge_stitch_hi = int(self.preedge_stitch_hi.text()) - edge_stitch_lo = int(self.edge_stitch_lo.text()) - edge_stitch_hi = int(self.edge_stitch_hi.text()) - postedge_stitch_lo = int(self.postedge_stitch_lo.text()) - postedge_stitch_hi = int(self.postedge_stitch_hi.text()) + preedge_stitch_lo = int(self.edit_preedge_stitch_lo.text()) + preedge_stitch_hi = int(self.edit_preedge_stitch_hi.text()) + edge_stitch_lo = int(self.edit_edge_stitch_lo.text()) + edge_stitch_hi = int(self.edit_edge_stitch_hi.text()) + postedge_stitch_lo = int(self.edit_postedge_stitch_lo.text()) + postedge_stitch_hi = int(self.edit_postedge_stitch_hi.text()) - padding_preedge = int(self.padding_preedge.text()) - padding_postedge = int(self.padding_postedge.text()) + padding_preedge = int(self.edit_padding_preedge.text()) + padding_postedge = int(self.edit_padding_postedge.text()) - traj=trajectory(edge_energy = E0, offsets = ([preedge_lo,preedge_hi,edge_hi,postedge_hi]),velocities = ([velocity_preedge, velocity_edge, velocity_postedge]), - stitching = ([preedge_stitch_lo, preedge_stitch_hi, edge_stitch_lo, edge_stitch_hi, postedge_stitch_lo, postedge_stitch_hi]), + #Create and interpolate trajectory + traj = trajectory() + traj.define(edge_energy = E0, offsets = ([preedge_lo,preedge_hi,edge_hi,postedge_hi]),velocities = ([velocity_preedge, velocity_edge, velocity_postedge]),\ + stitching = ([preedge_stitch_lo, preedge_stitch_hi, edge_stitch_lo, edge_stitch_hi, postedge_stitch_lo, postedge_stitch_hi]),\ servocycle = 16000, padding_lo = padding_preedge ,padding_hi=padding_postedge) - - def save_trajectory(selfself): + traj.interpolate() + + #Plot single trajectory motion + ax = self.figure_single_trajectory.add_subplot(111) + ax.hold(False) + ax.plot(traj.time, traj.energy, 'r*') + ax.hold(True) + ax.plot(traj.time_grid, traj.energy_grid, 'b') + ax.set_xlabel('Time /s') + ax.set_ylabel('Energy /eV') + ax2 = ax.twinx() + ax2.hold(False) + ax2.plot(traj.time_grid[0:-1], traj.energy_grid_der, 'r') + self.canvas_single_trajectory.draw() + + # Tile trajectory + traj.tile(reps=5) + ax = self.figure_full_trajectory.add_subplot(111) + ax.hold(False) + ax.plot(traj.energy_grid, 'b') + ax.set_xlabel('Servo event / 1/16000 s') + ax.set_ylabel('Encoder count') + self.canvas_full_trajectory.draw() + + + + def save_trajectory(self): pass def test(self): diff --git a/isstools/trajectory/trajectory.py b/isstools/trajectory/trajectory.py index 5808b381..2bb349dc 100644 --- a/isstools/trajectory/trajectory.py +++ b/isstools/trajectory/trajectory.py @@ -62,8 +62,10 @@ def define(self, edge_energy = 11564, offsets = ([-200,-30,50,1000]),velocities e_padding_hi = postedge_hi+20 # concatenate the arrays - self.time = np.array([t_padding_lo, t_preedge_lo, t_preedge_hi, t_edge_lo, t_edge_hi, t_postedge_lo, t_postedge_hi, t_padding_hi]) - self.energy = np.array([e_padding_lo, e_preedge_lo, e_preedge_hi, e_edge_lo, e_edge_hi, e_postedge_lo, e_postedge_hi,e_padding_hi]) + self.time = np.array([t_padding_lo, t_preedge_lo, t_preedge_hi, \ + t_edge_lo, t_edge_hi, t_postedge_lo, t_postedge_hi, t_padding_hi]) + self.energy = np.array([e_padding_lo, e_preedge_lo, e_preedge_hi,\ + e_edge_lo, e_edge_hi, e_postedge_lo, e_postedge_hi,e_padding_hi]) @@ -71,6 +73,7 @@ def interpolate(self): cs = interpolate.CubicSpline(self.time,self.energy, bc_type='clamped') self.time_grid = np.arange(self.time[0], self.time[-1], 1 / self.servocycle) self.energy_grid=cs(self.time_grid) + self.energy_grid_der=np.diff(self.energy_grid) def tile (self,reps = 1): @@ -79,6 +82,9 @@ def tile (self,reps = 1): self.time_grid = np.tile(self.time_grid, reps) self.energy_grid = np.tile(self.energy_grid, reps) + def e2encoder(self): + self.encoder_grid=[] + def plot(self): plt.plot(self.time, self.energy, 'r+') diff --git a/isstools/ui/XLive.ui b/isstools/ui/XLive.ui index d81c4b62..5a420db4 100644 --- a/isstools/ui/XLive.ui +++ b/isstools/ui/XLive.ui @@ -84,7 +84,7 @@ - + 50 @@ -275,7 +275,7 @@ - Vellocities + Velocities @@ -382,7 +382,7 @@ - + 100 @@ -471,7 +471,7 @@ 1140 - 90 + 80 201 61 @@ -485,8 +485,8 @@ 700 10 - 121 - 81 + 141 + 91 @@ -790,19 +790,6 @@ - - - - 690 - 890 - 16 - 21 - - - - eV - -