From c566b4070ef846b06aaa976181d730b02f5b6ded Mon Sep 17 00:00:00 2001 From: "support.sampyo" Date: Thu, 4 Jul 2024 05:12:08 +0000 Subject: [PATCH] Commit message --- control.json | 48 ++++++++------- framework.yaml | 2 +- main.py | 160 +++++++++++++++++++++++++++++-------------------- 3 files changed, 123 insertions(+), 87 deletions(-) diff --git a/control.json b/control.json index 116a3a3..ae7b748 100644 --- a/control.json +++ b/control.json @@ -4,40 +4,46 @@ "action": "Off" }, "measure": { - "action": "On", - "duration": 20 + "action": "On" }, "mixed": { - "action": "Off", - "duration": 7 + "action": "Off" }, "pure": { "action": "Off", - "duration": 10, - "holding": 7 + "duration": 1.5 + }, + "enter":{ + "action": "Off" }, - "enter":{ - "action": "Off", - "duration": 5 - }, "vent": { - "action": "On", - "duration": 20, - "holding": 7 + "action": "On" }, "motor": { "action": "Off" }, - "main": { - "action": "Off", - "duration": 1.5 - } + "main": { + "action": "Off", + "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": { - "clean": { - "duration": 20, - "time": 25 - } + "clean": { + "duration": 20, + "time": 25 + } }, "type": "manual" } diff --git a/framework.yaml b/framework.yaml index 5616ffc..c337d43 100644 --- a/framework.yaml +++ b/framework.yaml @@ -7,5 +7,5 @@ spec: virtualEnv: base # 사용할 가상환경 이름입니다. package: requirements.txt # 설치할 Python 패키지 정보 파일입니다.(기본 값은 requirement.txt 입니다.) stackbase: - tagName: v0.0.40 # Stackbase(gitea)에 릴리즈 태그명 입니다. + tagName: v0.0.41 # Stackbase(gitea)에 릴리즈 태그명 입니다. repoName: sampyo-dio # Stackbase(gitea)에 저장될 저장소 이릅니다. diff --git a/main.py b/main.py index beeca4e..4adbd6f 100644 --- a/main.py +++ b/main.py @@ -35,13 +35,36 @@ def Valve_MixedWater(chip, status, action): chip.set_values(status) -def Valve_PureWater(chip, status, action): - if action == 'On': - status[3] = 1 - else: # action == 'Off' - status[3] = 0 - +def Valve_PureWater(chip, status, action, duration=7): + global pure_valve_status + + status[2] = 0 + status[3] = 0 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): if action == 'On': @@ -64,7 +87,7 @@ def Valve_MainWater(chip, status, action, duration=7): status[6] = 0 chip.set_values(status) time.sleep(duration) - else: + else: # 'Off' status[5] = 0 status[6] = 1 chip.set_values(status) @@ -75,9 +98,9 @@ def Valve_MainWater(chip, status, action, duration=7): chip.set_values(status) time.sleep(0.05) - if action == 'On' and duration == 7: + if action == 'On' and duration >= 7: main_valve_status = 2 - elif action == 'On' and duration != 7: + elif action == 'On' and duration < 7: main_valve_status = 1 else: main_valve_status = 0 @@ -117,90 +140,94 @@ def Command_Read(): cmd = json.load(f) 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']) - - 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') - Motor(chip=output_lines, status=status, action='Off') - - time.sleep(5) - start = Measure_Weight(client=client) + 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']) - Valve_MixedWater(chip=output_lines, status=status, action='On') - time.sleep(0.5) + + # Step 0. Mesure init weight before starting the sequence + time.sleep(setp0_duration) + start = Measure_Weight(client=client) + + # Step 1. Vent pured water before input mixed water + # Target valve status: [Motor: Off, Vent: On, Pure: Off, Enter: On, Main: On] Valve_EnterWater(chip=output_lines, status=status, action='On') time.sleep(0.5) Valve_Vent(chip=output_lines, status=status, action='On') - time.sleep(vent_holding) - Valve_EnterWater(chip=output_lines, status=status, action='Off') - time.sleep(vent_holding) + time.sleep(0.5) + Valve_MainWater(chip=output_lines, status=status, action='On', duration=main_duration) + 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') time.sleep(0.5) 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') - time.sleep(0.5) + # Step 4. Mesure the weight + # Target valve status: [Motor: Off, Vent: Off, Pure: Off, Enter: Off, Main: Off] Valve_EnterWater(chip=output_lines, status=status, action='Off') - time.sleep(measure_duration) - - # measure weight + time.sleep(0.5) + Valve_MainWater(chip=output_lines, status=status, action='Off') + + time.sleep(setp4_duration) end = Measure_Weight(client=client) time.sleep(1) Calculate_Concentration(weight=(float(end)-float(start))) - - Motor(chip=output_lines, status=status, action='On') - time.sleep(0.5) - - Valve_PureWater(chip=output_lines, status=status, action='On') - time.sleep(0.5) - + # Step 5. Drain the mixed water and add pure water. + # Target valve status: [Motor: Off, Vent: On, 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='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') time.sleep(0.5) - - # 2) Input Pure Water - Valve_PureWater(chip=output_lines, status=status, action='On') - 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) + Motor(chip=output_lines, status=status, action='On') + time.sleep(setp7_duration) + + # Step 8. Drain pure Water + # Target valve status: [Motor: On, Vent: On, Pure: Off, Enter: Off, Main: Off] Valve_EnterWater(chip=output_lines, status=status, action='Off') time.sleep(0.5) - - # 4) Wait until empty 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='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') - time.sleep(0.5) - Valve_Vent(chip=output_lines, status=status, action='Off') - time.sleep(0.5) - + time.sleep(setp9_duration) + return 1 elif cmd['type'] == 'clean': @@ -463,7 +490,10 @@ if __name__ == "__main__": signal.signal(signal.SIGINT, exit_handler) main_valve_status = 0 + pure_value_status = 0 + 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: jsonData = json.load(f)