def __init__(self,
              host='192.168.0.103',
              port=8989,
              retry_no=5,
              name_modifer=""):
     """
     Initialize Camera Client Class
     :param host: [String] Server host
     :param port: [Int] Server port
     :param retry_no: [Int] Number of retries
     """
     self.host = host
     #self.port = port
     #with open('ports.txt','r') as f:
     #    self.port = int(f.read())
     self.port = port
     self.retryNo = retry_no
     # set logger file
     self.logger = Logger(filename='camera_client' + name_modifer,
                          title="CameraClient",
                          directory='',
                          logexists='append')
     self.logger.start()
     if not self.__auto_retry(self.__create_socket()):
         self.logger.log(f"ERROR: Create socket failure")
         return
     if not self.__auto_retry(self.__connect_to_server()):
         self.logger.log(f"ERROR: Connect to server failure")
         return
Exemple #2
0
    def __init__(self, host=IP_ADDRESS, port=CAMERA_SERVER_PORT, black_and_white=False, retry_no=5):
        """
        Initialize server
        :param host: [String] host address
        :param port: [Int] port
        :param black_and_white: [Bool] Is white and white camera image?
        :param retry_no: [Int] Number of retries
        """
        try:
            self.host = host
        except Exception as e:
            print("Change IP_ADRESS in definitions.py to your dev machine ip adress!")
        self.port = port
        self.bw = black_and_white
        self.retryNo = retry_no
        # set logger file
        self.logger = Logger(filename='server_xavier', title="ServerXavier", directory=LOG_DIRECTORY, logexists='append')
        self.logger.start()
        
        # start up camera
        front_camera_connected = False
        bottom_camera_connected = False
        try:
            front_camera = cv2.VideoCapture(CAMERAS.FRONT_CAMERA_DEVNAME)
            front_camera_connected = True
        except:
            self.logger.log("Front camera not connected")
        try:
            bottom_camera = cv2.VideoCapture(CAMERAS.BOTTOM_CAMERA_DEVNAME)
            bottom_camera_connected = True
        except:
            self.logger.log("Bottom camera not connected")
        if front_camera_connected and bottom_camera_connected:
            self.camerasDict = {"front": front_camera,"bottom": bottom_camera}    
            self.cameraCapture = self.camerasDict["front"]
        elif front_cammera_connected:
            self.camerasDict = {"front": front_camera}    
            self.cameraCapture = self.camerasDict["front"]
        elif bottom_camera_connected:
            self.camerasDict = {"bottom": bottom_camera}    
            self.cameraCapture = self.camerasDict["front"]
        else:
            self.print("No camera connected")
            self.logger.log("No camera connected")
            
        if not self.__auto_retry(self.__create_socket()):
            self.logger.log(f"ERROR: Create socket failure")
            return
        if not self.__auto_retry(self.__bind_socket()):
            self.logger.log(f"ERROR: Bind socket failure")
            return
        self.logger.log(f"Init complete")

        # variables for videoClient use
        self.VIDEO_PATH = ''
        self.VIDEO = None
        self.VIDEO_FRAME_COUNT = 0
    def __init__(self):
        self.sensor = ms5837.MS5837_02BA(
        )  # Default I2C bus is 1 (Raspberry Pi 3)
        self.client = Client(DEPTH_DRIVER_PORT)

        self.logger = DEFLOG.DEPTH_LOCAL_LOG
        if self.logger:
            self.logger = Logger(filename='depth_sensor',
                                 directory=DEFLOG.LOG_DIRECTORY)
Exemple #4
0
    def __init__(self, USB_device_adress=USB.SONAR):
        self.logger = DEFLOG.DISTANCE_LOCAL_LOG
        if DEFLOG.DISTANCE_LOCAL_LOG:
            self.logger = Logger(filename='front_distance',
                                 directory=DEFLOG.LOG_DIRECTORY)

        self.sensor = Ping1D(USB_device_adress, 115200)
        self.log("connected to the device")
        self.client = Client(DISTANCE_DRIVER_PORT)
        self.log("connected to the server")
Exemple #5
0
    def __init__(self):
        self.pi = pigpio.pi()
        self.logger = Logger(filename='light_handling', directory='logs/electro/')

        if not self.pi.connected:
            self.logger.log("pi not connected", logtype='error')
            exit()

        self.logger.log("setup")
        self.setup()
Exemple #6
0
    def __init__(self):
        self.pi = pigpio.pi()
        self.logger = Logger(filename='torpedoes_handling')

        if not self.pi.connected:
            self.logger.log("pi not connected", logtype='error')
            exit()

        self.logger.log("setup")
        self.setup()
