A maior rede de estudos do Brasil

Grátis
LidarPythonCode

Pré-visualização | Página 2 de 7

6, self.oQs)
 oTweakerY = self.cPlatformTweaker(self.sGy, self.iYgryoInitial, self.iYgryoHighLimit, self.iYgryoLowLimit, 7, self.oQs)
 oMPU = self.cMPU
 
 ## print( "COOLIES tweak init " )
 while (self.bDo == True):
####
 self.oEvent.wait() #see fInt6050CallBack( iChannel ):
 ## print( "COOLIES tweak triggered " )
####
 ## exit process?
 if ( not self.oQr.empty() ):
 ## print( "oQr.empty() " )
 s = self.oQr.get_nowait()
 if ( s is not None ):
 if ( s == "HALT"):
 ## print( "mpHalt" )
 self.bDo = False
 return;
####
 ## does not do unless last queued item has been processed
 if ( self.oQs.empty() ):
 try:
 ## print( "self.oQs.empty() " )
####
 if (oMPU is None):
 oMPU = self.cMPU
 print("oMPU recovery")
####
 if ( bDoGyro ):
## print( "tweakX" )
 oTweakerX.fProcess_MPU6050(oMPU.fReturnMPU_Info())
####
 else:
 ## print( "tweakY" )
 oTweakerY.fProcess_MPU6050(oMPU.fReturnMPU_Info())
 ####
 ## print( bDoGyro )
 except Exception as e:
 print( "fMP_MPUtweaker() " + str(e) + " doX " + str(bDoGyro) )
 oMPU = None
 finally:
 bDoGyro = not bDoGyro
 self.oEvent.clear()
 return;
 
 def fMP_bDoToFalse(self):
 
 self.bDo = False
 self.mpProc.terminate()
 ## print( "done COOLIES ")
 return;
 
 class cPlatformTweaker():
 def __init__(self, sAxis, iIdeal, iHighLimit, iLowLimit, iInfoPosition, oQ):
 self.sAxis = sAxis
 self.fltIdeal = float(iIdeal)
 self.fltMax = float(iHighLimit)
 self.fltMin = float(iLowLimit)
 self.iInfoPosition = iInfoPosition
 self.fltMaxTorqueAngle = 3.0
 self.fltTorqueAngle_uSec = 22.22
 self.fltSleepTime = 0.25
 self.iRound = 2
 self.fltMinTorqueAngle = 0.17
 self.fltInitial = self.fltIdeal # default fltIdeal, incase fSetInitialPosition is not used
 self.oQ = oQ 
 self.bInitialSet = False
 self.last = 0.0
 self.lastOut = int(self.fltInitial)
 self.fSetInitialPosition()
 
 
 def fSetInitialPosition(self):
 #set platform to ideal posit at start
 self.oQ.put(self.sAxis + str(self.fltIdeal))
 self.fltInitial = self.fltIdeal 
 self.bInitialSet = True
 return;
 def fProcess_MPU6050(self, sMPUInfoIn):
 
 sMPU = ""
 ## using the cMPU6050.py module mpu6050 data is retrived.
 ## using X or Y gryo info an offset torque angle is derived
 ## for servo tilt angle correction
 ##infoposition defines position of data in stream from gyro
 ## print(sMPUInfoIn)
####
 sMPU = sMPUInfoIn.split()
 ## print( self.sAxis )
####
 if (self.sAxis == "gX "):
####
 ## direction magnitude of change
 fltDir_Mag = float( sMPU[8] )
 fltDir_Mag = -(fltDir_Mag * self.fltTorqueAngle_uSec)
 self.fltIdeal = self.fltInitial - fltDir_Mag
 ## print( self.fltIdeal )
 if( abs(self.fltIdeal - self.fltInitial) > 5 ):
 self.oQ.put( self.sAxis + str(int(round(self.fltIdeal))) )
####
 if (self.sAxis == "gY "):
