Simulation Core
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

716 lines
21 KiB

  1. module COperationScenariosMain
  2. use CIActionReference
  3. implicit none
  4. public
  5. procedure (ActionVoid), pointer :: UpdateUnityPtr
  6. contains
  7. ! subroutine OperationScenarios_Setup()
  8. ! use CSimulationVariables
  9. ! implicit none
  10. ! call OnSimulationInitialization%Add(OperationScenarios_Init)
  11. ! call OnSimulationStop%Add(OperationScenarios_Init)
  12. ! !call OnOperationScenariosStep%Add(OperationScenarios_Step)
  13. ! !call OnOperationScenariosOutput%Add(OperationScenarios_Output)
  14. ! call OnOperationScenariosMain%Add(OperationScenariosMainBody)
  15. ! end subroutine
  16. ! subroutine OperationScenarios_Init
  17. ! use COperationScenariosSettings, OperationScenariosInitialization => Initialization
  18. ! implicit none
  19. ! call OperationScenariosInitialization()
  20. ! end subroutine OperationScenarios_Init
  21. subroutine OperationScenarios_Step
  22. use CSimulationVariables
  23. use CKellyConnectionEnum
  24. use CElevatorConnectionEnum
  25. use CCloseKellyCockLedNotification
  26. use CCloseSafetyValveLedNotification
  27. use CFillMouseHoleLedNotification
  28. use CIrIBopLedNotification
  29. use CIrSafetyValveLedNotification
  30. use CLatchLedNotification
  31. use COpenKellyCockLedNotification
  32. use COpenSafetyValveLedNotification
  33. use CSlipsNotification
  34. use CSwingLedNotification
  35. use CTongNotification
  36. use CUnlatchLedNotification
  37. use CInstallFillupHeadPermission
  38. use CInstallMudBucketPermission
  39. use CIrIbopPermission
  40. use CIrSafetyValvePermission
  41. use CRemoveFillupHeadPermission
  42. use CRemoveMudBucketPermission
  43. use CHookHeight
  44. use CIbopHeight
  45. use CNearFloorConnection
  46. use CSafetyValveHeight
  47. use CSlackOff
  48. use CStandRack
  49. use CStringPressure
  50. use CZeroStringSpeed
  51. use CUnityInputs, only: &
  52. Get_ElevatorConnectionPossible, &
  53. Get_JointConnectionPossible, &
  54. Get_ElevatorPickup, &
  55. Get_NearFloorPosition, &
  56. Get_SingleSetInMouseHole
  57. use CBucketEnum
  58. use CElevatorEnum
  59. use CHeadEnum
  60. use CIbopEnum
  61. use CKellyEnum
  62. use CMouseHoleEnum
  63. use COperationConditionEnum
  64. use CSafetyValveEnum
  65. use CSlipsEnum
  66. use CSwingEnum
  67. use CTongEnum
  68. use CStringUpdate
  69. use CFlowPipeDisconnectEnum
  70. use CFlowKellyDisconnectEnum
  71. use CFillupHeadPermission
  72. use CSwingDrillPermission
  73. use CSwingOffPermission
  74. use CSwingTiltPermission
  75. use CTdsStemJointHeight
  76. use CTdsConnectionModesEnum
  77. use CTdsElevatorModesEnum
  78. use CTdsSpineEnum
  79. use CTdsSwingEnum
  80. use CTdsTongEnum
  81. use CTdsBackupClamp
  82. use CTdsIbopLedNotification
  83. use CTdsPowerLedNotification
  84. use CTdsTorqueWrenchLedNotification
  85. implicit none
  86. call Evaluate_KellyConnection()
  87. call Evaluate_ElevatorConnection()
  88. call Evaluate_CloseKellyCockLed()
  89. call Evaluate_CloseSafetyValveLed()
  90. call Evaluate_FillMouseHoleLed()
  91. call Evaluate_IrIBopLed()
  92. call Evaluate_IrSafetyValveLed()
  93. call Evaluate_LatchLed()
  94. call Evaluate_OpenKellyCockLed()
  95. call Evaluate_OpenSafetyValveLed()
  96. call Evaluate_SlipsNotification()
  97. call Evaluate_SwingLed()
  98. call Evaluate_TongNotification()
  99. call Evaluate_UnlatchLed()
  100. call Evaluate_InstallFillupHeadPermission()
  101. call Evaluate_InstallMudBucketPermission()
  102. call Evaluate_IrIbopPermission()
  103. call Evaluate_IrSafetyValvePermission()
  104. call Evaluate_RemoveFillupHeadPermission()
  105. call Evaluate_RemoveMudBucketPermission()
  106. call Evaluate_MudBucket()
  107. call Evaluate_Elevator()
  108. call Evaluate_FillupHead()
  109. call Evaluate_Ibop()
  110. call Evaluate_Kelly()
  111. call Evaluate_MouseHole()
  112. call Evaluate_MouseHole()
  113. call Evaluate_OperationCondition()
  114. call Evaluate_SafetyValve()
  115. call Evaluate_Slips()
  116. call Evaluate_Swing()
  117. call Evaluate_Tong()
  118. call Evaluate_StringUpdate()
  119. call Evaluate_FlowKellyDisconnect()
  120. call Evaluate_FlowPipeDisconnect()
  121. !if(Get_FillMouseHoleLed()) then
  122. ! call Set_MouseHole(MOUSE_HOLE_FILL)
  123. !else
  124. ! if((Get_KellyConnection() == KELLY_CONNECTION_SINGLE .or.&
  125. ! Get_ElevatorConnection() == ELEVATOR_CONNECTION_SINGLE) .and.&
  126. ! Get_HookHeight() >= 95.0 ) then
  127. ! call Set_MouseHole(MOUSE_HOLE_NEUTRAL)
  128. ! else
  129. ! call Set_MouseHole(MOUSE_HOLE_EMPTY)
  130. ! endif
  131. !endif
  132. !topdrive
  133. call Evaluate_TdsElevatorModes()
  134. call Evaluate_TdsConnectionModes()
  135. call Evaluate_SwingTiltPermission()
  136. call Evaluate_SwingOffPermission()
  137. call Evaluate_SwingDrillPermission()
  138. call Evaluate_FillupHeadPermission()
  139. call Evaluate_TdsTong()
  140. call Evaluate_TdsBackupClamp()
  141. call Evaluate_TdsSwing()
  142. call Evaluate_TdsSpine()
  143. call Evaluate_PowerLed()
  144. call Evaluate_IbopLed()
  145. call Evaluate_TorqueWrenchLed()
  146. end subroutine OperationScenarios_Step
  147. subroutine OperationScenarios_Output
  148. implicit none
  149. end subroutine OperationScenarios_Output
  150. subroutine OperationScenariosMainBody
  151. use CSimulationVariables
  152. use CKellyConnectionEnum
  153. use CElevatorConnectionEnum
  154. use CCloseKellyCockLedNotification
  155. use CCloseSafetyValveLedNotification
  156. use CFillMouseHoleLedNotification
  157. use CIrIBopLedNotification
  158. use CIrSafetyValveLedNotification
  159. use CLatchLedNotification
  160. use COpenKellyCockLedNotification
  161. use COpenSafetyValveLedNotification
  162. use CSlipsNotification
  163. use CSwingLedNotification
  164. use CTongNotification
  165. use CUnlatchLedNotification
  166. use CInstallFillupHeadPermission
  167. use CInstallMudBucketPermission
  168. use CIrIbopPermission
  169. use CIrSafetyValvePermission
  170. use CRemoveFillupHeadPermission
  171. use CRemoveMudBucketPermission
  172. use CHookHeight
  173. use CIbopHeight
  174. use CNearFloorConnection
  175. use CSafetyValveHeight
  176. use CSlackOff
  177. use CStandRack
  178. use CStringPressure
  179. use CZeroStringSpeed
  180. use CUnityInputs, only: &
  181. Get_ElevatorConnectionPossible, &
  182. Get_JointConnectionPossible, &
  183. Get_ElevatorPickup, &
  184. Get_NearFloorPosition, &
  185. Get_SingleSetInMouseHole
  186. use CBucketEnum
  187. use CElevatorEnum
  188. use CHeadEnum
  189. use CIbopEnum
  190. use CKellyEnum
  191. use CMouseHoleEnum
  192. use COperationConditionEnum
  193. use CSafetyValveEnum
  194. use CSlipsEnum
  195. use CSwingEnum
  196. use CTongEnum
  197. use CStringUpdate
  198. use CFlowPipeDisconnectEnum
  199. use CFlowKellyDisconnectEnum
  200. use CFillupHeadPermission
  201. use CSwingDrillPermission
  202. use CSwingOffPermission
  203. use CSwingTiltPermission
  204. use CTdsStemJointHeight
  205. use CTdsConnectionModesEnum
  206. use CTdsElevatorModesEnum
  207. use CTdsSpineEnum
  208. use CTdsSwingEnum
  209. use CTdsTongEnum
  210. use CTdsBackupClamp
  211. use CTdsIbopLedNotification
  212. use CTdsPowerLedNotification
  213. use CTdsTorqueWrenchLedNotification
  214. implicit none
  215. loop1: do
  216. call Evaluate_KellyConnection()
  217. call Evaluate_ElevatorConnection()
  218. call Evaluate_CloseKellyCockLed()
  219. call Evaluate_CloseSafetyValveLed()
  220. call Evaluate_FillMouseHoleLed()
  221. call Evaluate_IrIBopLed()
  222. call Evaluate_IrSafetyValveLed()
  223. call Evaluate_LatchLed()
  224. call Evaluate_OpenKellyCockLed()
  225. call Evaluate_OpenSafetyValveLed()
  226. call Evaluate_SlipsNotification()
  227. call Evaluate_SwingLed()
  228. call Evaluate_TongNotification()
  229. call Evaluate_UnlatchLed()
  230. call Evaluate_InstallFillupHeadPermission()
  231. call Evaluate_InstallMudBucketPermission()
  232. call Evaluate_IrIbopPermission()
  233. call Evaluate_IrSafetyValvePermission()
  234. call Evaluate_RemoveFillupHeadPermission()
  235. call Evaluate_RemoveMudBucketPermission()
  236. call Evaluate_MudBucket()
  237. call Evaluate_Elevator()
  238. call Evaluate_FillupHead()
  239. call Evaluate_Ibop()
  240. call Evaluate_Kelly()
  241. call Evaluate_MouseHole()
  242. call Evaluate_MouseHole()
  243. call Evaluate_OperationCondition()
  244. call Evaluate_SafetyValve()
  245. call Evaluate_Slips()
  246. call Evaluate_Swing()
  247. call Evaluate_Tong()
  248. call Evaluate_StringUpdate()
  249. call Evaluate_FlowKellyDisconnect()
  250. call Evaluate_FlowPipeDisconnect()
  251. !if(Get_FillMouseHoleLed()) then
  252. ! call Set_MouseHole(MOUSE_HOLE_FILL)
  253. !else
  254. ! if((Get_KellyConnection() == KELLY_CONNECTION_SINGLE .or.&
  255. ! Get_ElevatorConnection() == ELEVATOR_CONNECTION_SINGLE) .and.&
  256. ! Get_HookHeight() >= 95.0 ) then
  257. ! call Set_MouseHole(MOUSE_HOLE_NEUTRAL)
  258. ! else
  259. ! call Set_MouseHole(MOUSE_HOLE_EMPTY)
  260. ! endif
  261. !endif
  262. !topdrive
  263. call Evaluate_TdsElevatorModes()
  264. call Evaluate_TdsConnectionModes()
  265. call Evaluate_SwingTiltPermission()
  266. call Evaluate_SwingOffPermission()
  267. call Evaluate_SwingDrillPermission()
  268. call Evaluate_FillupHeadPermission()
  269. call Evaluate_TdsTong()
  270. call Evaluate_TdsBackupClamp()
  271. call Evaluate_TdsSwing()
  272. call Evaluate_TdsSpine()
  273. call Evaluate_PowerLed()
  274. call Evaluate_IbopLed()
  275. call Evaluate_TorqueWrenchLed()
  276. !if (IsStopped==.true.) exit loop1
  277. if(IsStopped) call Quit()
  278. call sleepqq(100)
  279. enddo loop1
  280. end subroutine OperationScenariosMainBody
  281. subroutine SubscribeUpdateUnity(a)
  282. !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeUpdateUnity
  283. !DEC$ ATTRIBUTES ALIAS: 'SubscribeUpdateUnity' :: SubscribeUpdateUnity
  284. implicit none
  285. procedure (ActionVoid) :: a
  286. UpdateUnityPtr => a
  287. end subroutine
  288. subroutine UpdateUnity()
  289. implicit none
  290. if(associated(UpdateUnityPtr)) call UpdateUnityPtr()
  291. end subroutine
  292. subroutine PreProcessingSnapshot
  293. !DEC$ ATTRIBUTES DLLEXPORT :: PreProcessingSnapshot
  294. !DEC$ ATTRIBUTES ALIAS: 'PreProcessingSnapshot' :: PreProcessingSnapshot
  295. use CSwingEnumVariables
  296. use CSlipsEnumVariables
  297. use CHookVariables
  298. use CTongEnumVariables
  299. use CHoistingVariables
  300. use CKellyConnectionEnumVariables
  301. use CElevatorConnectionEnumVariables
  302. use COperationConditionEnumVariables
  303. use CMouseHoleEnumVariables
  304. implicit none
  305. if(Hoisting%DriveType == Kelly_DriveType) then ! kelly mode
  306. if(Get_OperationCondition() == OPERATION_DRILL) then
  307. if(Get_KellyConnection() == KELLY_CONNECTION_NOTHING) then
  308. call Kelly_ConnectionNothing()
  309. elseif (Get_KellyConnection() == KELLY_CONNECTION_STRING) then
  310. call Kelly_ConnectionString()
  311. elseif (Get_KellyConnection() == KELLY_CONNECTION_SINGLE) then
  312. call Kelly_ConnectionSingle()
  313. endif
  314. elseif (Get_OperationCondition() == OPERATION_TRIP) then
  315. if(Get_ElevatorConnection() == ELEVATOR_CONNECTION_NOTHING) then
  316. call Elevator_ConnectionNothing()
  317. elseif (Get_ElevatorConnection() == ELEVATOR_CONNECTION_STRING) then
  318. call Elevator_ConnectionString()
  319. elseif (Get_ElevatorConnection() == ELEVATOR_CONNECTION_STAND) then
  320. call Elevator_ConnectionStand()
  321. elseif (Get_ElevatorConnection() == ELEVATOR_CONNECTION_SINGLE) then
  322. call Elevator_ConnectionSingle()
  323. endif
  324. endif
  325. else ! Topdrive mode
  326. !
  327. endif
  328. ! final adjustments
  329. call Update_MouseHole_From_Snapshot()
  330. end subroutine PreProcessingSnapshot
  331. subroutine Kelly_ConnectionNothing
  332. use CSwingEnumVariables
  333. use CSlipsEnumVariables
  334. use CHookVariables
  335. implicit none
  336. call Set_HookHeight(75.0)
  337. call sleep(1)
  338. ! first wait for unity to get to starting point
  339. loop1: do
  340. if(Get_Swing() == SWING_WELL_END .and. Get_Slips() == SLIPS_SET_END) exit loop1
  341. call sleepqq(100)
  342. enddo loop1
  343. call sleep(1)
  344. !TODO: possibly goto a position to activate swing
  345. ! goto preferred swing position
  346. if(Swing_S == SWING_MOUSE_HOLE_END) then
  347. call Set_Swing(SWING_MOUSE_HOLE_BEGIN)
  348. call UpdateUnity()
  349. loop2: do
  350. if(Get_Swing() == SWING_MOUSE_HOLE_END) exit loop2
  351. call sleepqq(100)
  352. enddo loop2
  353. elseif (Swing_S == SWING_RAT_HOLE_END) then
  354. call Set_Swing(SWING_RAT_HOLE_BEGIN)
  355. call UpdateUnity()
  356. loop3: do
  357. if(Get_Swing() == SWING_RAT_HOLE_END) exit loop3
  358. call sleepqq(100)
  359. enddo loop3
  360. !elseif (Swing_S == SWING_WELL_END) then
  361. ! call Set_Swing(SWING_WELL_BEGIN)
  362. ! call UpdateUnity()
  363. ! loop4: do
  364. ! if(Get_Swing() == SWING_WELL_END) exit loop4
  365. ! call sleepqq(100)
  366. ! enddo loop4
  367. endif
  368. call sleep(3)
  369. ! move to final hook height
  370. call Update_HookHeight_From_Snapshot()
  371. call sleep(3)
  372. end subroutine Kelly_ConnectionNothing
  373. subroutine Kelly_ConnectionString
  374. use CSwingEnumVariables
  375. use CSlipsEnumVariables
  376. use CHookVariables
  377. use CTongEnumVariables
  378. implicit none
  379. call Set_HookHeight(75.0)
  380. call sleep(1)
  381. ! first wait for unity to get to starting point
  382. loop1: do
  383. if(Get_Swing() == SWING_WELL_END .and. Get_Slips() == SLIPS_SET_END) exit loop1
  384. call sleepqq(100)
  385. enddo loop1
  386. call sleep(1)
  387. ! goto connection to string position
  388. call Set_HookHeight_S(66.7)
  389. call sleep(1)
  390. ! start tong makeup
  391. call Set_Tong(TONG_MAKEUP_BEGIN)
  392. call UpdateUnity()
  393. loop2: do
  394. if(Get_Tong() == TONG_MAKEUP_END) exit loop2
  395. call sleepqq(100)
  396. enddo loop2
  397. call sleepqq(100)
  398. ! release slips
  399. call Set_Slips(SLIPS_UNSET_BEGIN)
  400. call UpdateUnity()
  401. loop3: do
  402. if(Get_Slips() == SLIPS_UNSET_END) exit loop3
  403. call sleepqq(100)
  404. enddo loop3
  405. call sleepqq(100)
  406. ! move to final hook height
  407. call Update_HookHeight_From_Snapshot()
  408. call sleep(3)
  409. ! put slips to saved position
  410. if(Slips_S == SLIPS_SET_END) then
  411. call Set_Slips(SLIPS_SET_BEGIN)
  412. call UpdateUnity()
  413. loop4: do
  414. if(Get_Slips() == SLIPS_SET_END) exit loop4
  415. call sleepqq(100)
  416. enddo loop4
  417. call sleep(1)
  418. endif
  419. end subroutine Kelly_ConnectionString
  420. subroutine Kelly_ConnectionSingle
  421. use CSwingEnumVariables
  422. use CSlipsEnumVariables
  423. use CTongEnumVariables
  424. use CHookVariables
  425. implicit none
  426. call Set_HookHeight(75.0)
  427. call sleep(1)
  428. ! first wait for unity to get to starting point
  429. loop1: do
  430. if(Get_Swing() == SWING_WELL_END .and. Get_Slips() == SLIPS_SET_END) exit loop1
  431. call sleepqq(100)
  432. enddo loop1
  433. call sleep(1)
  434. ! goto swing mouse hole position
  435. call Set_HookHeight_S(70.0)
  436. call sleep(1)
  437. ! swing mouse hole
  438. call Set_Swing(SWING_MOUSE_HOLE_BEGIN)
  439. call UpdateUnity()
  440. loop2: do
  441. if(Get_Swing() == SWING_MOUSE_HOLE_END) exit loop2
  442. call sleepqq(100)
  443. enddo loop2
  444. call sleepqq(100)
  445. ! goto makeup pipe location
  446. call Set_HookHeight_S(65.0)
  447. call sleep(1)
  448. ! start tong makeup
  449. call Set_Tong(TONG_MAKEUP_BEGIN)
  450. call UpdateUnity()
  451. loop3: do
  452. if(Get_Tong() == TONG_MAKEUP_END) exit loop3
  453. call sleepqq(100)
  454. enddo loop3
  455. call sleepqq(100)
  456. if (Swing_S == SWING_WELL_END) then ! already in mouse hole
  457. ! goto swing location
  458. call Set_HookHeight_S(98.0)
  459. call sleep(1)
  460. ! goto preferred swing position
  461. call Set_Swing(SWING_WELL_BEGIN)
  462. call UpdateUnity()
  463. loop4: do
  464. if(Get_Swing() == SWING_WELL_END) exit loop4
  465. call sleepqq(100)
  466. enddo loop4
  467. call sleep(2)
  468. endif
  469. ! move to final hook height
  470. call Update_HookHeight_From_Snapshot()
  471. call sleep(3)
  472. end subroutine Kelly_ConnectionSingle
  473. subroutine Elevator_ConnectionNothing
  474. use CSwingEnumVariables
  475. use CSlipsEnumVariables
  476. use CHookVariables
  477. use CKellyEnumVariables
  478. implicit none
  479. call Set_HookHeight(75.0)
  480. call sleep(1)
  481. ! first wait for unity to get to starting point
  482. loop1: do
  483. if(Get_Swing() == SWING_WELL_END .and. Get_Slips() == SLIPS_SET_END) exit loop1
  484. call sleepqq(100)
  485. enddo loop1
  486. call sleep(1)
  487. !TODO: possibly goto a position to activate swing
  488. !! first goto mouse hole
  489. !call Set_Swing(SWING_MOUSE_HOLE_BEGIN)
  490. !call UpdateUnity()
  491. !loop2: do
  492. ! if(Get_Swing() == SWING_MOUSE_HOLE_END) exit loop2
  493. ! call sleepqq(100)
  494. !enddo loop2
  495. !call sleep(1)
  496. !
  497. !! then goto rat hole
  498. !call Set_Swing(SWING_RAT_HOLE_BEGIN)
  499. !call UpdateUnity()
  500. !loop3: do
  501. ! if(Get_Swing() == SWING_RAT_HOLE_END) exit loop3
  502. ! call sleepqq(100)
  503. !enddo loop3
  504. !call sleep(1)
  505. ! kelly back
  506. call Set_Kelly(KELLY_REMOVE)
  507. call sleepqq(100)
  508. ! goto preferred swing position
  509. if(Swing_S == SWING_MOUSE_HOLE_END) then
  510. call Set_Swing(SWING_MOUSE_HOLE_BEGIN)
  511. call UpdateUnity()
  512. loop4: do
  513. if(Get_Swing() == SWING_MOUSE_HOLE_END) exit loop4
  514. call sleepqq(100)
  515. enddo loop4
  516. elseif (Swing_S == SWING_RAT_HOLE_END) then
  517. call Set_Swing(SWING_RAT_HOLE_BEGIN)
  518. call UpdateUnity()
  519. loop5: do
  520. if(Get_Swing() == SWING_RAT_HOLE_END) exit loop5
  521. call sleepqq(100)
  522. enddo loop5
  523. elseif (Swing_S == SWING_WELL_END) then
  524. call Set_Swing(SWING_WELL_BEGIN)
  525. call UpdateUnity()
  526. loop6: do
  527. if(Get_Swing() == SWING_WELL_END) exit loop6
  528. call sleepqq(100)
  529. enddo loop6
  530. endif
  531. call sleepqq(100)
  532. ! move to final hook height
  533. call Update_HookHeight_From_Snapshot()
  534. call sleep(3)
  535. end subroutine Elevator_ConnectionNothing
  536. subroutine Elevator_ConnectionString
  537. implicit none
  538. end subroutine Elevator_ConnectionString
  539. subroutine Elevator_ConnectionStand
  540. implicit none
  541. end subroutine Elevator_ConnectionStand
  542. subroutine Elevator_ConnectionSingle
  543. implicit none
  544. end subroutine Elevator_ConnectionSingle
  545. end module COperationScenariosMain