Exemple #7
0
    def __init__(self, url= "http://192.168.0.103"):#url=f"http://localhost"):
        """
        :param port: Port of running darknet server
        :param url: Url of running darknet server external eg: "http://192.168.0.104"
        """
        with open('ports.txt','r') as f:
            self.port = str(int(f.read())+2)

        print("Darknet client port",self.port)
        self.url = url
        self.logger = Logger(filename='darknet_client', title="Darknet_Client", directory=LOG_DIRECOTRY, logexists='append')
        self.logger.log(url)
Exemple #8
0
    def __init__(self, log_direcory=""):
        self.serial = serial.Serial(IMU_PORT, 115200, stopbits=2, parity=serial.PARITY_NONE)
        self.lock_rate_of_turn = threading.Lock()
        self.lock_free_acc = threading.Lock()
        self.lock_angular_pos = threading.Lock()
        self.logger = Logger(filename='ahrs_separate', directory=log_direcory, logtype='info',
                             logformat='[{timestamp}] {logtype}:    {message}',
                             title='AHRS logger', logexists='append', console=False) 
        self.close_order = False

        self.yaw_correction = 0.0
        self.previous_yaw = 0.0
Exemple #9
0
    def __init__(self):
        '''
        Creates and stores references of all slave objects.
        '''

        self.logger = Logger(filename='main_xavier',
                             title="Main Xavier",
                             directory=LOG_DIRECOTRY)
        self.logger.start()

        # cameras
        self.camera_client = CameraClient(IP_ADDRESS, name_modifer="_main")
        self.logger.log("Cameras created")

        #communication
        self.communication = Communication()
        self.rpi_reference = self.communication.rpi_reference
        self.logger.log("communication was established")

        # sensors
        self.ahrs = AHRS(self.rpi_reference)
        self.depth_sensor = DepthSensor(self.rpi_reference)
        self.distance_sensor = DistanceSensor(self.rpi_reference)
        self.hydrophones = Hydrophones(self.rpi_reference)
        self.logger.log("sensors created")

        self.sensors = {
            'ahrs': self.ahrs,
            'depth': self.depth_sensor,
            'distance': self.distance_sensor,
            'hydrophones': self.hydrophones
        }
        #control
        self.movements = Movements(self.rpi_reference, self.logger)
        #self.torpedoes = Torpedoes(self.rpi_reference)
        #self.manipulator = Manipulator(self.rpi_reference)
        self.dropper = Dropper(self.rpi_reference)
        self.logger.log("control objects created")

        self.control = {
            'movements': self.movements,
            #torpedoes': self.torpedoes,
            #'manipulator': self.manipulator,
            'dropper': self.dropper
        }

        # task sheduler
        self.task_scheduler = TaskSchedululer(self.control, self.sensors,
                                              self.logger)
        self.logger.log("Task scheduler created")
Exemple #10
0
 def __init__(self):
     self.serial = serial_port = serial.Serial(IMU_PORT,
                                               115200,
                                               stopbits=2,
                                               parity=serial.PARITY_NONE)
     self.lock_rate_of_turn = threading.Lock()
     self.lock_free_acc = threading.Lock()
     self.lock_angular_pos = threading.Lock()
     self.logger = Logger(filename='ahrs',
                          directory='',
                          logtype='info',
                          timestamp='%Y-%m-%d | %H:%M:%S.%f',
                          logformat='[{timestamp}] {logtype}:    {message}',
                          prefix='',
                          postfix='',
                          title='AHRS logger',
                          logexists='append',
                          console=False)
     self.close_order = False
Exemple #11
0
 def __init__(self, host=HOST, port=PORT, retry_no=5):
     """
     Initialize Camera Client Class
     :param host: [String] Server host
     :param port: [Int] Server port
     :param retry_no: [Int] Number of retries
     """
     self.host = host
     self.port = port
     self.retryNo = retry_no
     # set logger file
     self.logger = Logger(filename='save_camera_client',
                          title="Save Camera Client",
                          directory=LOG_DIRECOTRY,
                          logexists='append')
     self.logger.start()
     if not self.__auto_retry(self.__create_socket()):
         self.logger.log(f"ERROR: Create socket failure")
         return
     if not self.__auto_retry(self.__connect_to_server()):
         self.logger.log(f"ERROR: Connect to server failure")
         return
Exemple #12
0
    def __init__(self, host=IP_ADDRESS, port=CAMERA_SERVER_PORT, retry_no=5, name_modifer=""):
        """
        Initialize Camera Client Class
        :param host: [String] Server host
        :param port: [Int] Server port
        :param retry_no: [Int] Number of retries
        """
        self.host = host
        self.port = port
        self.retryNo = retry_no
        # set logger file
        self.logger = Logger(filename='camera_client' + name_modifer, title="CameraClient", directory=LOG_DIRECOTRY,
                             logexists='append')
        self.logger.start()
        if not self.__auto_retry(self.__create_socket()):
            self.logger.log(f"ERROR: Create socket failure")
            return
        if not self.__auto_retry(self.__connect_to_server()):
            self.logger.log(f"ERROR: Connect to server failure")
            return

        self.VIDEO_PATH = input("Enter video's ABSOLUTE path >> ")
