Files
Feeding_control_system/tests/pd_service.py
2026-04-07 09:51:38 +08:00

144 lines
4.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import sys
import os
import math
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from hardware.transmitter import TransmitterController
class PdService:
def __init__(self):
print('派单测试初始化')
self.transmitter_controller=TransmitterController()
# self.pd_record_bll=PDRecordBll()
def get_fact_volumn_12(self,block_number:str='') -> float:
"""获取实际派单发量"""
# _now_volume=0
if not block_number:
print('分块号不能为空')
return
_pd_volume=0
_init_lower_weight=self.transmitter_controller.read_data(2)
if _init_lower_weight is None:
print(f'获取重量异常,上料斗传感器错误')
print(f'获取重量异常,上料斗传感器错误')
return None
print(f'get_fact_volumn当前重量{_init_lower_weight}')
_per_volume=2480
_left_volume=_init_lower_weight/_per_volume
if block_number=='B1':
_left_volume=_left_volume-0.5
if _left_volume>0:
_pd_volume=1.6-_left_volume
_pd_volume=math.ceil(_pd_volume*10)/10
else:
_pd_volume=1.6
elif block_number in ['B3','L1']:
_pd_volume=1.5
elif block_number=='B2':
#浇B3
_pd_volume=1.6
# self.prev_pd_volume=2
#调整
elif block_number=='L2':
if _init_lower_weight>950 and _init_lower_weight<=1350:
_pd_volume=1.5
elif _init_lower_weight>1350 and _init_lower_weight<=1600:
_pd_volume=1.4
elif _init_lower_weight<=950 and _init_lower_weight>800:
_pd_volume=1.6
else:
#1.9方大约L2和F的量
_pd_volume=1.9
# if _weight>1300:
#留0.15 math.floor(_now_volume*10)/10 保留一位小数,丢掉其他的
# if prev_pd_volume>0:
# _pd_volume=_pd_volume-(_left_volume+prev_pd_volume-1.86)
# else:
#不知道上一块叫的多少
_pd_volume=_pd_volume-(_left_volume+1.6-1.46)
_pd_volume=math.ceil(_pd_volume*10)/10+0.1
# _pd_volume=math.ceil(_pd_volume*10)/10
if _pd_volume>2.1:
_pd_volume=2.1
elif _pd_volume<0.8:
_pd_volume=0.8
return _pd_volume
def get_fact_volumn(self,block_number:str='') -> float:
"""获取实际派单发量"""
# _now_volume=0
if not block_number:
print('分块号不能为空')
return
_pd_volume=0
_init_lower_weight=self.transmitter_controller.read_data(2)
if _init_lower_weight is None:
print(f'获取重量异常,上料斗传感器错误')
print(f'获取重量异常,上料斗传感器错误')
return None
print(f'get_fact_volumn当前重量{_init_lower_weight}')
_per_volume=2480
_left_volume=_init_lower_weight/_per_volume
if block_number=='B1':
_left_volume=_left_volume-0.6
if _left_volume>0:
_pd_volume=2-_left_volume
_pd_volume=math.ceil(_pd_volume*10)/10
else:
_pd_volume=2
elif block_number in ['B3','L1']:
_pd_volume=1.9
elif block_number=='B2':
#浇B3
_pd_volume=2
# self.prev_pd_volume=2
#调整
elif block_number=='L2':
if _init_lower_weight>1250 and _init_lower_weight<=1650:
_pd_volume=1.9
elif _init_lower_weight>1650 and _init_lower_weight<=1900:
_pd_volume=1.8
elif _init_lower_weight<=1250 and _init_lower_weight>1100:
_pd_volume=2
else:
#2.4方大约L2和F的量
_pd_volume=2.4
# if _weight>1300:
#留0.15 math.floor(_now_volume*10)/10 保留一位小数,丢掉其他的
# if prev_pd_volume>0:
# _pd_volume=_pd_volume-(_left_volume+prev_pd_volume-1.86)
# else:
#不知道上一块叫的多少
_pd_volume=_pd_volume-(_left_volume+1.9-1.86)
_pd_volume=math.ceil(_pd_volume*10)/10+0.1
# _pd_volume=math.ceil(_pd_volume*10)/10
if _pd_volume>2.1:
_pd_volume=2.1
elif _pd_volume<0.8:
_pd_volume=0.8
return _pd_volume
if __name__ == "__main__":
system = PdService()
volume= system.get_fact_volumn('L2',1.9)
print("派单方量:",volume)