Skip to main content
. 2019 Dec 6;19(24):5387. doi: 10.3390/s19245387
Algorithm 1 Executing the ROV’s algorithms by performing parallel computing.
  • 1:

    import sys                     # System parameters and functions

  • 2:

    from Tkinter import  # Library for GUI

  • 3:

    import cv2                    # Library for image processing  

  • 4:

    import threading       # Library for parallel computing by threats  

  • 5:

    import serial                  # Library for serial communication  

  • 6:

    def ROV_Parallel_Computing ( )  

  • 7:

         def Motors_Control_and_Temperature( )  # Function for motor control and temperature sensing.  

  • 8:

            switch( PushButton ( ) ) # Configuration of the motions  

  • 9:

                case 1:  

  • 10:

                   def Config_UP ( )  

  • 11:

                case 2:  

  • 12:

                   def Config_DOWN ( )  

  • 13:

                case 3:  

  • 14:

                   def Config_LEFT ( )  

  • 15:

                case 4:  

  • 16:

                   def Config_RIGHT ( )  

  • 17:

                case 5:  

  • 18:

                   def Config_STOP ( )  

  • 19:

                case 6:  

  • 20:

                   def Config_CALIBRATE ( )  

  • 21:

             if(Serial.read == TEMP) # Read temperature  

  • 22:

                Read Temperature  

  • 23:

                Print Temperature.  

  • 24:

                Store Temperature.  

  • 25:

             endif  

  • 26:

         def Acquire3D_Position( )    # Read 3D position  

  • 27:

              def Read_Acl( )       # Read the accelerometer data  

  • 28:

              def Read_Gyr( )       # Read the gyroscope data  

  • 29:

              def filter_Comp( )   # Filtering accelerometer and gyro.  

  • 30:

              print( ’positon’ )  

  • 31:

         def Video_Capture( ):  

  • 32:

              print ("Camera")  

  • 33:

              cap=cv2.VideoCapture(0)       # Video capture.  

  • 34:

              while (1)  

  • 35:

                  ret, FPS = cap.read().  

  • 36:

                  cv2.imshow(’ROV CAM’,frame)  

  • 37:

                  CPUTEMP = Read_CPU_temp.  

  • 38:

                  print (FPS, CPUTEMP)  

  • 39:

                  key= cv2.waitKey(1)  

  • 40:

                  if key == 27:  

  • 41:

                         break  

  • 42:

              endwhile  

  • 43:

              cap.release.  

  • 44:

              cv2.destroyallWindows.  

  • 45:

         ROV_Parallel_Computing.mainloop()  

  • 46:

    try:         # Setup communication with Arduino Nano Microcontroller.  

  • 47:

                       ard = serial.Serial()  

  • 48:

                       ard.port = ’/dev/ttyUSB0’.  

  • 49:

                       ard.baudrate = 9600.  

  • 50:

                       ard.timeout = 3.  

  • 51:

                       ard.open().  

  • 52:

                       print(’Wait a moment....’).  

  • 53:

    except:.  

  • 54:

                       print(’Connection Error’)  

  • 55:

                       sys.exit().  

  • 56:

    # Parallel algorithms execution.  

  • 57:

    # Assign a thread for parallel execution.  

  • 58:

    CAMERA=threading.Thread(target = Video_Capture )                     

  • 59:

    CAMERA.start().  .

  • 60:

    POSITION=threading.Thread(target = Acquire_3D_Position )              

  • 61:

    POSITION.start().  

  • 62:

    MOTORS=threading.Thread(target = Motors_Control_and_Temperature )  

  • 63:

    MOTORS.start().  .

  • 64:

    APP=threading.Thread(target = ROV_Parallel_Computing)                 

  • 65:

    APP.start()