####
 ## direction magnitude of change
 fltDir_Mag = float( sMPU[9] )
 fltDir_Mag = fltDir_Mag * self.fltTorqueAngle_uSec
 self.fltIdeal = self.fltInitial + fltDir_Mag
 ## print( self.fltIdeal )
 if( abs(self.fltIdeal - self.fltInitial) > 2 ):
 self.oQ.put( self.sAxis + str(int(round(self.fltIdeal))) )
#### 
 ## sTemp = "%f,%f,%f,%f\r\n" %( self.lastX, self.fltIdeal, fltDir_Mag, fltB )
 ## print ( sTemp )
 ## oF = open("ChappieX.csv", "a+")
 ## oF.write(sTemp)
 ## oF.close()
####
 return;
 
 def fCheckMinMax(self, Ideal, Min, Max, Initial):
 
 if (Ideal > Max):
 Ideal = Initial
 if (Ideal < Min):
 Ideal = Initial
 return Ideal;
###################################################################################
# BEGIN CLASS
###################################################################################
#3/02/2018
class cCalculateVoltage:
 sVoltageMsg = "waiting"
 def __init__( self, fltR1, fltR2, fltVoltsNominal, fltVoltsRange ):
 self.fltR1 = fltR1
 self.fltR2 = fltR2
 self.fltAD_Factor = 0.0
 self.fltDivisorFactor = 0.0
 self.fltDivisorFactor = self.fltR1 / self.fltR2
 self.fltAD_Factor = 4095 / 3.3
 self.fltErrorFactor = 0.0
 self.iRound = 2
 self.fltZero = 0.0
 self.fltVoltsNominal = fltVoltsNominal
 self.fltVoltsRange = fltVoltsRange
 self.fltVoltsLow = self.fltVoltsNominal - self.fltVoltsRange
 self.vRaw = 0.0
 self.oTrigger = threading.Event()
 self.procV = threading.Thread(target = self.fVolts )
 self.fVoltsInit()
 
 def fVoltsInit( self ):
 self.oTrigger.clear()
 self.procV.daemon = True
 self.procV.start()
 return;
 
 def fDoTheVoltageThing( self, sVRaw ):
 self.vRaw = float( sVRaw )
 self.oTrigger.set()
 return;
##fltErrorFactor is from sampling Arduino VIN and not volts in directly. volts in measurement is after a arduino volts in protection circuit
 def fVolts( self ):
 try:
 while( 1 ):
 self.oTrigger.wait()
 fltVin = self.fltZero
 fltVin = ( self.vRaw / self.fltAD_Factor ) * self.fltDivisorFactor
 fltVin += self.fltErrorFactor
 fltVin = round( fltVin, self.iRound )
 self.sVoltageMsg = "%sV %s" %(str(fltVin), str(self.fCalculateVoltsPrecentage( fltVin )) )
 self.oTrigger.clear()
 except Exception as e:
 print( "cCalculateVoltage.fVolts() " + str(e) )
 return;
 
 def fCalculateVoltsPrecentage( self, fltVin ):
 fltVoltsPercent = 0.00
 if (fltVin >= self.fltVoltsNominal):
 fltVoltsPercent = 100.00
 else:
 fltVoltsPercent = self.fltVoltsNominal - fltVin
 fltVoltsPercent = (fltVoltsPercent / self.fltVoltsRange) * 100
 fltVoltsPercent = 100 - fltVoltsPercent
 GPIO.output(iLowInputVoltage, GPIO.LOW)
 if ( self.fltVoltsLow <= ( self.fltVoltsNominal - fltVin) ):
 fltVoltsPercent = 0.00
 GPIO.output(iLowInputVoltage, GPIO.HIGH)
 if (fltVoltsPercent < 10.01):
 GPIO.output(iLowInputVoltage, GPIO.HIGH)
 return round( fltVoltsPercent, self.iRound );
##################################################################################
# END CLASS
##################################################################################
#def fEmailAlertAlarm():
# fSendMail( str(datetime.datetime.now()) )
# return;
####
def fSendMail(sBody):
 #print("entered send email")
 if (len(sBody) == iZero):
 #print("fSendMail(sBody) len 0")
 sBody = "No

Crie agora seu perfil grátis para visualizar sem restrições.