Skip to content

Commit

Permalink
Added graphic interface to trajectory implementation"
Browse files Browse the repository at this point in the history
  • Loading branch information
Eli Stavitski authored and Eli Stavitski committed Sep 21, 2016
1 parent bfeb1ee commit c9265d8
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 47 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,4 @@ ENV/

# Rope project settings
.ropeproject
.DS_Store
11 changes: 11 additions & 0 deletions .idea/isstools.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 62 additions & 26 deletions isstools/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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):
Expand Down
10 changes: 8 additions & 2 deletions isstools/trajectory/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,18 @@ 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])



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):
Expand All @@ -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+')
Expand Down
25 changes: 6 additions & 19 deletions isstools/ui/XLive.ui
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="edit_edhe_hi">
<widget class="QLineEdit" name="edit_edge_hi">
<property name="text">
<string>50</string>
</property>
Expand Down Expand Up @@ -275,7 +275,7 @@
</font>
</property>
<property name="text">
<string>Vellocities</string>
<string>Velocities</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -382,7 +382,7 @@
</widget>
</item>
<item row="6" column="1">
<widget class="QLineEdit" name="edit_edhe_hi_6">
<widget class="QLineEdit" name="edit_postedge_stitch_hi">
<property name="text">
<string>100</string>
</property>
Expand Down Expand Up @@ -471,7 +471,7 @@
<property name="geometry">
<rect>
<x>1140</x>
<y>90</y>
<y>80</y>
<width>201</width>
<height>61</height>
</rect>
Expand All @@ -485,8 +485,8 @@
<rect>
<x>700</x>
<y>10</y>
<width>121</width>
<height>81</height>
<width>141</width>
<height>91</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_6">
Expand Down Expand Up @@ -790,19 +790,6 @@
</widget>
</widget>
</widget>
<widget class="QLabel" name="label_38">
<property name="geometry">
<rect>
<x>690</x>
<y>890</y>
<width>16</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>eV</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
Expand Down

0 comments on commit c9265d8

Please sign in to comment.