Ejemplo n.º 1
0
def process_one():

    logger.worker_configurer(self.settings['LOGGER'])
    log = logging.getLogger('ShipShape')

    while True:
        log.info("Hello from process one")
        time.sleep(1)
Ejemplo n.º 2
0
def process_two():

    logger.worker_configurer(self.settings['LOGGER'])
    log = logging.getLogger('ShipShape')

    while True:
        msg = "Hello hello from process two"
        print(msg)
        log.info(msg)
        time.sleep(1)
Ejemplo n.º 3
0
    def __init__(self, settings):
        
        self.cambpix = settings['MODI']['cambpix']
        self.message_types = settings['NMEA']['message_types']
        self.my_mmsi = settings['GENERAL']['my_mmsi']

        self.ship_update = nav_mat.clear_mat(settings['SHIP_MAT']['ship_mat_parameters'])
        self.delete_mat = self.ship_update
        self.rmc_speed = False

        self.logging = False
        # Initiate logger

        if self.logging == True:
            logger.worker_configurer(settings['LOGGER']['log_q'])
            self.log = logging.getLogger('UDPProcessor')
            self.log.info("started")


        self.ROI_ships = settings['SHIP_MAT']['ROI_ships']  # This is the distance to which boats should be considered
    def __init__(self, config_path):
        self.pool0 = ThreadPool(processes=1)
        self.pool1 = ThreadPool(processes=1)
        self.pool2 = ThreadPool(processes=1)
        self.pool3 = ThreadPool(processes=1)
        self.pool4 = ThreadPool(processes=1)
        self.pool5 = ThreadPool(processes=1)
        self.pool6 = ThreadPool(processes=1)

        # Load configuration file
        cnf = ConfigHandler(config_path=config_path)
        self.settings = cnf.get_config(
        )  # will integrate the complete config file later, now just this placeholder
        # self.settings = json.load(open(config_path, 'r'))

        # temporary cheat so I don't have to fix all the original spots which assume 18 cols
        # ships_mat_radar_ext = np.zeros((150,27)) # 9 columns added for radar data - trackid, (lat,lng) x 4 corners

        self.ships_mat = np.zeros(
            (self.settings['SHIP_MAT']['ships_mat_samples'],
             self.settings['SHIP_MAT']['ships_mat_vessels'],
             self.settings['SHIP_MAT']['ship_mat_parameters']))
        self.ships_mat[:, 0, 1] = self.settings['GENERAL'][
            'my_mmsi']  # 244070156.0 #RPA3 244596336.0 #sim
        self.ships_mat[:, :, 14:18] = 15.0  # default ship dimensions

        # port_rec_ATL  = self.settings['port_rec_ATL' ]; ip_rec_ATL  = self.settings['ip_rec_ATL' ]

        # Atlantis commands
        self.start_command = self.settings['MODI']['start_command']
        self.debugging_mode = self.settings['MODI']['debugging_mode']
        self.threaded_mode = self.settings['MODI']['threaded_mode']
        self.cambpix = self.settings['MODI']['cambpix']
        self.udp_mode = self.settings['MODI']['udp_mode']
        self.topic_mode = self.settings['MODI']['topic_mode']
        self.for_send = False

        self.logging = True

        if self.logging == True:
            # Processes
            self.processes = []
            self.log_q = Queue(
                maxsize=30
            )  # making this 30 will output errors if the queue is full
            self.settings['LOGGER']['log_q'] = self.log_q
            # Initiate the logger, must (probably) be done before the other classes initialise.
            logging_proc = Process(name="Logger_Listener",
                                   target=logger.LoggerListener,
                                   args=(self.log_q, self.settings['LOGGER']))
            logging_proc.deamon = True
            logging_proc.start()
            self.processes.append(
                logging_proc
            )  # Its always a good idea to track your processes.
            logger.worker_configurer(
                self.settings["LOGGER"]
            )  # configure local logger with the correct settings
            self.log = logging.getLogger(name="Autopilot")

        # Initializing classes
        self.sc_client = ShipCommClient(
            self.settings['IP_ADDRESSES']["ship_comm_address"],
            local_address=self.settings['IP_ADDRESSES']['self_ip'],
            process_name="autopilot")
        # self.SendAt = UDPSender(self.settings['nav_control']['ip_send_atlantis'], self.settings['nav_control']['port_send_atlantis'])
        self.UDPPEM = UDPP(self.settings)  # Process UDP streams
        self.NvPath = NavPath(self.settings)  # Calculate Paths
        self.NvCtrl = SimpleControls(
            self.settings)  # For sending control commands to ship
        # CodeAn  = CodeAnalytics()#For Debugging code

        self.engaged = False
