Browse Source

Neue logfiles. Sonstige bugfixes. Neue Emergency off prozedur

master
FINO2_HostPC_2 6 months ago
parent
commit
75887b18fd
  1. BIN
      code/__pycache__/winch_control.cpython-310.pyc
  2. 50
      code/cast_control.py
  3. 13
      code/startfile_control.py
  4. 40
      code/winch_control.py
  5. 2
      data/pull_parameter.json
  6. 79
      output/cast_log
  7. 24
      output/startfile_log
  8. 13
      raspi_crontabs.txt

BIN
code/__pycache__/winch_control.cpython-310.pyc

Binary file not shown.

50
code/cast_control.py

@ -25,6 +25,8 @@ class CastControl:
self.box_startfile_filepath = os.path.join(self.box_startfile_dirpath, "startfile.json")
self.winch_port=""
self.start_time=""
def start_cycle_if_startfile_found(self):
def init_emergency_stop(port):
@ -35,6 +37,38 @@ class CastControl:
else:
print("EMERGENCY STOP READS AS FAILED!")
startfile_found = self.check_for_startfile_boxpc()
if startfile_found == {}:
pass
else:
try:
print("PRESS \"Ctrl+C\" ANYTIME FOR EMERGENCY STOP")
time.sleep(0.2)
p = Process(target=self.cast_routine,args=(startfile_found,))
p.daemon = True # kill subprocess if main process killed
p.start()
p.join()
print("exiting")
except KeyboardInterrupt:
print("escape routine")
print(p.is_alive())
if p.is_alive():
p.kill()
init_emergency_stop(port=self.winch_port)
"""def start_cycle_if_startfile_found(self):
def init_emergency_stop(port):
winch_emergency_connection = WinchControl(port=port)
success = winch_emergency_connection.emergency_stop()
if success is True:
print("Emergency stop reports as successful")
else:
print("EMERGENCY STOP READS AS FAILED!")
startfile_found = self.check_for_startfile_boxpc()
if startfile_found == {}:
pass
@ -54,7 +88,8 @@ class CastControl:
print("escape routine")
if p.is_alive():
p.kill()
init_emergency_stop(port=self.winch_port)
init_emergency_stop(port=self.winch_port)"""
def check_for_startfile_boxpc(self) -> dict:
try:
@ -62,6 +97,9 @@ class CastControl:
start_parameters = json.load(json_file)
except FileNotFoundError:
print("No startfile found.")
time.sleep(3)
print("exiting")
time.sleep(1)
return {}
else:
os.remove(self.box_startfile_filepath)
@ -123,15 +161,17 @@ class CastControl:
else:
print("Motor has not shut down...initiating emergency stop")
winch.emergency_stop()
print("Cast complete. Winch motor disabled, connection closed.")
print("-------------")
print("CAST COMPLETE. Winch motor disabled, connection closed.")
print("-------------")
@staticmethod
def wait_stationary(seconds): # waits number of seconds +-1s
for i in range(seconds):
if i % 2 == 0 or i == 0 or i == seconds - 1:
print('Waiting...' + str(i) + "/" + str(seconds) + " s...", end="\r")
print('Waiting ' + str(i) + "/" + str(seconds) + " s...", end="\r")
time.sleep(1)
print('Waiting...' + str(i) + "/" + str(seconds) + " s...", end='')
print('Waiting ' + str(i) + "/" + str(seconds) + " s... ", end='')
print("Wait time complete.")
@staticmethod

13
code/startfile_control.py

