50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
#!/usr/bin/python
|
|
|
|
from pycomm.ab_comm.clx import Driver as ClxDriver
|
|
c = ClxDriver(True, 'ClxDriver.log')
|
|
PLC_IP_ADDRESS = "192.168.1.10"
|
|
|
|
class PLCException(Exception):
|
|
pass
|
|
|
|
upstroke_target_percent = [20.0, 50.0, 75.0]
|
|
downstroke_target_percent = [50.0]
|
|
|
|
if c.open(PLC_IP_ADDRESS):
|
|
# check that well is stopped
|
|
pump_run_status = c.read_tag(['Pump.Run'])[0][1]
|
|
if pump_run_status == 1:
|
|
raise PLCException("Cannot run the valve check while the pump is running. Stop the pump and try again.")
|
|
|
|
# Set up position targets
|
|
stroke_length = float(c.read_tag(['UnitConfig.Total_Stroke_Length'])[0][1])
|
|
upstroke_target = map(lamba x: (x/100.0) * stroke_length, upstroke_target_percent)
|
|
downstroke_target = map(lamba x: (x/100.0) * stroke_length, downstroke_target_percent)
|
|
|
|
# Store motor parameters
|
|
prev_motor_mode = map(lambda x: {'value':x[1], 'type':x[2]},c.read_tag(['UnitConfig.Speed_Torque_Mode'])[0])[0]
|
|
|
|
# Ensure drive in speed mode
|
|
if prev_motor_mode['value'] != 1:
|
|
c.write_tag('Card_Past[1].Data_Read', 1, 'REAL')
|
|
|
|
# Loop through upstroke position targets
|
|
|
|
|
|
# jog past 0 to within 3 inches of the target position
|
|
|
|
# let pid take over to hold at target
|
|
|
|
# once at target, start timer and store surface and downhole load and position
|
|
|
|
# For downstroke position target
|
|
# jog past 0 to within 3 inches of the target position
|
|
|
|
# let pid take over to hold at target
|
|
|
|
# once at target, start timer and store surface and downhole load and position
|
|
|
|
# re-write motor parameters
|
|
|
|
# do calculations
|