def modechange(self): #IDLE->ARMED if (self.mode == 0 and self.calstatus == 2): self.LED.resize(80, 80) self.LED.setStyleSheet( "border: 1px solid black; background-color: green; border-radius: 40px;" ) self.LED.setText(' Armed ') if (self.disableUSB == 0): #if we havent setup USB, do it here if (self.USB.verify() == False): self.USB = USBprimary() if (self.USB != None): self.USB.writeUSB(NMEA.Encode("ARMED", "1")) elif (self.USB.verify() == True): self.USB.writeUSB(NMEA.Encode("ARMED", "1")) self.DataTimer.start() self.mode = 1 elif (self.mode == 1 and self.calstatus == 2): self.LED.resize(80, 80) self.LED.setStyleSheet( "border: 1px solid black; background-color: red; border-radius: 40px;" ) self.LED.setText(' Idle ') if (self.disableUSB == 0): self.USB.writeUSB(NMEA.Encode("IDLE", "0")) self.DataTimer.stop() self.mode = 0
def UpdateSetpoints(self): #makes sure we have a valid input #X if (self.XSET and self.XSPoint.hasAcceptableInput()): self.XS.setText('X Setpoint (Current Value: %s)' % self.XSET) else: if (self.XSET == 0): self.XS.setText('X Setpoint (Current Value: %s)' % 0) else: self.xflag = True #Y if (self.YSET and self.YSPoint.hasAcceptableInput()): self.YS.setText('Y Setpoint (Current Value: %s)' % self.YSET) else: if (self.YSET == 0): self.YS.setText('X Setpoint (Current Value: %s)' % 0) else: self.yflag = True #Z if (self.ZSET and self.ZSPoint.hasAcceptableInput()): self.ZS.setText('Z Setpoint (Current Value: %s)' % self.ZSET) else: if (self.ZSET == 0): self.ZS.setText('Z Setpoint (Current Value: %s)' % 0) else: self.zflag = True #invalid input popup if (self.xflag or self.yflag or self.zflag): SPInvalid = QMessageBox() SPInvalid.setText( 'Invalid input(s) for one or more axis setpoints; valid range is +/-150+axis null offset with 3 decimal place maximum precision for each setpoint' ) self.xflag = False self.yflag = False self.zflag = False SPInvalid.exec_() #rounds the setpoint to 3 decimal places self.XSET -= round(self.XNOFF, 3) self.YSET -= round(self.YNOFF, 3) self.ZSET -= round(self.ZNOFF, 3) #encodes NMEA messages, subtracting NULL offset for each axis self.XSETE = NMEA.Encode('SETX', str(self.XSET)) self.YSETE = NMEA.Encode('SETY', str(self.YSET)) self.ZSETE = NMEA.Encode('SETZ', str(self.ZSET)) # #send USB messages across USB endpoint if (self.disableUSB == 0 and self.mode == 1): self.USB.writeUSB(self.XSETE) self.USB.writeUSB(self.YSETE) self.USB.writeUSB(self.ZSETE)
def UpdateSetpoints(self): #makes sure we have a valid input #X if (self.XSET and self.XSPoint.hasAcceptableInput()): self.XS.setText('X Setpoint (Current Value: %s)' % self.XSET) else: if (self.XSET == 0): self.XS.setText('X Setpoint (Current Value: %s)' % 0) else: self.xflag = True #Y if (self.YSET and self.YSPoint.hasAcceptableInput()): self.YS.setText('Y Setpoint (Current Value: %s)' % self.YSET) else: if (self.YSET == 0): self.YS.setText('X Setpoint (Current Value: %s)' % 0) else: self.yflag = True #Z if (self.ZSET and self.ZSPoint.hasAcceptableInput()): self.ZS.setText('Z Setpoint (Current Value: %s)' % self.ZSET) else: if (self.ZSET == 0): self.ZS.setText('Z Setpoint (Current Value: %s)' % 0) else: self.zflag = True #invalid input popup if (self.xflag or self.yflag or self.zflag): SPInvalid = QMessageBox() SPInvalid.setText( 'Invalid input(s) for one or more axis setpoints; valid range is -200 to 200 with 3 decimal place maximum precision for each setpoint' ) self.xflag = False self.yflag = False self.zflag = False SPInvalid.exec_() #encodes NMEA messages self.XSETE = NMEA.Encode('SETX', str(self.XSET)) self.YSETE = NMEA.Encode('SETY', str(self.YSET)) self.ZSETE = NMEA.Encode('SETZ', str(self.ZSET)) # NMEA.Decode(self.XSETE) # #send USB messages if (self.disableUSB == 0 and self.mode == 1): self.USB.writeUSB(self.XSETE) self.USB.writeUSB(self.YSETE) self.USB.writeUSB(self.ZSETE)
import NMEA_0183 as NMEA x = NMEA.Encode('XCUR', -89.69) print(x)
def calibrate3HC(self): # if(self.calstatus != 0): self.XSETE = NMEA.Encode('SETX', 0) self.YSETE = NMEA.Encode('SETY', 0) self.ZSETE = NMEA.Encode('SETZ', 0) #clear setpoints self.USB.writeUSB(self.XSETE) self.USB.writeUSB(self.YSETE) self.USB.writeUSB(self.ZSETE) #reset stored calibration values xcal = 0 ycal = 0 zcal = 0 self.XCAL = 0 self.YCAL = 0 self.ZCAL = 0 self.calstatus = 1 #take 20 data samples for each axis of the magnetometer, then take the average on each axis for x in range(0, 20): self.USB.writeUSB(NMEA.Encode('READ', "XMAG")) xcal = NMEA.Decode(self.USB.readUSB()) self.Calibration_Process(xcal) self.USB.writeUSB(NMEA.Encode('READ', "YMAG")) ycal = NMEA.Decode(self.USB.readUSB()) self.Calibration_Process(ycal) # print('Y' + str(ycal)) self.USB.writeUSB(NMEA.Encode('READ', "ZMAG")) zcal = NMEA.Decode(self.USB.readUSB()) self.Calibration_Process(zcal) time.sleep(0.03) #sleep gives better user interface experience time.sleep(2) #finish taking average self.XNOFF = self.XCAL / 20 self.YNOFF = self.YCAL / 20 self.ZNOFF = self.ZCAL / 20 self.XNULLreadout.setText('%f' % self.XNOFF) self.YNULLreadout.setText('%f' % self.YNOFF) self.ZNULLreadout.setText('%f' % self.ZNOFF) #adjusts setpoint input ranges to account for null offset self.XSPoint.setValidator( QDoubleValidator(-150.0 + self.XNOFF, 150.0 + self.XNOFF, 3)) self.YSPoint.setValidator( QDoubleValidator(-150.0 + self.YNOFF, 150.0 + self.YNOFF, 3)) self.ZSPoint.setValidator( QDoubleValidator(-150.0 + self.ZNOFF, 150.0 + self.ZNOFF, 3)) #enable user to arm 3HC self.calstatus = 2 #update LED self.CalLED.resize(80, 80) self.CalLED.setStyleSheet( "border: 1px solid black; background-color: green; border-radius: 40px;" ) self.CalLED.setText(' Calibrated ')
def pulldata(self): #reads all data sequentially and processes if (self.disableUSB == 0 and self.mode == 1): self.USB.writeUSB(NMEA.Encode('READ', "XCUR")) CNMEA = NMEA.Decode(self.USB.readUSB()) self.Process_NMEA(CNMEA) self.USB.writeUSB(NMEA.Encode('READ', "YCUR")) CNMEA2 = NMEA.Decode(self.USB.readUSB()) self.Process_NMEA(CNMEA2) self.USB.writeUSB(NMEA.Encode('READ', "ZCUR")) CNMEA3 = NMEA.Decode(self.USB.readUSB()) self.Process_NMEA(CNMEA3) self.USB.writeUSB(NMEA.Encode('READ', "XMAG")) NNMEA = NMEA.Decode(self.USB.readUSB()) self.Process_NMEA(NNMEA) self.USB.writeUSB(NMEA.Encode('READ', "YMAG")) NNMEA2 = NMEA.Decode(self.USB.readUSB()) self.Process_NMEA(NNMEA2) self.USB.writeUSB(NMEA.Encode('READ', "ZMAG")) NNMEA3 = NMEA.Decode(self.USB.readUSB()) self.Process_NMEA(NNMEA3)
import NMEA_0183 as NMEA x = NMEA.Encode('XCUR', 1.756) print(x)
def __init__(self, parent): super(QWidget, self).__init__(parent) self.layout = QVBoxLayout(self) self.tabs = QTabWidget() self.tab1 = QWidget() self.tab2 = QWidget() self.tab3 = QWidget() # self.tab4 = QWidget() # self.tabs.resize(400,400) # self.USB = None #variables----------------------------------------------- self.x = 0 self.y = 0 self.z = 0 self.test = 0 #setpoint values self.XSET = 0.0 self.YSET = 0.0 self.ZSET = 0.0 #magnetometer data and arrays self.XMAG = 0 self.YMAG = 0 self.ZMAG = 0 # self.XL = [0,0,0,0,0,0,0,0,0,0] # self.YL = [0,0,0,0,0,0,0,0,0,0] # self.ZL = [0,0,0,0,0,0,0,0,0,0] #flags for invalid setpoint input self.xflag = False self.yflag = False self.zflag = False #null offsets self.XNOFF = 0 self.YNOFF = 0 self.ZNOFF = 0 #Current Sensor self.XCUR = 0 self.YCUR = 0 self.ZCUR = 0 #other self.test = 0 #make this 1 to stop USB with changing mode self.disableUSB = 0 self.mode = 0 #this changes when system is changed from ARMED to IDLE #1 = AMRED, 0 = IDLE #end of variable declarations----------------------------- #initializes tab UI for each tab self.tab1UI() self.tab2UI() self.tab3UI() # self.tab4UI() #Qtimers for periodic value updating #timer pulls data on 1/10 second interval self.DataTimer = QTimer() self.DataTimer.setInterval(100) self.DataTimer.timeout.connect(self.pulldata) if (self.disableUSB == 0 and self.mode == 1): self.DataTimer.start() # self.ITimer.start() # self.PlotTimer.start() self.tabs.addTab(self.tab1, "HHC") # self.tabs.addTab(self.tab2,"HHC Field Vector Graphs") self.tabs.addTab(self.tab2, "Solar Vectors") self.tabs.addTab(self.tab3, "SOP and Useful Links") # Add tabs to widget self.layout.addWidget(self.tabs) self.setLayout(self.layout) # init USB if (self.disableUSB == 0): self.USB = USBprimary() #check if USb is connected if (self.USB.verify() == True): print("USB connection verified") if (self.disableUSB == 0 and self.mode == 1): self.USB.writeUSB("\n") self.USB.writeUSB(NMEA.Encode("ARMED", "1")) if (self.disableUSB == 0 and self.mode == 0): self.USB.writeUSB("\n") self.USB.writeUSB(NMEA.Encode("IDLE", "0"))
def pulldata(self): if (self.disableUSB == 0 and self.mode == 1): self.USB.writeUSB(NMEA.Encode('READ', "XCUR")) CNMEA = NMEA.Decode(self.USB.readUSB()) self.Process_NMEA(CNMEA) self.USB.writeUSB(NMEA.Encode('READ', "YCUR")) CNMEA2 = NMEA.Decode(self.USB.readUSB()) self.Process_NMEA(CNMEA2) self.USB.writeUSB(NMEA.Encode('READ', "ZCUR")) CNMEA3 = NMEA.Decode(self.USB.readUSB()) self.Process_NMEA(CNMEA3) self.USB.writeUSB(NMEA.Encode('READ', "XNULL")) NNMEA = NMEA.Decode(self.USB.readUSB()) self.Process_NMEA(NNMEA) self.USB.writeUSB(NMEA.Encode('READ', "YNULL")) NNMEA2 = NMEA.Decode(self.USB.readUSB()) self.Process_NMEA(NNMEA2) self.USB.writeUSB(NMEA.Encode('READ', "ZNULL")) NNMEA3 = NMEA.Decode(self.USB.readUSB()) self.Process_NMEA(NNMEA3)