@ -85,14 +85,15 @@ class Startfile:
if withprep_withstartfiledelay_starttime >= next_interval_datetime:
print("Startfile was send too late! System will not have enought time to check for startfile and prepare. ABORTING Cast")
print("Scheduled start at "+str(next_interval_datetime)+", but System would be ready at "+str(withprep_withstartfiledelay_starttime)+". Try again in next interval...")
raise StartfileValidityError
print("Startfile parameter valid. Next downcast will start at: " + str(next_interval_datetime))
return False
buffer_time = 30
cycle_time = upcast_duration + self.top_pause_seconds + self.warmup_seconds + downcast_duration + \
self.bottom_pause_seconds + buffer_time
if cycle_time >= self.cast_interval * 60:
print("Chosen pull interval shorter than cycle time. ABORTING")
raise StartfileValidityError
return False
now= datetime.datetime.now()
print(str(now)+": Startfile parameter valid. Next downcast set to: " + str(next_interval_datetime))
self.downcast_start_time = next_interval_datetime
self.upcast_start_time = next_interval_datetime - datetime.timedelta(seconds=total_preptime)
self.startfile_dict['downcast_start_time'] = str(self.downcast_start_time)
@ -126,11 +127,15 @@ def new_startfile_routine() -> bool:
# run this (over cron) ~2-3 minutes before every measurement interval
new_startfile = Startfile()
startfile_valid = new_startfile.is_startfile_valid()
now= datetime.datetime.now()
if startfile_valid is True:
new_startfile.send_startfile()
print(str(now)+": Startfile sent over")
return True
else:
print("Startfile not valid. Not sending startfile")
print(str(now)+": Startfile not valid. Not sending startfile")
raise StartfileValidityError
return False

40
code/winch_control.py

@ -290,22 +290,25 @@ class WinchControl:
# Check and set line speed
self.ser.write(b'UF[12]\r')
throwaway = self.ser.read_until(expected=b'UF[12]\r')
line_speed_reply = str(self.ser.read_until(expected=b";"))
print("Old line speed: " + line_speed_reply + " m/s")
old_line_speed_reply = str(self.ser.read_until(expected=b";"))[2:-2]
self.ser.write(b'UF[12]=' + str(self.line_speed).encode('ascii') + b'\r')
throwaway = self.ser.read_until(expected=b'UF[12]=')
line_speed_reply = str(self.ser.read_until(expected=b";"))
print("New line speed: " + line_speed_reply + " m/s")
new_line_speed_reply = str(self.ser.read_until(expected=b";"))[2:-4]
print("New line speed at " + new_line_speed_reply + " m/s. Old speed was " +old_line_speed_reply+ " m/s.")
time.sleep(0.5)
# start deploying line
self.ser.write(b'UF[13]\r')
throwaway = self.ser.read_until(expected=b'UF[13]\r')
line_deploy_reply = str(self.ser.read_until(expected=b";"))
print("Current line deployed: " + line_deploy_reply + " m")
old_line_deploy_reply = str(self.ser.read_until(expected=b";"))[2:-2]
self.ser.write(b'UF[13]=' + str(self.deploy_target).encode('ascii') + b'\r')
throwaway = self.ser.read_until(expected=b'UF[13]=')
line_deploy_reply = str(self.ser.read_until(expected=b";"))
print("Now deploying line to: " + line_deploy_reply + " m")
target_line_deploy_reply = str(self.ser.read_until(expected=b";"))[2:-4]
print("Now deploying line to: " + target_line_deploy_reply + " m. Line currently at "+old_line_deploy_reply+" m.")
winch_moving = True
while winch_moving is True:
@ -314,29 +317,28 @@ class WinchControl:
throwaway = self.ser.read_until(expected=b'MS\r')
motion_status_reply = self.ser.read_until(expected=b";")
if motion_status_reply == b'2;':
print("Winch still in motion")
time.sleep(0.1)
self.ser.write(b'UF[13]\r')
throwaway = self.ser.read_until(expected=b'UF[13]\r')
line_deploy_reply = str(self.ser.read_until(expected=b";"))
line_deploy_reply = str(self.ser.read_until(expected=b";"))[2:-2]
self.ser.write(b'JV\r')
throwaway = self.ser.read_until(expected=b'JV\r')
line_speed_reply = str(self.ser.read_until(expected=b";"))
line_speed_reply = str(self.ser.read_until(expected=b";"))[2:-2]
print("Current line deployed: " + line_deploy_reply + " m with "+line_speed_reply+
" m/s. Target: " + str(self.deploy_target) + " m.")
" m/s. Target: " + str(self.deploy_target) + " m. Winch still in motion")
elif motion_status_reply == b'0;':
self.ser.write(b'MS\r')
throwaway = self.ser.read_until(expected=b'MS\r')
motion_status_reply = self.ser.read_until(expected=b";")
if motion_status_reply == b'0;':
print("Winch stationary and enabled")
second_motion_status_reply = self.ser.read_until(expected=b";")
if second_motion_status_reply == b'0;':
time.sleep(0.1)
self.ser.write(b'UF[13]\r')
throwaway = self.ser.read_until(expected=b'UF[13]\r')
line_deploy_reply = str(self.ser.read_until(expected=b";"))
print("Current line deploy: " + line_deploy_reply + " m. Target: "
+ str(self.deploy_target) + " m.")
print("Target reached.")
line_deploy_reply = str(self.ser.read_until(expected=b";"))[2:-2]
print("Current line deployed: " + line_deploy_reply + " m. Target: "
+ str(self.deploy_target) + " m. Target reached.")
print("Winch stationary and enabled")
print("DEBUG: MS1: "+str(motion_status_reply)+" MS1: "+str(second_motion_status_reply))
winch_moving = False
elif motion_status_reply == b'3;':
print("Winch main motor disabled")

