Commit message

This commit is contained in:
support.sampyo 2024-07-04 05:12:08 +00:00
parent 4239597f8a
commit c566b4070e
3 changed files with 123 additions and 87 deletions

View File

@ -4,26 +4,20 @@
"action": "Off" "action": "Off"
}, },
"measure": { "measure": {
"action": "On", "action": "On"
"duration": 20
}, },
"mixed": { "mixed": {
"action": "Off", "action": "Off"
"duration": 7
}, },
"pure": { "pure": {
"action": "Off", "action": "Off",
"duration": 10, "duration": 1.5
"holding": 7
}, },
"enter":{ "enter":{
"action": "Off", "action": "Off"
"duration": 5
}, },
"vent": { "vent": {
"action": "On", "action": "On"
"duration": 20,
"holding": 7
}, },
"motor": { "motor": {
"action": "Off" "action": "Off"
@ -33,6 +27,18 @@
"duration": 1.5 "duration": 1.5
} }
}, },
"working-time":{
"step0": 5,
"step1": 10,
"step2": 6,
"step3": 7,
"step4": 20,
"step5": 10,
"step6": 6,
"step7": 6,
"step8": 10,
"step9": 0.5
},
"maintenance": { "maintenance": {
"clean": { "clean": {
"duration": 20, "duration": 20,

View File

@ -7,5 +7,5 @@ spec:
virtualEnv: base # 사용할 가상환경 이름입니다. virtualEnv: base # 사용할 가상환경 이름입니다.
package: requirements.txt # 설치할 Python 패키지 정보 파일입니다.(기본 값은 requirement.txt 입니다.) package: requirements.txt # 설치할 Python 패키지 정보 파일입니다.(기본 값은 requirement.txt 입니다.)
stackbase: stackbase:
tagName: v0.0.40 # Stackbase(gitea)에 릴리즈 태그명 입니다. tagName: v0.0.41 # Stackbase(gitea)에 릴리즈 태그명 입니다.
repoName: sampyo-dio # Stackbase(gitea)에 저장될 저장소 이릅니다. repoName: sampyo-dio # Stackbase(gitea)에 저장될 저장소 이릅니다.

146
main.py
View File

@ -35,13 +35,36 @@ def Valve_MixedWater(chip, status, action):
chip.set_values(status) chip.set_values(status)
def Valve_PureWater(chip, status, action): def Valve_PureWater(chip, status, action, duration=7):
if action == 'On': global pure_valve_status
status[3] = 1
else: # action == 'Off'
status[3] = 0
status[2] = 0
status[3] = 0
chip.set_values(status) chip.set_values(status)
time.sleep(0.05)
if action == 'On':
status[2] = 1
status[3] = 0
chip.set_values(status)
time.sleep(duration)
else: # 'Off'
status[2] = 0
status[3] = 1
chip.set_values(status)
time.sleep(7)
status[2] = 0
status[3] = 0
chip.set_values(status)
time.sleep(0.05)
if action == 'On' and duration >= 7:
pure_valve_status = 2
elif action == 'On' and duration < 7:
pure_valve_status = 1
else:
pure_valve_status = 0
def Valve_EnterWater(chip, status, action): def Valve_EnterWater(chip, status, action):
if action == 'On': if action == 'On':
@ -64,7 +87,7 @@ def Valve_MainWater(chip, status, action, duration=7):
status[6] = 0 status[6] = 0
chip.set_values(status) chip.set_values(status)
time.sleep(duration) time.sleep(duration)
else: else: # 'Off'
status[5] = 0 status[5] = 0
status[6] = 1 status[6] = 1
chip.set_values(status) chip.set_values(status)
@ -75,9 +98,9 @@ def Valve_MainWater(chip, status, action, duration=7):
chip.set_values(status) chip.set_values(status)
time.sleep(0.05) time.sleep(0.05)
if action == 'On' and duration == 7: if action == 'On' and duration >= 7:
main_valve_status = 2 main_valve_status = 2
elif action == 'On' and duration != 7: elif action == 'On' and duration < 7:
main_valve_status = 1 main_valve_status = 1
else: else:
main_valve_status = 0 main_valve_status = 0
@ -117,89 +140,93 @@ def Command_Read():
cmd = json.load(f) cmd = json.load(f)
if cmd['type'] == 'auto': if cmd['type'] == 'auto':
mixed_duration = int(cmd['device']['mixed']['duration'])
pure_duration = int(cmd['device']['pure']['duration'])
pure_holding = int(cmd['device']['pure']['holding'])
vent_duration = int(cmd['device']['vent']['duration'])
vent_holding = int(cmd['device']['vent']['holding'])
measure_duration = int(cmd['device']['measure']['duration'])
enter_duration = int(cmd['device']['enter']['duration'])
main_duration = float(cmd['device']['main']['duration']) main_duration = float(cmd['device']['main']['duration'])
pure_duration = float(cmd['device']['pure']['duration'])
setp0_duration = float(cmd['working-time']['setp0'])
setp1_duration = float(cmd['working-time']['setp1'])
setp2_duration = float(cmd['working-time']['setp2'])
setp3_duration = float(cmd['working-time']['setp3'])
setp4_duration = float(cmd['working-time']['setp4'])
setp5_duration = float(cmd['working-time']['setp5'])
setp6_duration = float(cmd['working-time']['setp6'])
setp7_duration = float(cmd['working-time']['setp7'])
setp8_duration = float(cmd['working-time']['setp8'])
setp9_duration = float(cmd['working-time']['setp9'])
if main_valve_status == 0:
Valve_MainWater(chip=output_lines, status=status, action='On', duration=main_duration)
else:
Valve_MainWater(chip=output_lines, status=status, action='Off')
Valve_MainWater(chip=output_lines, status=status, action='On', duration=main_duration)
Valve_Vent(chip=output_lines, status=status, action='Off') # Step 0. Mesure init weight before starting the sequence
Motor(chip=output_lines, status=status, action='Off') time.sleep(setp0_duration)
time.sleep(5)
start = Measure_Weight(client=client) start = Measure_Weight(client=client)
Valve_MixedWater(chip=output_lines, status=status, action='On') # Step 1. Vent pured water before input mixed water
time.sleep(0.5) # Target valve status: [Motor: Off, Vent: On, Pure: Off, Enter: On, Main: On]
Valve_EnterWater(chip=output_lines, status=status, action='On') Valve_EnterWater(chip=output_lines, status=status, action='On')
time.sleep(0.5) time.sleep(0.5)
Valve_Vent(chip=output_lines, status=status, action='On') Valve_Vent(chip=output_lines, status=status, action='On')
time.sleep(vent_holding) time.sleep(0.5)
Valve_EnterWater(chip=output_lines, status=status, action='Off') Valve_MainWater(chip=output_lines, status=status, action='On', duration=main_duration)
time.sleep(vent_holding) time.sleep(setp1_duration)
# Step 2. Empty the remaining pure water
# Target valve status: [Motor: Off, Vent: On, Pure: Off, Enter: Off, Main: On]
Valve_EnterWater(chip=output_lines, status=status, action='Off')
time.sleep(setp2_duration)
# Step 3. Input the mixed water
# Target valve status: [Motor: Off, Vent: Off, Pure: Off, Enter: On, Main: On]
Valve_Vent(chip=output_lines, status=status, action='Off') Valve_Vent(chip=output_lines, status=status, action='Off')
time.sleep(0.5) time.sleep(0.5)
Valve_EnterWater(chip=output_lines, status=status, action='On') Valve_EnterWater(chip=output_lines, status=status, action='On')
time.sleep(mixed_duration) time.sleep(setp3_duration)
Valve_MixedWater(chip=output_lines, status=status, action='Off') # Step 4. Mesure the weight
time.sleep(0.5) # Target valve status: [Motor: Off, Vent: Off, Pure: Off, Enter: Off, Main: Off]
Valve_EnterWater(chip=output_lines, status=status, action='Off') Valve_EnterWater(chip=output_lines, status=status, action='Off')
time.sleep(measure_duration) time.sleep(0.5)
Valve_MainWater(chip=output_lines, status=status, action='Off')
# measure weight time.sleep(setp4_duration)
end = Measure_Weight(client=client) end = Measure_Weight(client=client)
time.sleep(1) time.sleep(1)
Calculate_Concentration(weight=(float(end)-float(start))) Calculate_Concentration(weight=(float(end)-float(start)))
# Step 5. Drain the mixed water and add pure water.
Motor(chip=output_lines, status=status, action='On') # Target valve status: [Motor: Off, Vent: On, Pure: On, Enter: On, Main: Off]
time.sleep(0.5)
Valve_PureWater(chip=output_lines, status=status, action='On')
time.sleep(0.5)
Valve_EnterWater(chip=output_lines, status=status, action='On') Valve_EnterWater(chip=output_lines, status=status, action='On')
time.sleep(0.5) time.sleep(0.5)
Valve_Vent(chip=output_lines, status=status, action='On') Valve_Vent(chip=output_lines, status=status, action='On')
time.sleep(vent_duration) time.sleep(0.5)
Valve_PureWater(chip=output_lines, status=status, action='On', duration=pure_duration)
time.sleep(setp5_duration)
# Step 6. Drain mixed water
# Target valve status: [Motor: Off, Vent: On, Pure: On, Enter: Off, Main: Off]
Valve_EnterWater(chip=output_lines, status=status, action='Off')
time.sleep(setp6_duration)
# Step 7. Input pure water and clean
# Target valve status: [Motor: On, Vent: Off, Pure: On, Enter: On, Main: Off]
Valve_EnterWater(chip=output_lines, status=status, action='On')
time.sleep(0.5)
Valve_Vent(chip=output_lines, status=status, action='Off') Valve_Vent(chip=output_lines, status=status, action='Off')
time.sleep(0.5) time.sleep(0.5)
Motor(chip=output_lines, status=status, action='On')
time.sleep(setp7_duration)
# 2) Input Pure Water # Step 8. Drain pure Water
Valve_PureWater(chip=output_lines, status=status, action='On') # Target valve status: [Motor: On, Vent: On, Pure: Off, Enter: Off, Main: Off]
time.sleep(0.5)
Valve_EnterWater(chip=output_lines, status=status, action='On')
time.sleep(pure_duration)
Valve_PureWater(chip=output_lines, status=status, action='Off')
time.sleep(0.5)
Valve_EnterWater(chip=output_lines, status=status, action='Off') Valve_EnterWater(chip=output_lines, status=status, action='Off')
time.sleep(0.5) time.sleep(0.5)
# 4) Wait until empty
Valve_Vent(chip=output_lines, status=status, action='On') Valve_Vent(chip=output_lines, status=status, action='On')
time.sleep(vent_duration)
time.sleep(0.5) time.sleep(0.5)
Valve_PureWater(chip=output_lines, status=status, action='Off')
time.sleep(setp8_duration)
# 5) Motor Off and Vent close # Step 9. Stop moter
# Target valve status: [Motor: Off, Vent: On, Pure: Off, Enter: Off, Main: Off]
Motor(chip=output_lines, status=status, action='Off') Motor(chip=output_lines, status=status, action='Off')
time.sleep(0.5) time.sleep(setp9_duration)
Valve_Vent(chip=output_lines, status=status, action='Off')
time.sleep(0.5)
return 1 return 1
@ -463,7 +490,10 @@ if __name__ == "__main__":
signal.signal(signal.SIGINT, exit_handler) signal.signal(signal.SIGINT, exit_handler)
main_valve_status = 0 main_valve_status = 0
pure_value_status = 0
Valve_MainWater(chip=output_lines, status=status, action='Off') Valve_MainWater(chip=output_lines, status=status, action='Off')
Valve_PureWater(chip=output_lines, status=status, action='Off')
with open('./config.json', encoding='UTF-8') as f: with open('./config.json', encoding='UTF-8') as f:
jsonData = json.load(f) jsonData = json.load(f)