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.
 
 
 
 
 
 

717 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 COperationScenariosVariables
  302. ! use CElevatorConnectionEnumVariables
  303. use COperationConditionEnumVariables
  304. use CMouseHoleEnumVariables
  305. implicit none
  306. if(Hoisting%DriveType == Kelly_DriveType) then ! kelly mode
  307. if(Get_OperationCondition() == OPERATION_DRILL) then
  308. if(Get_KellyConnection() == KELLY_CONNECTION_NOTHING) then
  309. call Kelly_ConnectionNothing()
  310. elseif (Get_KellyConnection() == KELLY_CONNECTION_STRING) then
  311. call Kelly_ConnectionString()
  312. elseif (Get_KellyConnection() == KELLY_CONNECTION_SINGLE) then
  313. call Kelly_ConnectionSingle()
  314. endif
  315. elseif (Get_OperationCondition() == OPERATION_TRIP) then
  316. if(Get_ElevatorConnection() == ELEVATOR_CONNECTION_NOTHING) then
  317. call Elevator_ConnectionNothing()
  318. elseif (Get_ElevatorConnection() == ELEVATOR_CONNECTION_STRING) then
  319. call Elevator_ConnectionString()
  320. elseif (Get_ElevatorConnection() == ELEVATOR_CONNECTION_STAND) then
  321. call Elevator_ConnectionStand()
  322. elseif (Get_ElevatorConnection() == ELEVATOR_CONNECTION_SINGLE) then
  323. call Elevator_ConnectionSingle()
  324. endif
  325. endif
  326. else ! Topdrive mode
  327. !
  328. endif
  329. ! final adjustments
  330. call Update_MouseHole_From_Snapshot()
  331. end subroutine PreProcessingSnapshot
  332. subroutine Kelly_ConnectionNothing
  333. use CSwingEnumVariables
  334. use CSlipsEnumVariables
  335. use CHookVariables
  336. implicit none
  337. call Set_HookHeight(75.0)
  338. call sleep(1)
  339. ! first wait for unity to get to starting point
  340. loop1: do
  341. if(Get_Swing() == SWING_WELL_END .and. Get_Slips() == SLIPS_SET_END) exit loop1
  342. call sleepqq(100)
  343. enddo loop1
  344. call sleep(1)
  345. !TODO: possibly goto a position to activate swing
  346. ! goto preferred swing position
  347. if(Swing_S == SWING_MOUSE_HOLE_END) then
  348. call Set_Swing(SWING_MOUSE_HOLE_BEGIN)
  349. call UpdateUnity()
  350. loop2: do
  351. if(Get_Swing() == SWING_MOUSE_HOLE_END) exit loop2
  352. call sleepqq(100)
  353. enddo loop2
  354. elseif (Swing_S == SWING_RAT_HOLE_END) then
  355. call Set_Swing(SWING_RAT_HOLE_BEGIN)
  356. call UpdateUnity()
  357. loop3: do
  358. if(Get_Swing() == SWING_RAT_HOLE_END) exit loop3
  359. call sleepqq(100)
  360. enddo loop3
  361. !elseif (Swing_S == SWING_WELL_END) then
  362. ! call Set_Swing(SWING_WELL_BEGIN)
  363. ! call UpdateUnity()
  364. ! loop4: do
  365. ! if(Get_Swing() == SWING_WELL_END) exit loop4
  366. ! call sleepqq(100)
  367. ! enddo loop4
  368. endif
  369. call sleep(3)
  370. ! move to final hook height
  371. call Update_HookHeight_From_Snapshot()
  372. call sleep(3)
  373. end subroutine Kelly_ConnectionNothing
  374. subroutine Kelly_ConnectionString
  375. use CSwingEnumVariables
  376. use CSlipsEnumVariables
  377. use CHookVariables
  378. use CTongEnumVariables
  379. implicit none
  380. call Set_HookHeight(75.0)
  381. call sleep(1)
  382. ! first wait for unity to get to starting point
  383. loop1: do
  384. if(Get_Swing() == SWING_WELL_END .and. Get_Slips() == SLIPS_SET_END) exit loop1
  385. call sleepqq(100)
  386. enddo loop1
  387. call sleep(1)
  388. ! goto connection to string position
  389. call Set_HookHeight_S(66.7)
  390. call sleep(1)
  391. ! start tong makeup
  392. call Set_Tong(TONG_MAKEUP_BEGIN)
  393. call UpdateUnity()
  394. loop2: do
  395. if(Get_Tong() == TONG_MAKEUP_END) exit loop2
  396. call sleepqq(100)
  397. enddo loop2
  398. call sleepqq(100)
  399. ! release slips
  400. call Set_Slips(SLIPS_UNSET_BEGIN)
  401. call UpdateUnity()
  402. loop3: do
  403. if(Get_Slips() == SLIPS_UNSET_END) exit loop3
  404. call sleepqq(100)
  405. enddo loop3
  406. call sleepqq(100)
  407. ! move to final hook height
  408. call Update_HookHeight_From_Snapshot()
  409. call sleep(3)
  410. ! put slips to saved position
  411. if(Slips_S == SLIPS_SET_END) then
  412. call Set_Slips(SLIPS_SET_BEGIN)
  413. call UpdateUnity()
  414. loop4: do
  415. if(Get_Slips() == SLIPS_SET_END) exit loop4
  416. call sleepqq(100)
  417. enddo loop4
  418. call sleep(1)
  419. endif
  420. end subroutine Kelly_ConnectionString
  421. subroutine Kelly_ConnectionSingle
  422. use CSwingEnumVariables
  423. use CSlipsEnumVariables
  424. use CTongEnumVariables
  425. use CHookVariables
  426. implicit none
  427. call Set_HookHeight(75.0)
  428. call sleep(1)
  429. ! first wait for unity to get to starting point
  430. loop1: do
  431. if(Get_Swing() == SWING_WELL_END .and. Get_Slips() == SLIPS_SET_END) exit loop1
  432. call sleepqq(100)
  433. enddo loop1
  434. call sleep(1)
  435. ! goto swing mouse hole position
  436. call Set_HookHeight_S(70.0)
  437. call sleep(1)
  438. ! swing mouse hole
  439. call Set_Swing(SWING_MOUSE_HOLE_BEGIN)
  440. call UpdateUnity()
  441. loop2: do
  442. if(Get_Swing() == SWING_MOUSE_HOLE_END) exit loop2
  443. call sleepqq(100)
  444. enddo loop2
  445. call sleepqq(100)
  446. ! goto makeup pipe location
  447. call Set_HookHeight_S(65.0)
  448. call sleep(1)
  449. ! start tong makeup
  450. call Set_Tong(TONG_MAKEUP_BEGIN)
  451. call UpdateUnity()
  452. loop3: do
  453. if(Get_Tong() == TONG_MAKEUP_END) exit loop3
  454. call sleepqq(100)
  455. enddo loop3
  456. call sleepqq(100)
  457. if (Swing_S == SWING_WELL_END) then ! already in mouse hole
  458. ! goto swing location
  459. call Set_HookHeight_S(98.0)
  460. call sleep(1)
  461. ! goto preferred swing position
  462. call Set_Swing(SWING_WELL_BEGIN)
  463. call UpdateUnity()
  464. loop4: do
  465. if(Get_Swing() == SWING_WELL_END) exit loop4
  466. call sleepqq(100)
  467. enddo loop4
  468. call sleep(2)
  469. endif
  470. ! move to final hook height
  471. call Update_HookHeight_From_Snapshot()
  472. call sleep(3)
  473. end subroutine Kelly_ConnectionSingle
  474. subroutine Elevator_ConnectionNothing
  475. use CSwingEnumVariables
  476. use CSlipsEnumVariables
  477. use CHookVariables
  478. use CKellyEnumVariables
  479. implicit none
  480. call Set_HookHeight(75.0)
  481. call sleep(1)
  482. ! first wait for unity to get to starting point
  483. loop1: do
  484. if(Get_Swing() == SWING_WELL_END .and. Get_Slips() == SLIPS_SET_END) exit loop1
  485. call sleepqq(100)
  486. enddo loop1
  487. call sleep(1)
  488. !TODO: possibly goto a position to activate swing
  489. !! first goto mouse hole
  490. !call Set_Swing(SWING_MOUSE_HOLE_BEGIN)
  491. !call UpdateUnity()
  492. !loop2: do
  493. ! if(Get_Swing() == SWING_MOUSE_HOLE_END) exit loop2
  494. ! call sleepqq(100)
  495. !enddo loop2
  496. !call sleep(1)
  497. !
  498. !! then goto rat hole
  499. !call Set_Swing(SWING_RAT_HOLE_BEGIN)
  500. !call UpdateUnity()
  501. !loop3: do
  502. ! if(Get_Swing() == SWING_RAT_HOLE_END) exit loop3
  503. ! call sleepqq(100)
  504. !enddo loop3
  505. !call sleep(1)
  506. ! kelly back
  507. call Set_Kelly(KELLY_REMOVE)
  508. call sleepqq(100)
  509. ! goto preferred swing position
  510. if(Swing_S == SWING_MOUSE_HOLE_END) then
  511. call Set_Swing(SWING_MOUSE_HOLE_BEGIN)
  512. call UpdateUnity()
  513. loop4: do
  514. if(Get_Swing() == SWING_MOUSE_HOLE_END) exit loop4
  515. call sleepqq(100)
  516. enddo loop4
  517. elseif (Swing_S == SWING_RAT_HOLE_END) then
  518. call Set_Swing(SWING_RAT_HOLE_BEGIN)
  519. call UpdateUnity()
  520. loop5: do
  521. if(Get_Swing() == SWING_RAT_HOLE_END) exit loop5
  522. call sleepqq(100)
  523. enddo loop5
  524. elseif (Swing_S == SWING_WELL_END) then
  525. call Set_Swing(SWING_WELL_BEGIN)
  526. call UpdateUnity()
  527. loop6: do
  528. if(Get_Swing() == SWING_WELL_END) exit loop6
  529. call sleepqq(100)
  530. enddo loop6
  531. endif
  532. call sleepqq(100)
  533. ! move to final hook height
  534. call Update_HookHeight_From_Snapshot()
  535. call sleep(3)
  536. end subroutine Elevator_ConnectionNothing
  537. subroutine Elevator_ConnectionString
  538. implicit none
  539. end subroutine Elevator_ConnectionString
  540. subroutine Elevator_ConnectionStand
  541. implicit none
  542. end subroutine Elevator_ConnectionStand
  543. subroutine Elevator_ConnectionSingle
  544. implicit none
  545. end subroutine Elevator_ConnectionSingle
  546. end module COperationScenariosMain