Ejemplo n.º 5
0
    def __init__(self, settings):

        self.topic_name = settings["TOPICS"]["nav_control"]
        self.metrics_topic = settings["TOPICS"]["metrics_topic"]

        serial_control = settings['MODI']['serial_control']

        self.iter_time = time.time()
        self.nmea_make = NMEAStrings()
        self.logging = False
        if self.logging == True:
            logger.worker_configurer(settings['LOGGER']['log_q'])
        self.log = logging.getLogger('CONTROL')

        # TODO: We would likely want to have a single topic for sending controls, but there is
        # self.SendAtln = UDPSender(settings['IP_ADDRESSES']['ip_send_atlantis'],
        #                           settings['UDP_PORTS']['port_send_atlantis'])
        self.SendRPA3 = UDPSender(settings['IP_ADDRESSES']['ip_send_SendRPA3'],
                                  settings['UDP_PORTS']['port_send_SendRPA3'])

        # self.SendArduino = SerialSender(settings['nav_control']['com_send_Arduino'],
        # settings['nav_control']['baud_send_Arduino'])

        if serial_control == False:
            self.SendArduino = SerialDummy('/dev/ttyS1', 115200)

        if serial_control == True:
            self.SendArduino = SerialSender('/dev/ctrl', 500000)

        # StaticPath = False
        self.SendTRC = True  # False

        # PID
        self.turning_right = True

        recieved = 0
        ships_mat = 0

        for_send = self.nmea_make.ROR(0, 0)
        self.SendArduino.send_string(recieved, for_send, ships_mat)
        for_send = self.nmea_make.RSA(0, 0)
        # self.SendAtln.send_string(recieved, for_send, ships_mat)
        self.t_reg = time.time()
        self.t_reg_plot = time.time()
        # plotting properties
        self.x_vec = np.linspace(0, 1, 1000 + 1)[0:-1]
        self.y_vec = np.zeros(len(self.x_vec))
        self.hdg_input = np.zeros(len(self.x_vec))
        self.line1 = []
        self.line2 = []

        self.manoeuvre = None
        self.manoeuvre_check = None

        #circle right
        self.heading_difference_circle_right = 0.0
        self.check_circle_manoeuvre_right = 0
        self.t_start_manoeuvre_circle_right = 0.0
        self.t_end_manoeuvre_circle_right = time.time()


        #circle left
        self.t_start_manoeuvre_circle_left = 0.0
        self.check_circle_manoeuvre_left = 0
        self.heading_difference_circle_left = 0.0
        self.t_end_manoeuvre_circle_left = time.time()

        #zigzag 10
        self.t_end_manoeuvre_zigzag_10 = time.time()
        self.manoeuvre_zigzag_10_phase = 0

        # zigzag 20
        self.t_end_manoeuvre_zigzag_20 = time.time()
        self.manoeuvre_zigzag_20_phase = 0

        #astern

        self.t_start_manoeuvre_circle_right = 0
        self.t_start_manoeuvre_circle_left = 0
        self.t_start_manoeuvre_zigzag_10 = 0
        self.t_start_manoeuvre_zigzag_20 = 0
        self.t_start_manoeuvre_astern = 0
Ejemplo n.º 6
0
    def __init__(self, settings):

        self.logging = False
        if self.logging == True:
            logger.worker_configurer(settings["LOGGER"]['log_q'])
            self.log = logging.getLogger("NavPath")
            self.log.info(f'NavPath: Initialized NavPath and sending to 7775')
        # cap_comm.write("Paths", "1,3,4 56")

        self.num_time_samples = int(settings['SHIP_MAT']["ships_mat_samples"])
        # self.SendEX = Sender(settings["IP_ADDRESSES"]['ip_send_atlantis'], settings["UDP_PORTS"]['port_send_atlantis'])
        self.nmea_send = NMEAStrings()
        filename = os.path.join(os.path.dirname(__file__),
                                (settings["NAV_PATH"]['path_seed']))
        nav_map = genfromtxt(filename, delimiter=',')
        self.pts = nav_map[:, :4]
        #self.desired_resolution = 0.05 with self.distance2wpt = 3 works nice on PID
        self.desired_resolution = 0.01
        self.distance2wpt = 20
        self.static_path = settings["NAV_PATH"]['force_static_path']
        # self.distance2wpt = 0.0001
        self.all_waypoints_alpha, actual_resolution_row, actual_resolution_col = self.auto_thicken_paths(
            self.pts, self.desired_resolution)  # self.thicken_paths(density)
        self.row_distance_m = actual_resolution_row * 1000  #Resolution of points in perpendicular to boat
        self.col_distance_gl = actual_resolution_col  #low presision km to global equivelance
        self.response_time = 0.3  #This is how long the path generator should take. It traids off distance for speed
        self.lookback = 0
        self.iterpolation_space = 11  # 5 #This is best if its an odd number (It will choose to cross beween two boats in the middle)
        self.RIS = 40  # Row interpolation space

        # Initiate Local Logger
        if self.logging == True:
            logger.worker_configurer(
                settings['LOGGER']
                ['log_q'])  # configure local logger with the correct settings
            self.log = logging.getLogger(name="Autopilot")
        #Things to change based on density

        self.path_decimation = settings["NAV_PATH"]['path_decimation']
        self.safty_distance = int(actual_resolution_row /
                                  nt.geo_to_meters(20, 20))  # 500 pts
        self.mass = settings["NAV_PATH"]['ships_mass']
        if self.logging == True:
            self.log.info(f'NavPath = safety distance {self.safty_distance}')

        self.starting_value = 0

        self.length = self.ending_value = self.all_waypoints_alpha.shape[0]
        self.total_path_length = self.all_waypoints_alpha.shape[0]
        self.half_width_alpha = int(self.all_waypoints_alpha.shape[1] / 2)

        #For changing the path length
        self.path_resizing_parameter = int(0.001 * self.length)  #50

        self.center_track = int(self.half_width_alpha / 2)
        # self.total_path_length = self.ending_value
        self.create_waypoint_variables(self.starting_value,
                                       self.total_path_length)
        self.search_path = np.arange(0, self.half_width_alpha)
        self.my_path = self.center_track
        self.trigger = True  #Center Path biase trigger
        self.old_my_path = self.my_path
        self.same_path_trigger_tick = nt.get_time()
        self.path4biase = 0

        self.tree = self.create_search_trees(self.all_waypoints_alpha)
        if self.logging == True:
            self.log.info("Created Tree")
        self.number_of_loops = 0
        self.box_lats_stacked = [[]]
        self.box_lngs_stacked = [[]]
        self.momentum = False

        #Number of points in a ship. Initialise variable

        # self.avg_distans_points = nt.distance_spherical()
        self.longest_ship = 0
        self.mmsi_keep = 0  #This is a place to  keep the ships that are in the track