Hamburger Hamburger

Heating and Ventilation Control

/HvcMotorDriver

Keine Erläuterungen gefunden.

import  RPi.GPIO as  GPIO


class HvcMotorDriver:
    def  __init__(self):
        #
        self.MDPins={}
        self.MDPins['pinOpen'] = 18
        self.MDPins['pinShut'] = 17
        self.MDPos={}
        self.MDPos['Shut'] = 979
        self.MDPos['Open'] = 1450
        self.maxOperationTime = 2 # seconds
        
    def  setMode(self):
        #Setup GPIO
        #GPIO.setwarnings(False) #probably you already use HvcSetGPIO
        GPIO.setmode(GPIO.BCM)
        message = "HvcMotorDriver.setMode: \n"
        actuators={}
        for  pin in self.MDPins:
            GPIO.setup(self.MDPins[pin], GPIO.OUT)
            message = message + "GPIO "+pin+":\t"+str(self.MDPins[pin])+"\t=> OUT \n"
            #            actuators[pin] = 0
            #
            #        return actuators,message
            
        return message

    def  move(self,sensors,opMode):
        """ Enable operation when operationMode changes,
            for  a certain time,
            if the motor position is valid
        """
        if self.MDPos['Open'] > self.MDPos['Shut']: 
            minPos = self.MDPos['Shut']
            maxPos = self.MDPos['Open']
            direction = "asc"
        else:
            maxPos = self.MDPos['Shut']
            minPos = self.MDPos['Open']
            direction = "des"
            
        if sensors['posBp']>0.95*minPos and sensors['posBp']<10.05*maxPos:
            print(opMode['byPs'],self.operationModeLast)
            if opMode['byPs'] != self.operationModeLast:
                self.operationModeLast = opMode['byPs']
                self.operationTimer = self.maxOperationTime
            elif self.operationTimer > 0:
                self.operationTimer = self.operationTimer-1

        message = "opMode: "+opMode['byPs']+" timer= "+str(self.operationTimer)+" sirection= "+direction+"\n"
        # set GPIO pins for  operation
        if opMode['byPs']=="open" and  self.operationTimer>0:
            active = True
            if direction == "asc" and sensors['posBp']<self.MDPos['Open']:
                GPIO.output(self.MDPins['pinOpen'], GPIO.HIGH)
                GPIO.output(self.MDPins['pinShut'], GPIO.LOW)
            elif direction == "des" and sensors['posBp']>self.MDPos['Open']:
                GPIO.output(self.MDPins['pinOpen'], GPIO.HIGH)
                GPIO.output(self.MDPins['pinShut'], GPIO.LOW)
            else:
                # full stop
                GPIO.output(self.MDPins['pinOpen'], GPIO.HIGH)
                GPIO.output(self.MDPins['pinShut'], GPIO.HIGH)
                
        elif opMode['byPs']=="shut" and  self.operationTimer>0:
            active = True
            if direction == "asc" and sensors['posBp']>self.MDPos['Shut']:
                GPIO.output(self.MDPins['pinOpen'], GPIO.LOW)
                GPIO.output(self.MDPins['pinShut'], GPIO.HIGH)
            elif direction == "des" and sensors['posBp']<self.MDPos['Shut']:
                GPIO.output(self.MDPins['pinOpen'], GPIO.LOW)
                GPIO.output(self.MDPins['pinShut'], GPIO.HIGH)
            else:
                # full stop
                GPIO.output(self.MDPins['pinOpen'], GPIO.HIGH)
                GPIO.output(self.MDPins['pinShut'], GPIO.HIGH)
                
        elif opMode['byPs']=="stop":
            active = False
            GPIO.output(self.MDPins['pinOpen'], GPIO.LOW)
            GPIO.output(self.MDPins['pinShut'], GPIO.LOW)
            
        else:
            # inactive
            active = False
            GPIO.output(self.MDPins['pinOpen'], GPIO.LOW)
            GPIO.output(self.MDPins['pinShut'], GPIO.LOW)
            
        print(message)
        return active
    
#persistant values:
HvcMotorDriver.operationTimer=0
HvcMotorDriver.operationModeLast=""


if __name__ == "__main__":
    import  time
    from HvcReadSPI import  HvcReadSPI
    
    myMD = HvcMotorDriver()
    msg = myMD.setMode()
    print(msg)
    
    opMode = {}
    opMode['byPs']="open" #     <<===  set target
    myMD.operationModeLast="shut"
    #opMode['byPs']="shut" #     <<===  set target
    #myMD.operationModeLast="open"
    #opMode['byPs']="stop" #     <<===  set target

    # myIO = HvcSetGPIO()
    mySPI = HvcReadSPI()
    ADC,msg = mySPI.readADCverbose()
    print(msg)
    while True:
        ADC = mySPI.readADC()
        sensors={}
        sensors['posBp']=ADC['posBp']
        active = myMD.move(sensors,opMode)
        for  pin in myMD.MDPins:
            foo = GPIO.input(myMD.MDPins[pin])
            print(pin,foo)
            
        if active:
            print(opMode['byPs'],sensors['posBp'])

        time.sleep(1)

python

1/HvcLightControl.py
2/HvcHCSR04ultrasonic.py
3/HvcPV.py
4/HvcMotorDriver.py
5/HvcRollerShutter.py
6/manGenMqttMap.py
7/HvcReadSPI.py
8/HvcMqtt.py
9/HvcTables.py
10/HvcMain.py
11/HvcSetGPIO.py
12/HvcWifiRelay.py
13/HvcOperationMode.py
14/HvcControl.py
15/HvcRaw2phys.py
16/HvcWeather.py
17/HvcOneWire.py
18/makeDoc.py
19/HvcFronius.py
20/EnergyManager.py
21/HvcSendI2C.py

php

1/HV_colorMap.php
2/HV_Admin_Login.php
3/HV_readOperationState.php
4/HV_setParameters.php
5/HV_config.php
6/EM_handleJSON.php
7/index.php
8/readFilenames.php
9/HV_restart.php
10/HV_moveGate.php
11/HV_showLog.php
12/HV_RollerShutter.php
13/EM_editParameter.php
14/HV_serviceLog.php
15/HV_H2Olevel.php
16/HV_TempCal.php
17/HV_Fronius.php
18/EM_plot.php
19/readNamedData.php
20/HV_composeH2Oplot.php
21/HVdoc.php
22/HV_showWeatherForecast.php
23/HV_showHouse.php

Der gesamte Sourcecode darf gemäß GNU General Public License weiterverbreitet werden.