A maior rede de estudos do Brasil

Grátis
LidarPythonCode

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

#8-25-2018
#ACC
#Uno Pi Data interface project
import serial
import RPi.GPIO as GPIO
##import sys
import time
import datetime
import smtplib
from email.mime.text import MIMEText
import threading
import multiprocessing as mp
import smbus
## from luma.core.interface.serial import i2c
from luma.core.render import canvas
from PIL import ImageFont
from luma.oled.device import ssd1306
OLEDdevice = ssd1306()
import queue
q = queue.Queue(maxsize = 0) #create threading queue set size to infinate
oMP = None
mpQsend = mp.Queue()
mpQrcv = mp.Queue()
mpTweakerEvent = mp.Event() #multiprocessing event
## oLockQput = threading.Lock()
import cMpu6050
#interrupt from uno - time to read serial port
iUnoDataReady = 4 #J8-7
#exit interrupt used to stop program
iHalt = 17 #J8-11
iAlertOnOff = 5
## iMPU6050int = 26 #J8-37
#object detected alert
iAlertEmailTimerTrigger = 22
#Servo Tweaker triggers
#iServoTweakerTriggers = 27
#out to uno
iPiReady = 6
#Count Down Timer Trigger
#set to trigger email sending
#1X per hour
##iCDT_Trigger= 13
#low input voltage warning pin
iLowInputVoltage = 23
iPinBuzzer0 = 16
iPinResetArduino = 25
iPinOnePPS = 24
iPinInt = 21
bIsGPIO_CleanUp = False
#prevent object detection during distance aquisition
bDistanceLengthBlanking = True
iZero = 0
iOne = 1
iTwo = 2
iThree = 3
iFour = 4
iFive = 5
iSix = 6
iSeven = 7
bOKToTweak = False
##iTriggerCount = 0 #count for externial timming pulses
bResetTimePassed = False #timer trigger counting enable disable
oTriggerOLED = threading.Event()
iTriggerOLED_Count = iZero
oTriggerCM = threading.Event()
oTrigger32K = threading.Event()
oTriggerSerialSend = threading.Event()
oAspectChange = threading.Event()
oDoVolt = threading.Event()
## oPremptTweak = threading.Event()
iSecondOfLastAlert = 0
sOLED_AlertMessage = "*:"
## sOLED_TweakX = ""
## sOLED_TweakY = ""
## iScans = [0] * 61
## iCurrentCell = 0
## fltAspectIncrement = 5.555
fltScanAspectChange = 1400.0 #dont put a zero in here
bAspectIncrease = True
##fltAngleMid = 1450.00
## bAspectChangeInProgress = False
#############################################
sDistanceScanTime = ""
#############################################
##
#############################################
## save for reference
## s_cm = "cm"
## sVOlTS = "VOLTS"
## sDistance = "Distance"
## sAspectCng = "AspectCng "
## sPASSWORD = "PASSWORD"
## sPLATFORM = "PLATFORM"
## sAspectComplete = "AspectComplete"
## s_doVolts = "doVolts"
#sFLD ="FLD" 
## s_pwd_request = "pwd request "
## s_start_time = "start time "
## s_pwd_received = "pwd received"
##############################################
bOK_Send = True
############################
## fltDistanceAngle = 0.0
##################################################################################
# END VARIABLE DECLEARTIONS
##################################################################################
##################################################################################
###################################################################################
# BEGIN CLASS
##################################################################################
# Enviromental info container
class cEnvermentals():
 sTemperatureC = ""
 sTemperatureF = "" 
 sHumidity = ""
 sPressure = "0.0"
 sAltitude = "0.0"
 sTrending = ""
 altitude = 0.0
 iTrends = [0]
 iBase = 0
 def __init__( self ):
 self.SealevelPressure = 101325.0
 self.Var1 = 0.190295
 self.Var2 = 44330.0
 self.fltConversion = 133.3223684
 self.fltOldPressure = 0.0
 self.oTrigger = threading.Event()
 self.procE = threading.Thread(target = self.fConvertPascelsTo_mmHg )
 self.Pascal = 0.0
 self.fEnvermentalsInit()
 
 def fEnvermentalsInit( self ):
 self.oTrigger.clear()
 self.procE.daemon = True
 self.procE.start()
 return;
 
 def fDoThePressureThing( self, sPressure ):
 self.Pascal = float( sPressure )
 self.oTrigger.set()
 return;
 
 def fConvertPascelsTo_mmHg( self ):
 while( 1 ):
 self.oTrigger.wait()
 ## print( "fConvertPascelsTo_mmHg" )
 fltNew = 0.0
 fltNew = round( self.Pascal / self.fltConversion, 2 )