Exemple #13
0
from flask import Flask, request, Response
import time
import pickle
import os
import argparse as ap
from neural_networks.utils.DarknetYoloModel import DarknetYoloModel
from camera_server.cameraClient import CameraClient
from utils.project_managment import PROJECT_ROOT
from definitions import IP_ADDRESS, LOG_DIRECOTRY
from logpy.LogPy import Logger

if __name__ == "__main__":
    logger = Logger(filename='darknet_server',
                    title="Darknet_Server",
                    directory=LOG_DIRECOTRY,
                    logexists='append')

    parser = ap.ArgumentParser(description="Darknet yolo server")
    #parser.add_argument("-p", '--port', default=5000, type=int, help="Port on which server will be run")
    #parser.add_argument("-m", '--model', required=True, type=str, help="Path to model folder, relative to project root")
    parser.add_argument("-t",
                        '--threshold',
                        default=0.5,
                        type=float,
                        help="Detection threshold (from 0 to 1)")

    args = parser.parse_args()

    server = Flask(__name__)

    cam_client = CameraClient(host=str(os.system('hostname -I')))
 def __init__(self):
     self.sensor = ms5837.MS5837_30BA(
     )  # Default I2C bus is 1 (Raspberry Pi 3)
     self.client = Client(ports.DEPTH_DRIVER_PORT)
     self.logger = Logger(filename='depth')

def set_engines(powers):
    spi.writebytes(struct.pack("B", 255))
    for i in REMAP_ENGINES_LIST:
        x = 100 + powers[i] * 100
        x = int(x)
        spi.writebytes(struct.pack("B", x))
    for i in range(5):
        tmp = spi.readbytes(1)[0]


if __name__ == '__main__':
    logger = DEFLOG.MOVEMENTS_LOCAL_LOG
    if logger:
        logger = Logger(filename='zmq_engine_client',
                        directory=DEFLOG.LOG_DIRECTORY)
    engine_slave = rov_comm.Client(ports.ENGINE_MASTER_PORT)

    if MODE == 'ROV4':
        spi = spidev.SpiDev()
        spi.open(0, 0)
        spi.max_speed_hz = 15600000
    else:
        engine_driver = EngineDriver()

    print("WIP")
    while True:
        try:
            movements = engine_slave.get_data()  #robimy z byte na movements
            if logger:
                logger.log("movements: " + str(movements))