2
data/pull_parameter.json

@ -1,7 +1,7 @@
{"winch_port": "/dev/ttyUSB0",
"time_firstpull" : 120000,
"pull_interval_minutes": 2,
"pull_interval_minutes": 5,
"warmup_seconds" : 5,
"bottom_pause" : 5,
"top_pause" : 5,

79
output/cast_log

@ -0,0 +1,79 @@
PRESS "Ctrl+C" ANYTIME FOR EMERGENCY STOP
Setting line speed to 0.02 m/s
Setting deploy target to 0 m
Open connection to winch on Port /dev/ttyUSB0... winch connection established on port /dev/ttyUSB0
Winch main motor is disabled
Waiting until 2022-12-16 15:29:20 for next movement -> 6s... Waiting until 2022-12-16 15:29:20 for next movement -> 4s... Waiting until 2022-12-16 15:29:20 for next movement -> 4s... Wait time complete.
enabling main motor... main motor now enabled!
Winch is stationary and enabled
System Status:
System Status Decimal Value: 24576
System Status Bit Values: 110000000000000
WinchInMotion -> False
LevelWindHomed -> False
DrumCommunicationError -> False
LevelWindCommunicationError -> False
JogIn -> False
JogOut -> False
MoveToPositionIn -> False
MoveToPositionOut -> False
WinchWasNotSafelyShutdown -> False
LevelWindIsDisabled -> False
LevelWindGearingByVelocity -> False
LevelWindGearingByPosition -> True
BackupBatteryCharging -> True
ReelInLimitActive -> False
UnwindLimitReached -> False
LevelWindManual -> False
Winch connection opened, motor enabled.
Setting line speed to 0.02 m/s
Setting deploy target to 0.1 m
Waiting until 2022-12-16 15:29:20 for next movement -> 0s... Wait time complete.
New line speed at 0.02 m/s. Old speed was 0.020000 m/s.
Now deploying line to: 0.1 m. Line currently at 0.500240 m.
Current line deployed: 0.479568 m with -0.019961 m/s. Target: 0.1 m. Winch still in motion
Current line deployed: 0.454617 m with -0.016396 m/s. Target: 0.1 m. Winch still in motion
Current line deployed: 0.431091 m with -0.017109 m/s. Target: 0.1 m. Winch still in motion
Current line deployed: 0.406853 m with -0.019961 m/s. Target: 0.1 m. Winch still in motion
Current line deployed: 0.380478 m with -0.020674 m/s. Target: 0.1 m. Winch still in motion
Current line deployed: 0.356239 m with -0.022100 m/s. Target: 0.1 m. Winch still in motion
Current line deployed: 0.331287 m with -0.023525 m/s. Target: 0.1 m. Winch still in motion
Current line deployed: 0.307049 m with -0.024238 m/s. Target: 0.1 m. Winch still in motion
Current line deployed: 0.282097 m with -0.018535 m/s. Target: 0.1 m. Winch still in motion
Current line deployed: 0.256435 m with -0.019248 m/s. Target: 0.1 m. Winch still in motion
Current line deployed: 0.232197 m with -0.018535 m/s. Target: 0.1 m. Winch still in motion
Current line deployed: 0.207958 m with -0.020674 m/s. Target: 0.1 m. Winch still in motion
Current line deployed: 0.183720 m with -0.019961 m/s. Target: 0.1 m. Winch still in motion
Current line deployed: 0.159481 m with -0.019961 m/s. Target: 0.1 m. Winch still in motion
Current line deployed: 0.133106 m with -0.016396 m/s. Target: 0.1 m. Winch still in motion
Current line deployed: 0.108868 m with -0.018535 m/s. Target: 0.1 m. Winch still in motion
Current line deployed: 0.100311 m. Target: 0.1 m. Target reached.
Winch stationary and enabled
DEBUG: MS1: b'0;' MS1: b'0;'
Setting line speed to 0.02 m/s
Setting deploy target to 0.5 m
Waiting until 2022-12-16 15:30:00 for next movement -> 12s... Waiting until 2022-12-16 15:30:00 for next movement -> 10s... Waiting until 2022-12-16 15:30:00 for next movement -> 8s... Waiting until 2022-12-16 15:30:00 for next movement -> 6s... Waiting until 2022-12-16 15:30:00 for next movement -> 4s... Waiting until 2022-12-16 15:30:00 for next movement -> 4s... Wait time complete.
New line speed at 0.02 m/s. Old speed was 0.020000 m/s.
Now deploying line to: 0.5 m. Line currently at 0.100311 m.
Current line deployed: 0.120983 m with 0.019961 m/s. Target: 0.5 m. Winch still in motion
Current line deployed: 0.147362 m with 0.019248 m/s. Target: 0.5 m. Winch still in motion
Current line deployed: 0.171600 m with 0.018535 m/s. Target: 0.5 m. Winch still in motion
Current line deployed: 0.195839 m with 0.017109 m/s. Target: 0.5 m. Winch still in motion
Current line deployed: 0.220078 m with 0.024951 m/s. Target: 0.5 m. Winch still in motion
Current line deployed: 0.246456 m with 0.014971 m/s. Target: 0.5 m. Winch still in motion
Current line deployed: 0.270691 m with 0.019248 m/s. Target: 0.5 m. Winch still in motion
Current line deployed: 0.294930 m with 0.021387 m/s. Target: 0.5 m. Winch still in motion
Current line deployed: 0.319881 m with 0.024951 m/s. Target: 0.5 m. Winch still in motion
Current line deployed: 0.344120 m with 0.019961 m/s. Target: 0.5 m. Winch still in motion
Current line deployed: 0.371212 m with 0.020674 m/s. Target: 0.5 m. Winch still in motion
Current line deployed: 0.396873 m. Target: 0.5 m. Target reached.
Winch stationary and enabled
DEBUG: MS1: b'0;' MS1: b'0;'
Waiting 0/5 s... Waiting 2/5 s... Waiting 4/5 s... Waiting 4/5 s... Wait time complete.
stopping winch... Winch stopped
disabling main motor... main motor now disabled
Close winch connection on Port /dev/ttyUSB0... winch connection closed on port /dev/ttyUSB0
-------------
CAST COMPLETE. Winch motor disabled, connection closed.
-------------
exiting

24
output/startfile_log

@ -0,0 +1,24 @@
Startfile parameter valid. Next downcast will start at: 2022-12-16 14:58:00
Startfile parameter valid. Next downcast will start at: 2022-12-16 14:58:00
Startfile parameter valid. Next downcast will start at: 2022-12-16 15:00:00
Startfile parameter valid. Next downcast will start at: 2022-12-16 15:00:00
Startfile parameter valid. Next downcast will start at: 2022-12-16 15:02:00
Startfile parameter valid. Next downcast will start at: 2022-12-16 15:02:00
2022-12-16 15:02:11.757029: Startfile parameter valid. Next downcast will start at: 2022-12-16 15:04:00
2022-12-16 15:03:12.095531: Startfile parameter valid. Next downcast will start at: 2022-12-16 15:04:00
2022-12-16 15:04:11.426772: Startfile parameter valid. Next downcast set to: 2022-12-16 15:06:00
2022-12-16 15:04:11.426890: Startfile sent over
2022-12-16 15:05:11.754846: Startfile parameter valid. Next downcast set to: 2022-12-16 15:06:00
2022-12-16 15:05:11.754962: Startfile sent over
2022-12-16 15:06:12.084100: Startfile parameter valid. Next downcast set to: 2022-12-16 15:08:00
2022-12-16 15:06:12.084231: Startfile sent over
2022-12-16 15:07:11.407879: Startfile parameter valid. Next downcast set to: 2022-12-16 15:08:00
2022-12-16 15:07:11.407996: Startfile sent over
2022-12-16 15:10:01.730136: Startfile parameter valid. Next downcast set to: 2022-12-16 15:12:00
2022-12-16 15:10:01.730267: Startfile sent over
2022-12-16 15:19:01.575532: Startfile parameter valid. Next downcast set to: 2022-12-16 15:20:00
2022-12-16 15:19:01.575664: Startfile sent over
2022-12-16 15:24:02.289189: Startfile parameter valid. Next downcast set to: 2022-12-16 15:26:00
2022-12-16 15:24:02.289465: Startfile sent over
2022-12-16 15:28:02.137508: Startfile parameter valid. Next downcast set to: 2022-12-16 15:30:00
2022-12-16 15:28:02.137612: Startfile sent over

13
raspi_crontabs.txt

@ -0,0 +1,13 @@
@reboot sleep 30; export DISPLAY=:0 && python3 /home/pi/Desktop/FINO2_profiling_lift_app/code/RasPi_app.py # Starts raspi lift GUI
@reboot date >> /home/pi/Desktop/date.txt # logs last reboot datetime
# */2 * * * * python3 -u /home/pi/Desktop/FINO2_profiling_lift_app/code/modules/flntus_profiling.py >> /home/pi/Desktop/FINO2_profiling_lift_app/output/terminal_logs/flntus_log 2>&1 # runs and logs flntus scan
# */2 * * * * python3 -u /home/pi/Desktop/FINO2_profiling_lift_app/code/modules/sbe19p_profiling.py >> /home/pi/Desktop/FINO2_profiling_lift_app/output/terminal_logs/sbe19_log 2>&1 # # runs and logs sbe19plus scan
#1 * * * * python3 -u /home/pi/Desktop/FINO2_profiling_lift_app/code/build_monitoring_telegram.py # Logs system parameters
*/10 * * * * python3 -u /home/pi/Desktop/FINO2_profiling_lift_app/code/modules/dht_read_and_log.py >> /home/pi/Desktop/FINO2_profiling_lift_app/output/terminal_logs/dht_log 2>&1 # runs and logs dht sensor
# */2 * * * * sleep 60; python3 -u /home/pi/Desktop/FINO2_profiling_lift_app/code/build_data_telegram.py # Builds telegram from newest measurement data
Loading…
Cancel
Save