diff --git a/.gitignore b/.gitignore deleted file mode 100644 index ac43ebc..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.pyc -*.py~ diff --git a/PiBeamProfiler.py b/PiBeamProfiler.py old mode 100755 new mode 100644 index ab6d8a5..a67f75c --- a/PiBeamProfiler.py +++ b/PiBeamProfiler.py @@ -23,252 +23,410 @@ import numpy as np from scipy.misc.pilutil import toimage from scipy.optimize import curve_fit -import time, sys +import time +import sys import cv2 +#Changed: Added a function to make the initial width guess more efficient andd added more data points used +#Seems to work better on the raspberry pi class proflayout(QtGui.QWidget): def __init__(self): super(proflayout, self).__init__() - self.zoom = 1 - self.imageres = [640,480] - desktop = QtGui.QDesktopWidget() - screensize = desktop.availableGeometry() - self.screenres = [screensize.width(),screensize.height()] - - # initialize the camera - self.camera = PiCamera() - - #set camera resolution, gain , sutter speed and framerate - self.camera.resolution = (self.imageres[0], self.imageres[1]) - self.camera.framerate = 33 # in Hz - self.camera.shutter_speed = 500 # in us - self.camera.exposure_mode = 'off' - self.camera.iso = 300 - - #grab a reference to the raw camera capture - self.rawCapture = PiRGBArray(self.camera, size=(640, 480)) - - # allow the camera to warmup - time.sleep(0.1) - self.initializeGUI() + self.imageres = [640, 480] + self.zoom = 1 + self.getzoomgaps() + self.fitting = True + self.breakloop = False + desktop = QtGui.QDesktopWidget() + screensize = desktop.availableGeometry() + self.screenres = [screensize.width(), screensize.height()] + self.initCamera() + self.initializeGUI() + + def initCamera(self): + # initialize the camera + self.camera = PiCamera() + # set camera resolution, gain , sutter speed and framerate + self.camera.resolution = (self.imageres[0], self.imageres[1]) + self.camera.framerate = 33 # in Hz + self.camera.shutter_speed = 100 # in us + self.camera.exposure_mode = 'off' + self.camera.iso = 300 + + # grab a reference to the raw camera capture + self.rawCapture = PiRGBArray(self.camera, size=(self.imageres[0], + self.imageres[1])) + + # allow the camera to warmup + time.sleep(0.1) def initializeGUI(self): self.setWindowTitle('Beam Profiler') - self.setGeometry(0, 0, self.screenres[0], self.screenres[1]) + self.setGeometry(0, 0, self.screenres[0], self.screenres[1]) layout = QtGui.QGridLayout() - self.setupPlots() - - self.expslider = QtGui.QSlider(QtCore.Qt.Vertical) - self.expslider.setSingleStep(1) - self.explabel = QtGui.QLabel('Exposure') - self.expbar = QtGui.QProgressBar() - self.expbar.setOrientation(QtCore.Qt.Vertical) - self.expbar.setValue(65) - self.videowindow = QtGui.QLabel(self) - - self.xwaist = QtGui.QLabel() - self.ywaist = QtGui.QLabel() - self.xwaist.setStyleSheet('color: #FF6600; font-weight: bold; font-family: Copperplate / Copperplate Gothic Light, sans-serif') - self.ywaist.setStyleSheet('color: #FF6600; font-weight: bold; font-family: Copperplate / Copperplate Gothic Light, sans-serif') - self.zoominbutton = QtGui.QPushButton('Zoom In') - self.zoomoutbutton = QtGui.QPushButton('Zoom Out') - buttonsize = [int(self.screenres[1]/4 ), int(self.screenres[1]/2)] - self.highresbutton = QtGui.QPushButton('1024x768') - self.lowresbutton = QtGui.QPushButton('640x480') - self.highresbutton.setCheckable(True) - self.lowresbutton.setCheckable(True) - self.lowresbutton.setChecked(True) - self.highresbutton.setFixedSize(buttonsize[0],buttonsize[1]) - self.lowresbutton.setFixedSize(buttonsize[0],buttonsize[1]) - self.zoominbutton.setFixedSize(buttonsize[0],buttonsize[1]) - self.zoomoutbutton.setFixedSize(buttonsize[0],buttonsize[1]) - self.zoominbutton.toggled.connect(self.zoomin) - self.setupPlots() + self.createPlots() + self.setupPlots() + + self.expslider = QtGui.QSlider(QtCore.Qt.Vertical) + self.expslider.setSingleStep(1) + self.explabel = QtGui.QLabel('Exposure') + self.expbar = QtGui.QProgressBar() + self.expbar.setOrientation(QtCore.Qt.Vertical) + self.expbar.setValue(65) + self.videowindow = QtGui.QLabel(self) + + self.xwaist = QtGui.QLabel() + self.ywaist = QtGui.QLabel() + font = 'color: #FF6600; font-weight: bold; font-family: Copperplate / Copperplate Gothic Light, sans-serif' + self.xwaist.setStyleSheet(font) + self.ywaist.setStyleSheet(font) + self.zoominbutton = QtGui.QPushButton('Zoom In') + self.zoomoutbutton = QtGui.QPushButton('Zoom Out') + buttonsize = [int(self.screenres[1]/8), int(self.screenres[1]/4)] + self.highresbutton = QtGui.QPushButton('1296x972') + self.lowresbutton = QtGui.QPushButton('640x480') + self.highresbutton.setCheckable(True) + self.lowresbutton.setCheckable(True) + self.lowresbutton.setChecked(True) + self.highresbutton.setFixedSize(buttonsize[0], buttonsize[1]) + self.lowresbutton.setFixedSize(buttonsize[0], buttonsize[1]) + self.zoominbutton.setFixedSize(buttonsize[0], buttonsize[1]) + self.zoomoutbutton.setFixedSize(buttonsize[0], buttonsize[1]) + self.zoominbutton.toggled.connect(self.zoomin) + self.setupPlots() self.canvasrow = FigureCanvas(self.figurerow) - self.canvascolumn = FigureCanvas(self.figurecolumn) - - self.expslider.valueChanged[int].connect(self.changeExposure) - self.zoominbutton.clicked.connect(self.zoomin) - self.zoomoutbutton.clicked.connect(self.zoomout) - self.lowresbutton.clicked.connect(self.lowres) - self.highresbutton.clicked.connect(self.highres) - - layout.addWidget(self.videowindow, 0,0,2,1) - layout.addWidget(self.canvasrow, 2,0,2,1) - layout.addWidget(self.canvascolumn, 0,1,2,1) - layout.addWidget(self.expbar, 0,4,2,1) - #withholds these widgets for tiny screens - if not (self.screenres[0] or self.screenres[1] <= 400): - layout.addWidget(self.lowresbutton, 0,2) - layout.addWidget(self.highresbutton, 1,2) - layout.addWidget(self.zoominbutton, 0,3) - layout.addWidget(self.zoomoutbutton, 1,3) - layout.addWidget(self.expslider, 0,5,2,1) - layout.addWidget(self.xwaist, 2,1) - layout.addWidget(self.ywaist, 3,1) + self.canvascolumn = FigureCanvas(self.figurecolumn) + + self.expslider.valueChanged[int].connect(self.changeExposure) + self.zoominbutton.clicked.connect(self.zoomin) + self.zoomoutbutton.clicked.connect(self.zoomout) + self.lowresbutton.clicked.connect(self.lowres) + self.highresbutton.clicked.connect(self.highres) + + layout.addWidget(self.videowindow, 0, 0, 2, 1) + layout.addWidget(self.canvasrow, 2, 0, 2, 1) + layout.addWidget(self.canvascolumn, 0, 1, 2, 1) + layout.addWidget(self.expbar, 0, 4, 2, 1) + # withholds these widgets for tiny screens + print self.screenres + if not ((self.screenres[0] or self.screenres[1]) <= 400): + layout.addWidget(self.lowresbutton, 1, 2) + layout.addWidget(self.highresbutton, 1, 3) + layout.addWidget(self.zoominbutton, 0, 3) + layout.addWidget(self.zoomoutbutton, 0, 2) + layout.addWidget(self.expslider, 0, 5, 2, 1) + layout.addWidget(self.xwaist, 2, 1, 1, 3) + layout.addWidget(self.ywaist, 3, 1, 1, 3) self.setLayout(layout) def startCamera(self): - # capture frames from the camera - for frame in self.camera.capture_continuous(self.rawCapture, format="bgr", use_video_port=True): - - # grab the raw NumPy array representing the image - image = frame.array - - #take the green part of the image - greenimage = image[:,:,1] - globmax = np.max(greenimage) - - #cv2 thingy - key = cv2.waitKey(1) & 0xFF - - #create array for plotting with the number of pixels in each axis - xpixels = np.linspace(0,len(greenimage[0,:]),len(greenimage[0,:])) - ypixels = np.linspace(0,len(greenimage[:,0]),len(greenimage[:,0])) - - #row and colum sum for live plots - columnsum = greenimage.sum(axis=1)/40.0 - rowsum = greenimage.sum(axis=0)/40.0 - - #subtract minumum value (background subtraction) - columnsum = columnsum - np.min(columnsum) - rowsum = rowsum - np.min(rowsum) - - #Init Guess for fitting - columnampguess = columnsum.max() - columncenterguess = np.argmax(columnsum[::-1]) - - rowampguess = rowsum.max() - rowcenterguess = np.argmax(rowsum) - percexp = 100 * globmax/255.0 - self.expbar.setValue(percexp) - - #Curve fit rowsum and column sum to gaussian, fit parameters returned in popt1/2 - try: - popt1, pcov1 = curve_fit(self.func, xpixels, rowsum, p0=[rowampguess,rowcenterguess,200]) - popt2, pcov2 = curve_fit(self.func, ypixels, columnsum[::-1], p0=[columnampguess,columncenterguess,200]) - - except: - popt1, popt2 = [[0,0,1], [0,0,1]] - - #updates data for row and column plots, also mirrors column data - self.linesrow.set_xdata(xpixels) - self.linesrow.set_ydata(rowsum) - - self.linescolumn.set_xdata(columnsum[::-1]) - self.linescolumn.set_ydata(ypixels) - - #updates data for fit row and column plots - self.linesrowfit.set_xdata(xpixels) - self.linesrowfit.set_ydata(self.func(xpixels, popt1[0],popt1[1],popt1[2])) - - self.linescolumnfit.set_xdata(self.func(ypixels, popt2[0],popt2[1],popt2[2])) - self.linescolumnfit.set_ydata(ypixels) - - - #draw data and flush - self.figurerow.canvas.draw() - self.figurerow.canvas.flush_events() + # capture frames from the camera + + for frame in self.camera.capture_continuous(self.rawCapture, + format="bgr", + use_video_port=True): + + # grab the raw NumPy array representing the imagef + image = frame.array + np.nan_to_num(image) + + # take the green part of the image + greenimage = image[:, :, 1] + globmax = np.max(greenimage) + + # cv2 thingy + key = cv2.waitKey(1) & 0xFF + + # row and colum sum for live plots + columnsum = greenimage.sum(axis=1)/40.0 + columnsum = columnsum[::-1] + rowsum = greenimage.sum(axis=0)/40.0 + + # subtract minumum value (background subtraction) + columnsum = columnsum - np.min(columnsum) + rowsum = rowsum - np.min(rowsum) + columnampguess = columnsum.max() + columncenterguess = np.argmax(columnsum) + + rowampguess = rowsum.max() + rowcenterguess = np.argmax(rowsum) + percexp = 100 * globmax/255.0 + self.expbar.setValue(percexp) + + rowampguess = rowsum.max() + rowcenterguess = np.argmax(columnsum) + #******************************************************************** + # Added Things + #******************************************************************** + #coarsen function returns an array + # Why is coarsecolumny and coarserowx just there? what purpose does it have? + coarsecolumny , coarsecolumnx = self.coarsen(self.ypixels, columnsum, 1) + coarserowx, coarserowy = self.coarsen(self.xpixels, rowsum, 1) + + coarsecolumny = np.nan_to_num(coarsecolumny) + coarsecolumnx = np.nan_to_num(coarsecolumnx) + coarserowy = np.nan_to_num(coarserowy) + coarserowx = np.nan_to_num(coarserowx) + columnampguess = coarsecolumnx.max() + columncenterguess = np.argmax(coarsecolumnx) + + #obtain indices in x array to obtain x value when y=1/e**2 + rowx_e2 = self.closest(coarserowy, np.exp(-2)) + columnx_e2 = self.closest(coarsecolumny, np.exp(-2)) + + # coarsecolumnx uses the index associated with the 1/e**2 value to find x value + #multiply x value by 2 to find the width diameter + columnwidthguess = 2*coarsecolumnx[columnx_e2] + rowwidthguess = 2*coarserowx[rowx_e2] + + #********************************************************************* + # End of changed stuff + #********************************************************************* + #the units are adjusted for later in the code + if self.fitting is True: + try: + p0 = [rowampguess, rowcenterguess, rowwidthguess] + popt1, pcov1 = curve_fit(self.gaussian, coarserowx, + coarserowy, p0=p0) + except: + popt1 = [0, 0, 1] + + try: + p0 = [columnampguess, columncenterguess, columnwidthguess] + popt2, pcov2 = curve_fit(self.gaussian, coarsecolumny, + coarsecolumnx, p0=p0) + except: + popt2 = [0, 0, 1] + else: + popt1, popt2 = [[0, 0, 1], [0, 0, 1]] + + # updates data for row and column plots, also mirrors column data + self.linesrow.set_xdata(coarserowx) + self.linesrow.set_ydata(coarserowy) + + self.linescolumn.set_xdata(coarsecolumnx) + self.linescolumn.set_ydata(coarsecolumny) + + # updates data for fit row and column plots + + self.linesrowfit.set_xdata(coarserowx) + y_data = self.gaussian(coarserowx, popt1[0], popt1[1], popt1[2]) + self.linesrowfit.set_ydata(y_data) + + x_data = self.gaussian(coarsecolumny, popt2[0], popt2[1], popt2[2]) + self.linescolumnfit.set_xdata(x_data) + self.linescolumnfit.set_ydata(coarsecolumny) + + # draw data and flush + self.figurerow.canvas.draw() + self.figurerow.canvas.flush_events() + + self.figurecolumn.canvas.draw() + self.figurecolumn.canvas.flush_events() + #**************************************************************************************************** + # Added things -> Forced this too be correct by embedding the 8 factor + #**************************************************************************************************** + # update X and Y waist labels with scaled waists + x_diameter = self.get_beam_diameter(w_I=popt1[2]) + text_ending = 'um, 1/e**2 Int. diam.' + x_text = 'X = ' + str(x_diameter)[0:5] + text_ending + self.xwaist.setText(x_text) + y_diameter = self.get_beam_diameter(w_I=popt2[2]) + y_text = 'Y = ' + str(y_diameter)[0:5] + text_ending + self.ywaist.setText(y_text) + + # convert RGB image np array to qPixmap and update canvas widget + image = image[int(self.gaprow):self.imageres[0] - int(self.gaprow),int(self.gapcolumn):self.imageres[1] - int(self.gapcolumn)] + qPixmap = self.nparrayToQPixmap(image) + videoy = int(self.screenres[0]/2.1) + videox = int(1.333 * videoy) + self.videowindow.setPixmap(qPixmap.scaled(videox, videoy)) + + # clear the stream in preparation for the next frame + self.rawCapture.truncate(0) + + def get_beam_diameter(self, w_I): + """ + Return the 1/e**2 beam diameter in micrometers. + Parameters + ---------- + w_I: float, the 1/e beam radius in pixels + Returns + ------- + float + """ + w_I_um = self.convert_scaled_pixels_to_um(value=w_I) + beam_diameter = np.abs(2. * np.sqrt(2.) * w_I_um) + return beam_diameter + + def convert_scaled_pixels_to_um(self, value): + """ + Converts a camera pixel value that could be scaled by the resolution + to a value in micrometers. + Parameters + ---------- + value: float, value in scaled pixels + Returns + ------- + float + + #************************************************************************************************************ + # This function might be producing the change in the size + #************************************************************************************************************ + + """ + # Set the resolution scaling factor. + # if self.imageres[0] == 640: + # resolution_factor = 2 + # else: + # resolution_factor = 1 + + pixels_to_um_conversion_factor = 5.875 #1.18 possible other conversion + return pixels_to_um_conversion_factor * value + + def createPlots(self): + + # Set up plot axes and figure positions + self.figurerow, self.axrow = plt.subplots() - self.figurecolumn.canvas.draw() - self.figurecolumn.canvas.flush_events() + self.figurecolumn, self.axcolumn = plt.subplots() - #update X and Y waist labels with scaled waists - self.xwaist.setText('X = ' + str(np.abs(popt1[2]*2*5.875))[0:5] + 'um') - self.ywaist.setText('Y = ' +str(np.abs(popt2[2]*2*5.875))[0:5] + 'um') + # Create line objects for fast plot redrawing + self.linesrow, = self.axrow.plot([], [], linewidth=2, color='purple') + self.linesrowfit, = self.axrow.plot([], [], linestyle='--', linewidth=2, color='yellow') - # convert RGB image np array to qPixmap and update canvas widget - qPixmap = self.nparrayToQPixmap(image) - videoy = int(self.screenres[0]/2.1) - videox = int(1.333 * videoy) - self.videowindow.setPixmap(qPixmap.scaled(videox,videoy)) - - # clear the stream in preparation for the next frame - self.rawCapture.truncate(0) + self.linescolumn, = self.axcolumn.plot([], [], linewidth=2, color='purple') + self.linescolumnfit, = self.axcolumn.plot([], [], linestyle='--', linewidth=2, color='yellow') def setupPlots(self): - #Set up plot axes and figure positions - self.figurerow, self.axrow = plt.subplots() - #self.figurerow.gca().set_position([0,0,1,1]) - - self.figurecolumn, self.axcolumn = plt.subplots() - #self.figurecolumn.gca().set_position([0,0,1,1]) - - #Create line objects for fast plot redrawing - self.linesrow, = self.axrow.plot([],[],linewidth=2,color='purple') - self.linesrowfit, = self.axrow.plot([],[],linestyle='--',linewidth=2,color='yellow') - - self.linescolumn, = self.axcolumn.plot([],[],linewidth=2,color='purple') - self.linescolumnfit, = self.axcolumn.plot([],[],linestyle='--',linewidth=2,color='yellow') + self.xpixels = np.linspace(0, self.imageres[0], self.imageres[0]) + self.ypixels = np.linspace(0, self.imageres[1], self.imageres[1]) self.axrow.set_xlim(0, self.imageres[0]) - self.axrow.set_ylim(0,300) + self.axrow.set_ylim(0, 300) self.axcolumn.set_xlim(0, 300) - self.axcolumn.set_ylim(0,self.imageres[1]) + self.axcolumn.set_ylim(0, self.imageres[1]) - self.axrow.xaxis.set_ticks_position('none') - self.axrow.yaxis.set_ticks_position('none') - self.axrow.get_xaxis().set_visible(False) - self.axrow.get_yaxis().set_visible(False) - self.axrow.patch.set_visible(False) + self.axrow.xaxis.set_ticks_position('none') + self.axrow.yaxis.set_ticks_position('none') + self.axrow.get_xaxis().set_visible(False) + self.axrow.get_yaxis().set_visible(False) + self.axrow.patch.set_visible(False) - self.axcolumn.xaxis.set_ticks_position('none') - self.axcolumn.yaxis.set_ticks_position('none') - self.axcolumn.get_xaxis().set_visible(False) - self.axcolumn.get_yaxis().set_visible(False) - self.axcolumn.patch.set_visible(False) + self.axcolumn.xaxis.set_ticks_position('none') + self.axcolumn.yaxis.set_ticks_position('none') + self.axcolumn.get_xaxis().set_visible(False) + self.axcolumn.get_yaxis().set_visible(False) + self.axcolumn.patch.set_visible(False) def changeExposure(self, value): - scaledvalue = 0.5 * value**2 + 1 - self.camera.shutter_speed = int(scaledvalue) - - #gaussian function used in fitting routine - def func(self, x, a, x0, sigma): - return a*np.exp(-(x-x0)**2/(2*sigma**2)) - - #converts nparray to qpixmap + scaledvalue = 0.5 * value**2 + 1 + self.camera.shutter_speed = int(scaledvalue) + + def gaussian(self, x, a, x0, w_I): + """ + Gaussian profile function used in fitting routine. + Parameters + ---------- + x: float, abscissa + a: float, amplitude coefficient + x0: float, center + w_I: float, 1/e intensity radius in pixels + Returns + ------- + float + """ + return a*np.exp(-(x-x0)**2/(w_I**2)) + + # converts nparray to qpixmap def nparrayToQPixmap(self, arrayImage): - pilImage = toimage(arrayImage) - qtImage = ImageQt(pilImage) - qImage = QtGui.QImage(qtImage) - qPixmap = QtGui.QPixmap(qImage) - return qPixmap + pilImage = toimage(arrayImage) + qtImage = ImageQt(pilImage) + qImage = QtGui.QImage(qtImage) + qPixmap = QtGui.QPixmap(qImage) + return qPixmap - #to be added + # to be added def zoomin(self): - if self.zoom >= 10: - self.zoom = 10 - else: - self.zoom += 1 - self.resizePlots() + if self.zoom >= 10: + self.zoom = 10 + else: + self.zoom += 1 + self.resizePlots() def zoomout(self): - if self.zoom <= 1: - self.zoom = 1 - else: - self.zoom -= 1 - self.resizePlots() + if self.zoom <= 1: + self.zoom = 1 + else: + self.zoom -= 1 + self.resizePlots() def lowres(self): - self.highresbutton.setChecked(False) + self.highresbutton.setChecked(False) + self.breakloop = True + self.imageres = [640, 480] + time.sleep(1) + self.camera.close() + self.setupPlots() + self.initCamera() + self.startCamera() def highres(self): - self.lowresbutton.setChecked(False) + self.lowresbutton.setChecked(False) + self.breakloop = True + self.imageres = [1296, 972] + time.sleep(1) + self.camera.close() + self.setupPlots() + self.initCamera() + self.startCamera() + + def getzoomgaps(self): + self.gaprow = self.imageres[0]*(self.zoom * 0.04) + self.gapcolumn = self.imageres[1]*(self.zoom * 0.04) def resizePlots(self): - gaprow = self.imageres[0]*(self.zoom * 0.04) - self.axrow.set_xlim(gaprow, self.imageres[0] - gaprow) - self.axrow.set_ylim(0,300) + self.getzoomgaps() + self.axrow.set_xlim(self.gaprow, self.imageres[0] - self.gaprow) + self.axrow.set_ylim(0, 300) - gapcolumn = self.imageres[1]*(self.zoom * 0.04) self.axcolumn.set_xlim(0, 300) - self.axcolumn.set_ylim(gapcolumn,self.imageres[1] - gapcolumn) + self.axcolumn.set_ylim(self.gapcolumn, self.imageres[1] - self.gapcolumn) + + def coarsen(self, xdata, ydata, points): + newlength = int(len(xdata)/points) + newxdata = [] + newydata = [] + j = 0 + for i in range(newlength): + i = points*(i) + newydata.append(np.mean(ydata[int(j):int(i)])) + newxdata.append(xdata[int((i + j)/2)]) + j = i + return np.array(newxdata), np.array(newydata) + + def closeEvent(self, x): + self.camera.close() + + # *********************************************************************************************** + # Added Function + #************************************************************************************************ + # This function is used to sort through the y array to pick the value closest to 1/e**2 + # and returns the index of this value in the array + def closest(self,list, Number): + + temp = [] + # item becomes a variable after the for + for item in list: + temp.append(abs(Number - item)) + + return temp.index(min(temp)) if __name__ == "__main__": @@ -276,6 +434,4 @@ def resizePlots(self): proflayoutwidget = proflayout() proflayoutwidget.show() proflayoutwidget.startCamera() - sys.exit(a.exec_()) - - + sys.exit(a.exec_()) \ No newline at end of file diff --git a/Pseudocode.txt b/Pseudocode.txt new file mode 100644 index 0000000..cee36e4 --- /dev/null +++ b/Pseudocode.txt @@ -0,0 +1,7 @@ +Plan to Implement a Better Guess: +1. Sort (by using a function possibly) through all the y values for either row or column (will have to do for both) + sort to find the index of the value closest to 1/e**2 +2. Return the index of that y value and use for the x array to find the x value that corresponds to this +output the number that corresponds to this x array index +3. Take the absolute value of the outputted number from x array (in case it is on the negative side of the axis) +and multiply this number by 2 to obtain the beam size (the diameter width) diff --git a/Raspi commands.txt b/Raspi commands.txt new file mode 100644 index 0000000..0485e06 --- /dev/null +++ b/Raspi commands.txt @@ -0,0 +1,309 @@ +#******************************************************************************** +# General Settings commands +#******************************************************************************** + +#******************************************************************************** +# FOR RASPBERRY PI VIEWING IN HAMILITON LAB +#******************************************************************************** +# Remember that the code for the beam profiler runs under the home folder code +# to access this code go onto cd /code/PiBeamProfiler and here you can edit the +# code on a text editor and pull changes from github +#********************************************************************************* + +#***************************** +#Looking up Information and help +#help command helps give a summary of a command and how it works +# write the command name with this at the end to find that information +--help + +#***************************** +# Moving/Retrieving Tabs/Using Terminal +#***************************** +#press alt and then press tab + +#move a tab by clicking anywhere and holding alt to move the tab + +#press tab to finish typing +# Example: "Pi" and then tab will finish itself most likely finish to +# PiBeamProfiler/ +# this works for commands and folder names + +#press up key to retrieve the last thing that was typed and +#keep clicking to find more previous commands + +#things that are saved or created automatically go to the +#home directory category + +#***************************** +# Basic Commands and Updates +#***************************** +# This changes the directory that the terminal uses +# Meaning you can access different folders and directories using this command +cd foldername/subfoldername + +#list the contents in a directory or folder +#type this after folder name that popped up after the cd command was used +#this shows everything that is in the folder +ls + +# CAUTION: keep in mind the pi has to be connected to the internet to be fully updated +#updating packages +sudo apt-get update + +#upgrading packages +sudo apt-get upgrade + +# This will automatically pop up in the terminal before you type a command +pi@raspberrypi:/$ + +#**************************** +# Configurations +#**************************** + +#config.txt +#************************* +#this file changes basic settings of the pi such as screen rotation, +#overscan (whether the screen fits properly), and other things + +# To get to the configurations document and modify +# uncomment things and reboot to apply +# ctrl X, y, ctrl M to apply +sudo nano /boot/config.txt #configure the pi document + + #config.txt expanded contents: +#this file changes basic settings of the pi such as screen rotation, +#overscan (whether the screen fits properly), and other things + +#sudo reboot to apply the new changes to the configuration document +sudo reboot + +#This stuff is on that configuration document + # To rotate the display screen +display_rotate=0 #no rotatatin +display_rotate=1 #rotate by 90 degrees +display_rotate=2 #rotate by 180 degrees +display_rotate=3 #rotate by 270 degrees + + # overscan +#to change how the display fits the screen change the overscan settings +#this will be under this file so type this code in +#overscan directions on the .txt configure document + +#rotating the display will mess up the mouse settings on the screen so this might help +#this will change the x and y axis of the mouse +$ sudo apt-get install xinput #try this with/ without the $ symbol, not sure which one actually works +xinput --list +DISPLAY=:0 xinput --list +xinput set-prop 'FT5406 memory based driver' 'Evdev Axes Swap' 1 +xinput --set-prop 'FT5406 memory based driver' 'Evdev Axis Inversion' 0 1 +xinput --set-prop 'FT5406 memory based driver' 'Evdev Axis Inversion' 1 0 + + +#resolve.conf +#********************* +#Access Domain Name System (what it is using for the internet) +#raspberry pi one says ucla physics domain +#expanded in internet section +sudo nano /etc/resolv.conf + +#Network Configuration +#********************* +#Opening the network configurations +sudo nano /etc/network/interfaces +#expanded in internet section + +#**************************** +# Menu +#**************************** +#Getting to the menu Options +#getting to different menu options +# this contains the camera (enable/disable), filesystem, change passowrd, overclock, and about +sudo raspi-config + + + +#***************************************************************************************** +# Internet Help/commands +#***************************************************************************************** + +#*********************** +# Common/Frequent Error +#*********************** +#When you get this error the internet section might help +#go to internet section to try and resolve this error +# try fixing the nameservers which is below +#add nameservers to network configuration page and then save in the way it says earlier + +#Err http://archive.raspberrypi.org wheezy InRelease +  +#Err http://mirrordirector.raspbian.org wheezy InRelease +  +#Err http://archive.raspberrypi.org wheezy Release.gpg + # Temporary failure resolving 'archive.raspberrypi.org' +#Err http://mirrordirector.raspbian.org wheezy Release.gpg +#  Temporary failure resolving 'mirrordirector.raspbian.org' +#Reading package lists... Done +#W: Failed to fetch http://mirrordirector.raspbian.org/raspbian/dists/wheezy/InRelease  + +#W: Failed to fetch http://archive.raspberrypi.org/debian/dists/wheezy/InRelease  + +#W: Failed to fetch http://archive.raspberrypi.org/debian/dists/wheezy/Release.gpg  +#Temporary failure resolving 'archive.raspberrypi.org' + +#W: Failed to fetch http://mirrordirector.raspbian.org/raspbian/dists/wheezy/Release.gpg  +#Temporary failure resolving 'mirrordirector.raspbian.org' + +#W: Some index files failed to download. They have been ignored, or old ones used instead. + +#************************* +#Nameservers and Configuring the Pi to google +#************************* +#configuring the internet: first edit with this command (interfaces configuration) +sudo nano /etc/network/interfaces + +#these nameservers belong to google +#add this to the resolve.conf document +nameserver 8.8.8.8 +nameserver 8.8.4.4 + +#The top of the document currently says +#iface wlan0 +#Replace it at the top with this to get it to work +auto eth0 #this should be only thing at the top + +#find something that looks like this on this document and change the +#static to dhcp +iface eth0 inet dhcp #change the static to dhcp + +#************************ +#testing the internet speed +#************************ +#enter these commands in this order +sudo apt-get install python-pip +sudo easy_install speedtest-cli +speedtest-cli #outputs the speed + +#************************ +# Installing a Better Web Browser +#************************ +#To install something similar to chrome use this: +$ sudo apt-get install chromium-browser + +#if this does not work use the update command and then rerun chromium + +#***************************************************************************************** +# Camera Help/commands +#***************************************************************************************** + +#Getting to the menu Options to Hopefully get the Camera Working +#this will access camera options +sudo raspi-config + +#Opening up the Camera Options +raspistill + +#taking a picture +#the last part is the name of the image +#It will be saved to your user's home directory with this filename +raspistill -o image.jpg + +#record a video +raspivid + +#To capture a 10 second video with raspberry pi +raspivid -o video.h264 -t 1000 + +# open the menu options +sudo raspi-config + + #Fixing the Camera +#this might be useful (didnt work for me though) +#firmware is problem +# Use the following command to get the very latest (but experimental) firmware: +#DO NOT USE THIS MADE SOFTWARE NOT WORK +sudo rpi-update + +#Increasing gpu memory +#go to the config.txt document described in configurations section +#increase gpu memory so that gpu_mem = 144 #this messed up beam profiler requires more power + + + +#************************************************************************ +# Coding/Using Git and Github +#************************************************************************ + +#******************* +# Installing/Configuring Git +#******************* +#installing git +sudo apt-get install git + +#configure git +git config --global user.name "Harry Potter" +git config --global user.email "h.potter@hogwarts.prof + +#text editor (you can use a different text editor this one just sets one +# and works fine) +git config --global core.editor nano + +#******************* +# Basic Commands: +# cloning, pushing, pulling +#******************* + +#clone a repository (still figuring out which folder it goes to?) +#use any website name and have the .git at the end of the github website +git clone https://github.com/CampbellGroup/PiBeamProfiler.git + +#git commands +git checkout branchname #type in the name you want to checkout +git branch #shows you which branch you are on + +#when the code on the device conflicts with code on the internet, this +#command changes the code on the device to match the one on the internet +git stash + +#shows the differences between code on github and code on device +git diff + +#run the code within a specified directory (you first need to do this using the cd command +python CodeName.py + +#changing the code on the pi in a text editor +nano PiBeamProfiler.py + + #three steps to change code and send to github on the internet +# 1 +#use this one when entire files are added to a folder +git add filename +# or this one +#use this one to see changes made to certain documents already in the folder +#this goes through your changes one by one and you say whether it is okay to add them +git add -p + +#2 +# write a message of what you changed +git commit -m "message" + +#3 +#send to the internet +#NEVER PUSH MASTER +git push origin branchname + + # obtain the code from the internet +git pull + +#removing a folder +#make sure you are in the folder by using cd and ls +#do steps 2 and 3 to send to github +git rm -rf foldername + + +#running python on the raspberry pi +# CAUTION you can only run this when you are within the folder this is located which means you still have +#to run cd code/PiBeamProfiler/ first to access the python code +python codename.py +#in the beam profiler's case then run +python PiBeamProfiler.py + diff --git a/Raspi_commands.txt b/Raspi_commands.txt new file mode 100644 index 0000000..30b9141 --- /dev/null +++ b/Raspi_commands.txt @@ -0,0 +1,304 @@ +#******************************************************************************** +# General Settings commands +#******************************************************************************** + +#******************************************************************************** +# FOR RASPBERRY PI VIEWING IN HAMILITON LAB +#******************************************************************************** +# Remember that the code for the beam profiler runs under the home folder code +# to access this code go onto cd /code/PiBeamProfiler and here you can edit the +# code on a text editor and pull changes from github +#********************************************************************************* + +#***************************** +#Looking up Information and help +#help command helps give a summary of a command and how it works +# write the command name with this at the end to find that information +--help + +#***************************** +# Moving/Retrieving Tabs/Using Terminal +#***************************** +#press alt and then press tab + +#move a tab by clicking anywhere and holding alt to move the tab + +#press tab to finish typing +# Example: "Pi" and then tab will finish itself most likely finish to +# PiBeamProfiler/ +# this works for commands and folder names + +#press up key to retrieve the last thing that was typed and +#keep clicking to find more previous commands + +#things that are saved or created automatically go to the +#home directory category + +#***************************** +# Basic Commands and Updates +#***************************** +# This changes the directory that the terminal uses +# Meaning you can access different folders and directories using this command +cd foldername/subfoldername + +#list the contents in a directory or folder +#type this after folder name that popped up after the cd command was used +#this shows everything that is in the folder +ls + +# CAUTION: keep in mind the pi has to be connected to the internet to be fully updated +#updating packages +sudo apt-get update + +#upgrading packages +sudo apt-get upgrade + +# This will automatically pop up in the terminal before you type a command +pi@raspberrypi:/$ + +#**************************** +# Configurations +#**************************** + +#config.txt +#************************* +#this file changes basic settings of the pi such as screen rotation, +#overscan (whether the screen fits properly), and other things + +# To get to the configurations document and modify +# uncomment things and reboot to apply +# ctrl X, y, ctrl M to apply +sudo nano /boot/config.txt #configure the pi document + + #config.txt expanded contents: +#this file changes basic settings of the pi such as screen rotation, +#overscan (whether the screen fits properly), and other things + +#sudo reboot to apply the new changes to the configuration document +sudo reboot + +#This stuff is on that configuration document + # To rotate the display screen +display_rotate=0 #no rotatatin +display_rotate=1 #rotate by 90 degrees +display_rotate=2 #rotate by 180 degrees +display_rotate=3 #rotate by 270 degrees + + # overscan +#to change how the display fits the screen change the overscan settings +#this will be under this file so type this code in +#overscan directions on the .txt configure document + +#rotating the display will mess up the mouse settings on the screen so this might help +#this will change the x and y axis of the mouse +$ sudo apt-get install xinput #try this with/ without the $ symbol, not sure which one actually works +xinput --list +DISPLAY=:0 xinput --list +xinput set-prop 'FT5406 memory based driver' 'Evdev Axes Swap' 1 +xinput --set-prop 'FT5406 memory based driver' 'Evdev Axis Inversion' 0 1 +xinput --set-prop 'FT5406 memory based driver' 'Evdev Axis Inversion' 1 0 + + +#resolve.conf +#********************* +#Access Domain Name System (what it is using for the internet) +#raspberry pi one says ucla physics domain +#expanded in internet section +sudo nano /etc/resolv.conf + +#Network Configuration +#********************* +#Opening the network configurations +sudo nano /etc/network/interfaces +#expanded in internet section + +#**************************** +# Menu +#**************************** +#Getting to the menu Options +#getting to different menu options +# this contains the camera (enable/disable), filesystem, change passowrd, overclock, and about +sudo raspi-config + + + +#***************************************************************************************** +# Internet Help/commands +#***************************************************************************************** + +#*********************** +# Common/Frequent Error +#*********************** +#When you get this error the internet section might help +#go to internet section to try and resolve this error +# try fixing the nameservers which is below +#add nameservers to network configuration page and then save in the way it says earlier + +#Err http://archive.raspberrypi.org wheezy InRelease +  +#Err http://mirrordirector.raspbian.org wheezy InRelease +  +#Err http://archive.raspberrypi.org wheezy Release.gpg + # Temporary failure resolving 'archive.raspberrypi.org' +#Err http://mirrordirector.raspbian.org wheezy Release.gpg +#  Temporary failure resolving 'mirrordirector.raspbian.org' +#Reading package lists... Done +#W: Failed to fetch http://mirrordirector.raspbian.org/raspbian/dists/wheezy/InRelease  + +#W: Failed to fetch http://archive.raspberrypi.org/debian/dists/wheezy/InRelease  + +#W: Failed to fetch http://archive.raspberrypi.org/debian/dists/wheezy/Release.gpg  +#Temporary failure resolving 'archive.raspberrypi.org' + +#W: Failed to fetch http://mirrordirector.raspbian.org/raspbian/dists/wheezy/Release.gpg  +#Temporary failure resolving 'mirrordirector.raspbian.org' + +#W: Some index files failed to download. They have been ignored, or old ones used instead. + +#************************* +#Nameservers and Configuring the Pi to google +#************************* +#configuring the internet: first edit with this command (interfaces configuration) +sudo nano /etc/network/interfaces + +#these nameservers belong to google +#add this to the resolve.conf document +nameserver 8.8.8.8 +nameserver 8.8.4.4 + +#The top of the document currently says +#iface wlan0 +#Replace it at the top with this to get it to work +auto eth0 #this should be only thing at the top + +#find something that looks like this on this document and change the +#static to dhcp +iface eth0 inet dhcp #change the static to dhcp + +#************************ +#testing the internet speed +#************************ +#enter these commands in this order +sudo apt-get install python-pip +sudo easy_install speedtest-cli +speedtest-cli #outputs the speed + +#************************ +# Installing a Better Web Browser +#************************ +#To install something similar to chrome use this: +$ sudo apt-get install chromium-browser + +#if this does not work use the update command and then rerun chromium + +#***************************************************************************************** +# Camera Help/commands +#***************************************************************************************** + +#Getting to the menu Options to Hopefully get the Camera Working +#this will access camera options +sudo raspi-config + +#Opening up the Camera Options +raspistill + +#taking a picture +#the last part is the name of the image +#It will be saved to your user's home directory with this filename +raspistill -o image.jpg + +#record a video +raspivid + +#To capture a 10 second video with raspberry pi +raspivid -o video.h264 -t 1000 + +# open the menu options +sudo raspi-config + + #Fixing the Camera +#this might be useful (didnt work for me though) +#firmware is problem +# Use the following command to get the very latest (but experimental) firmware: +#DO NOT USE THIS MADE SOFTWARE NOT WORK +sudo rpi-update + +#Increasing gpu memory +#go to the config.txt document described in configurations section +#increase gpu memory so that gpu_mem = 144 #this messed up beam profiler + + + +#************************************************************************ +# Coding/Using Git and Github +#************************************************************************ + +#******************* +# Installing/Configuring Git +#******************* +#installing git +sudo apt-get install git + +#configure git +git config --global user.name "Harry Potter" +git config --global user.email "h.potter@hogwarts.prof + +#text editor (you can use a different text editor this one just sets one +# and works fine) +git config --global core.editor nano + +#******************* +# Basic Commands: +# cloning, pushing, pulling +#******************* + +#clone a repository (still figuring out which folder it goes to?) +#use any website name and have the .git at the end of the github website +git clone https://github.com/CampbellGroup/PiBeamProfiler.git + +#git commands +git checkout branchname #type in the name you want to checkout +git branch #shows you which branch you are on + +#when the code on the device conflicts with code on the internet, this +#command changes the code on the device to match the one on the internet +git stash + +#shows the differences between code on github and code on device +git diff + +#run the code within a specified directory (you first need to do this using the cd command +python CodeName.py + +#changing the code on the pi in a text editor +nano PiBeamProfiler.py + + #three steps to change code and send to github on the internet +# 1 +#use this one when entire files are added to a folder +git add file name +# or this one +#use this one to see changes made to certain documents already in the folder +#this goes through your changes one by one and you say whether it is okay to add them +git add -p + +#2 +# write a message of what you changed +git commit -m "message" + +#3 +#send to the internet +#NEVER PUSH MASTER +git push origin branchname + + # obtain the code from the internet +git pull + +#running python on the raspberry pi +# CAUTION you can only run this when you are within the folder this is located which means you still have +#to run cd code/PiBeamProfiler/ first to access the python code +python codename.py +#in the beam profiler's case then run +python PiBeamProfiler.py + + diff --git a/TestData/testt1.jpg b/TestData/testt1.jpg new file mode 100644 index 0000000..2a67eb4 Binary files /dev/null and b/TestData/testt1.jpg differ diff --git a/TestData/testt2.jpg b/TestData/testt2.jpg new file mode 100644 index 0000000..d494c99 Binary files /dev/null and b/TestData/testt2.jpg differ diff --git a/TestData/testt3.jpg b/TestData/testt3.jpg new file mode 100644 index 0000000..b5b7b53 Binary files /dev/null and b/TestData/testt3.jpg differ diff --git a/TestData/testt4.jpg b/TestData/testt4.jpg new file mode 100644 index 0000000..8175663 Binary files /dev/null and b/TestData/testt4.jpg differ diff --git a/TestData/testt5.jpg b/TestData/testt5.jpg new file mode 100644 index 0000000..07f5795 Binary files /dev/null and b/TestData/testt5.jpg differ diff --git a/TestData/testt6.jpg b/TestData/testt6.jpg new file mode 100644 index 0000000..72200f2 Binary files /dev/null and b/TestData/testt6.jpg differ diff --git a/TestData/testt7.jpg b/TestData/testt7.jpg new file mode 100644 index 0000000..194dc32 Binary files /dev/null and b/TestData/testt7.jpg differ