Exemple #16
0
    def __init__(self):
        '''
        Creates and stores references of all slave objects.
        '''
        self.logger = Logger(filename='main',
                             title="Main",
                             directory=DEFLOG.LOG_DIRECTORY)

        #Sensors initialization
        self.ahrs = None
        self.depth = None
        self.hydrophones = None
        self.distance = None
        if SENSORS.AHRS:
            self.ahrs = AHRS(port=ports.AHRS_CLIENT_PORT,
                             main_logger=self.logger,
                             local_log=DEFLOG.AHRS_LOCAL_LOG,
                             log_timing=DEFLOG.AHRS_LOG_TIMING,
                             log_directory=DEFLOG.LOG_DIRECTORY,
                             mode=MODE)
        if SENSORS.DEPTH:
            self.depth = DepthSensor(port=ports.DEPTH_CLIENT_PORT,
                                     main_logger=self.logger,
                                     local_log=DEFLOG.DEPTH_LOCAL_LOG,
                                     log_timing=DEFLOG.DEPTH_LOG_TIMING,
                                     log_directory=DEFLOG.LOG_DIRECTORY)
        if SENSORS.HYDROPHONES:
            self.hydrophones = HydrophonesPair(
                port=ports.HYDRO_CLIENT_PORT,
                main_logger=self.logger,
                local_log=DEFLOG.HYDROPHONES_LOCAL_LOG,
                log_timing=DEFLOG.HYDROPHONES_LOG_TIMING,
                log_directory=DEFLOG.LOG_DIRECTORY)
        if SENSORS.DISTANCE:
            self.distance = DistanceSensor(
                port=ports.DISTANCE_CLIENT_PORT,
                main_logger=self.logger,
                local_log=DEFLOG.DISTANCE_LOCAL_LOG,
                log_timing=DEFLOG.HYDROPHONES_LOG_TIMING,
                log_directory=DEFLOG.LOG_DIRECTORY)

        #Controls initialization
        self.lights = None
        self.manipulator = None
        self.torpedoes = None
        self.dropper = None
        self.movements = Movements(port=ports.ENGINE_SLAVE_PORT,
                                   depth_sensor_ref=self.depth,
                                   ahrs_ref=self.ahrs,
                                   main_logger=self.logger,
                                   local_log=DEFLOG.MOVEMENTS_LOCAL_LOG,
                                   log_directory=DEFLOG.LOG_DIRECTORY)
        if CONTROL.LIGHTS:
            self.lights = Lights(port=ports.LIGHTS_CLIENT_PORT,
                                 main_logger=self.logger)
        if CONTROL.MANIPULATOR:
            self.manipulator = Manipulator(port=ports.MANIP_CLIENT_PORT,
                                           main_logger=self.logger)
        if CONTROL.TORPEDOES:
            self.torpedoes = Torpedoes(
                fire_client_port=ports.TORPEDO_FIRE_CLIENT_PORT,
                ready_driver_port=ports.TORPEDO_READY_DRIVER_PORT,
                main_logger=self.logger,
                local_log=DEFLOG.TORPEDOES_LOCAL_LOG,
                log_directory=DEFLOG.LOG_DIRECTORY)
        if CONTROL.DROPPER:
            self.dropper = Dropper(self.logger)

        #Run threads, in control for local logers

        self.logger.start()
        if SENSORS.DEPTH:
            self.depth.run()
        if SENSORS.AHRS:
            self.ahrs.run()
        if SENSORS.HYDROPHONES:
            self.hydrophones.run()
        if SENSORS.DISTANCE:
            self.distance.run()

        self.movements.run()
        if CONTROL.MANIPULATOR:
            self.manipulator.run()
        if CONTROL.LIGHTS:
            self.manipulator.run()
        if CONTROL.TORPEDOES:
            self.torpedoes.run()

        self.sensors_refs = {
            'AHRS': self.ahrs,
            'DepthSensor': self.depth,
            'HydrophonesPair': self.hydrophones,
            'DistanceSensor': self.distance,
            'Movements': self.movements,
            'Lights': self.lights,
            'Manipulator': self.manipulator,
            'Torpedoes': self.torpedoes,
            'dropper': self.dropper
        }
        #Here you can add more feature classes
        #Remeber then to provide proper Communication class methods

        self.comm = Communication(self.sensors_refs,
                                  RPI_ADDRESS,
                                  main_logger=self.logger)
        '''
Exemple #17
0
    def __init__(self,
                 host=str(os.system('hostname -I')),
                 black_and_white=False,
                 retry_no=5):
        """
        Initialize server
        :param host: [String] host address
        :param port: [Int] port
        :param black_and_white: [Bool] Is white and white camera image?
        :param retry_no: [Int] Number of retries
        """
        self.host = host
        with open('ports.txt', 'r') as f:
            self.port = int(f.read())
        self.bw = black_and_white
        self.retryNo = retry_no
        # set logger file
        self.logger = Logger(filename='server_xavier',
                             title="ServerXavier",
                             directory=LOG_DIRECOTRY,
                             logexists='append')
        self.logger.start()
        self.logger.log('Camera server port (darknet port +2) ' +
                        str(self.port))

        # start up camera

        front_camera_connected = False
        bottom_camera_connected = False
        try:
            front_camera = cv2.VideoCapture(CAMERAS.FRONT_CAMERA_DEVNAME)
            front_camera_connected = True
        except:
            self.logger.log("Front camera not connected")
        try:
            bottom_camera = cv2.VideoCapture(CAMERAS.BOTTOM_CAMERA_DEVNAME)
            bottom_camera_connected = True
        except:
            self.logger.log("Bottom camera not connected")
        if front_camera_connected and bottom_camera_connected:

            self.camerasDict = {"front": front_camera, "bottom": bottom_camera}
            self.cameraCapture = self.camerasDict["front"]
        elif front_camera_connected:
            self.camerasDict = {"front": front_camera}
            self.cameraCapture = self.camerasDict["front"]
        elif bottom_camera_connected:
            self.camerasDict = {"bottom": bottom_camera}
            self.camerasDict = {"front": front_camera, "bottom": bottom_camera}
            self.cameraCapture = self.camerasDict["front"]
        elif front_camera_connected:
            self.camerasDict = {"front": front_camera}
            self.cameraCapture = self.camerasDict["front"]
        elif bottom_camera_connected:
            self.camerasDict = {"bottom": bottom_camera}

            self.cameraCapture = self.camerasDict["front"]
        else:
            self.print("No camera connected")
            self.logger.log("No camera connected")

        if not self.__auto_retry(self.__create_socket()):
            self.logger.log(f"ERROR: Create socket failure")
            return
        if not self.__auto_retry(self.__bind_socket()):
            self.logger.log(f"ERROR: Bind socket failure")
            return
        self.logger.log(f"Init complete")

        # variables for videoClient use
        self.VIDEO_PATH = ''
        self.VIDEO = None
        self.VIDEO_FRAME_COUNT = 0