# if ( fltNew == self.fltOldPressure ):
# self.sTrending = "S"
# elif ( fltNew > self.fltOldPressure ):
# self.sTrending = "U"
# elif ( fltNew < self.fltOldPressure ):
# self.sTrending = "D"
 self.sPressure = str( fltNew )
 ## print( "fConvertPascelsTo_mmHg self.sPressure " + self.sPressure )
 self.fltOldPressure = fltNew
 self.bNewReading = False
 self.fPressureToAltitude( fltNew )
 self.fStoreP( fltNew )
 self.oTrigger.clear()
## sTemp = "%f\r\n" %( fltOldPressure )
## ## print ( sTemp )
## oF = open("PressureTrend.csv", "a+")
## oF.write(sTemp)
## oF.close()
 return;
 
 def fPressureToAltitude(self, fltPressure ):
 ## calculate altitude in meters
 if ( fltPressure > 0.0 ):
 self.altitude = self.Var2 * (1 - pow( (fltPressure/self.SealevelPressure), self.Var1 ))
 self.sAltitude = str( round(self.altitude, 2) )
 ##
 return;
 def fStoreC_F_H( self, sTemperatureC, sHumidity):
 self.sTemperatureC = sTemperatureC
 self.sHumidity = sHumidity
 self.sTemperatureF = str( (int(sTemperatureC) * 9 / 5) + 32 )
 ##
 return;
 def fStoreP( self, fltNew ):
 if( (self.iTrends[0] == 0) ):
 self.iTrends[0] = int(fltNew)
 self.iBase = int(fltNew)
 elif( len(self.iTrends) < 48 ):
 self.iTrends.append( int(fltNew) )
 elif( len(self.iTrends) >= 48 ):
 self.iTrends.append( int(fltNew) )
 self.iTrends.pop(0)
 self.iBase = self.iTrends[iZero]
 return;
 
###################################################################################
# BEGIN CLASS
###################################################################################
#Tweak mpu-6050 platform
#runs threaded to check platform level
'''
mpu gives tilt angle in degrees
servo being tourqued in micro seconds (uS)
servo at 0 degrees = 1000 uS. Servo to 180 = 2000uS. 1000 steps
1000/180 = 5.555. found 5.554 works better per degree
90+15 = 105 degrees
105 * 5.554 = 583
583+1000= 1583 or a max limit of 105 degrees.
Info Position:
 ## 0 gX
 ## 1 gY
 ## 2 gZ
 ## 3 aX
 ## 4 aY
 ## 5 aZ
 ## 6 X rotation
 ## 7 y rotation
 ## 8 lastX
 ## 9 lastY
 ## 10 GxRaw
 ## 11 GyRaw
'''
class cMP_Tweak():
 def __init__(self, oQs, oQr, oEvent):
 self.oEvent = oEvent
 self.cMPU = cMpu6050.cMPU6050()
 self.oQs = oQs
 self.oQr = oQr
 self.bDo = True
 self.iCount = 0
 self.oProcess = mp.Process
 self.iXgryoInitial = 1475
 self.iXgryoHighLimit = 1780
 self.iXgryoLowLimit = 1360
 self.iYgryoInitial = 1475
 self.iYgryoHighLimit = 1778
 self.iYgryoLowLimit = 1378
 self.sGx = "gX "
 self.sGy = "gY "
 self.mpProc = self.oProcess(target = self.fMP_MPUtweaker)
 def oMP_Start(self):
 try:
 self.mpProc.start()
 self.mpProc.join(None) #stops program from exiting
 except Exception as e:
 print("oMP_Start" + str(e))
 def fMP_MPUtweaker( self ):
 bDoGyro = True
 oTweakerX = self.cPlatformTweaker(self.sGx, self.iXgryoInitial, self.iXgryoHighLimit, self.iXgryoLowLimit,

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