Esempio n. 1
0
    def test_visible_above_horizon(self):
        """
        visible_above_horizon test
        """
        #equitorial orbit
        tle_line1 = "1 44235U 19029A   20178.66667824  .02170155  00000-0  40488-1 0  9998"
        tle_line2 = "2 44235  00.0000 163.9509 0005249 306.3756  83.0170 15.45172567 61683"
        #high inclination orbit
        tle2_line1 = "1 44235U 19029A   20178.66667824  .02170155  00000-0  40488-1 0  9998"
        tle2_line2 = "2 44235  70.0000 163.9509 0005249 306.3756  83.0170 15.45172567 61683"
        prop1 = orekit_utils.str_tle_propagator(tle_line1, tle_line2)
        prop2 = orekit_utils.str_tle_propagator(tle2_line1, tle2_line2)
        time = AbsoluteDate(2020, 6, 26, 1, 40, 00.000,
                            TimeScalesFactory.getUTC())

        #verified with graphing overviews
        self.assertFalse(orekit_utils.visible_above_horizon(
            prop1, prop2, time))
        self.assertTrue(
            orekit_utils.visible_above_horizon(prop1, prop2,
                                               time.shiftedBy(60. * 10.)))
        self.assertTrue(
            orekit_utils.visible_above_horizon(
                prop1, prop2, time.shiftedBy(60. * 10. + 45. * 60.)))
        time_period_visible = orekit_utils.visible_above_horizon(
            prop1, prop2, time, 60 * 30)[0]
        self.assertTrue(
            time.shiftedBy(60. * 10.).isBetween(time_period_visible[0],
                                                time_period_visible[1]))
Esempio n. 2
0
    def produce_links(self, save=False, new_shared_storage = None):
        """
        

        Args:
            save (bool, optional): Wether or not the packets should be saved. Defaults to True.
            new_shared_storage (dictionary, optional): A new dictionary containing satellite orbits,
            iot sensors, and groundstation to be used. Defaults to None.

        Returns:
            list: list of all of the inter satellite link packets
        """
        if new_shared_storage == None:
            shared_storage = self.shared_storage
        else:
            shared_storage = new_shared_storage
        satellite_links = self.satellite_links
        packet_links = []
        # for each element in the satellite links set make a packet
        for i in satellite_links:
            # find the names
            cubesat_a = i[i.find('/')+1:i.find('-')]
            cubesat_b = i[i.rfind('/')+1:]

            # create a orbit propagator for both satellites
            csat_a_prop = orekit_utils.analytical_propagator(shared_storage["swarm"][cubesat_a]["orbit"])
            csat_b_prop = orekit_utils.analytical_propagator(shared_storage["swarm"][cubesat_b]["orbit"])

            # create a list of times when the satellites can see each other
            start_time = orekit_utils.absolute_time_converter_utc_string(shared_storage["time"])            
            windows_array = orekit_utils.visible_above_horizon(csat_a_prop, csat_b_prop, start_time, self.duration)

            # create a list of times when the satellites can see and not see each other
            n_windows_array = self.process_time_window(windows_array)

            # create a list of objects when the satellite links can be shown for cesium
            show = self.create_show(n_windows_array)

            # create a list of times when the satellites can see and not see each other for cesium
            availability = self.create_availability(show)

            references = [i[:i.find("-to-")]+'#position', i[i.find("-to-") + 4:]+'#position']

            # Construct the packet with a generic link packet and data created above
            packet = deepcopy(self.shared_storage["generic"]["general_link"])
            packet["id"] = i
            packet["name"] = cubesat_a +" to " + cubesat_b
            packet["availability"] = availability
            packet["description"] = "<h1>Blah blah blah</h1>"   
            packet["polyline"]["show"] = show
            packet["polyline"]["positions"]["references"] = references
            packet_links.append(packet)
        # save as json if 
        if save:
            with open('data.json', 'w') as outfile:
                json.dump(packet_links, outfile)
        self.packets = packet_links
        return packet_links
Esempio n. 3
0
async def simulation_timepulse_propagate(message, nats_handler, shared_storage,
                                         logger):
    """
    Propagates the satellites current orbit and attitude

    Args:
        message (natsmessage): message
            message.data dictionary with structure as described in message_structure.json
            message.data["time"] is the time update
        nats_handler (natsHandler): distributes callbacks according to the message subject
        shared_storage: dictionary containing information on on the entire swarm, the time, and the particular satellites phonebook
    """
    # Distance that will prevent satellites from communicating
    max_range = shared_storage["range"]

    # Updating time
    shared_storage["time"] = message.data["time"]

    cubesat_id = nats_handler.sender_id

    #  Making a propagator for satellite running this service
    self_orbit_propagator = orekit_utils.analytical_propagator(
        shared_storage["swarm"][cubesat_id]["orbit"])

    # Each satellite's state will be upated and the phonebook will be updated
    for satellite in shared_storage["swarm"]:
        # Info about each satellite state is accessed to propagate orbit and attitude
        orbit_propagator = orekit_utils.analytical_propagator(
            shared_storage["swarm"][satellite]["orbit"])
        attitude = shared_storage["swarm"][satellite]["orbit"]["attitude"]
        attitude_param = dict()
        frame = shared_storage["swarm"][satellite]["orbit"]["frame"]

        # Info about satellite attitude is accessed
        if attitude in shared_storage["swarm"]:
            attitude_provider_type = orekit_utils.utils.MOVING_BODY_TRACKING
            attitude_param = shared_storage["swarm"][attitude]["orbit"]

        elif attitude in shared_storage["grstns"]:
            attitude_provider_type = orekit_utils.utils.GROUND_TRACKING
            attitude_param = shared_storage["grstns"][attitude]["location"]

        elif attitude in shared_storage["iots"]:
            attitude_provider_type = orekit_utils.utils.GROUND_TRACKING
            attitude_param = shared_storage["iots"][attitude]["location"]

        elif attitude == orekit_utils.utils.NADIR_TRACKING:
            attitude_provider_type = attitude
        else:
            raise Exception("attitude unknown")

        # storing/updating reference frame
        attitude_param["frame"] = frame

        # constructing a attitude provider from info gathered above
        attitude_provider = orekit_utils.attitude_provider_constructor(
            attitude_provider_type, attitude_param)

        # the orbit propagator and attitude provider are consolidated
        orbit_propagator.setAttitudeProvider(attitude_provider)

        time = orekit_utils.absolute_time_converter_utc_string(
            shared_storage["time"])

        # new satellite state containg attitude and orbit info
        new_state = orbit_propagator.propagate(time)

        # the shared storage is updated as necessary
        shared_storage["swarm"][satellite][
            "orbit"] = orekit_utils.get_keplerian_parameters(new_state)
        shared_storage["swarm"][satellite]["orbit"].update({"frame": frame})
        shared_storage["swarm"][satellite]["orbit"].update(
            {"attitude": attitude})
        shared_storage["swarm"][satellite][
            "last_update_time"] = shared_storage["time"]

        # Checking if the satellites target is in view and upating shared storage accordingly
        if attitude_provider_type == orekit_utils.utils.GROUND_TRACKING:
            shared_storage["swarm"][satellite][
                "target_in_view"] = orekit_utils.check_iot_in_range(
                    orbit_propagator, attitude_param["latitude"],
                    attitude_param["longitude"], attitude_param["altitude"],
                    time)
        elif attitude_provider_type == orekit_utils.utils.NADIR_TRACKING:
            shared_storage["swarm"][satellite]["target_in_view"] = True

        elif attitude_provider_type == orekit_utils.utils.MOVING_BODY_TRACKING:
            tracked_propagator = orekit_utils.analytical_propagator(
                attitude_param)
            shared_storage["swarm"][satellite][
                "target_in_view"] = orekit_utils.visible_above_horizon(
                    orbit_propagator, tracked_propagator, time)
        else:
            raise Exception("attitude_provider unknown")

        # Updating phonebook based on the location of the satellites
        if satellite != cubesat_id:
            cur_orbit_propagator = orekit_utils.analytical_propagator(
                shared_storage["swarm"][satellite]["orbit"])

            time = orekit_utils.absolute_time_converter_utc_string(
                shared_storage["time"])

            distance = orekit_utils.find_sat_distance(self_orbit_propagator,
                                                      cur_orbit_propagator,
                                                      time)

            if distance < max_range and orekit_utils.visible_above_horizon(
                    self_orbit_propagator, cur_orbit_propagator, time):
                shared_storage["sat_phonebook"][satellite] = True
            else:
                shared_storage["sat_phonebook"][satellite] = False

    # Message contaning data on the updated state of a satellite is sent for each sent
    for sat_id in shared_storage["swarm"]:
        msg = nats_handler.create_message(
            {"state": {
                sat_id: shared_storage["swarm"][sat_id]
            }}, MessageSchemas.STATE_MESSAGE)
        subject = "state"
        await nats_handler.send_message(subject, msg)

    # The satellites updated phonebook is sent
    sat_phonebook_message = nats_handler.create_message(
        shared_storage["sat_phonebook"], MessageSchemas.PHONEBOOK_MESSAGE)
    await nats_handler.send_message("internal.phonebook",
                                    sat_phonebook_message)

    # IOT PHONEBOOK UPDATER
    for iot_id in shared_storage["iots"]:
        latitude = shared_storage["iots"][iot_id]["location"]["latitude"]
        longitude = shared_storage["iots"][iot_id]["location"]["longitude"]
        altitude = shared_storage["iots"][iot_id]["location"]["altitude"]

        if orekit_utils.check_iot_in_range(
                self_orbit_propagator, latitude, longitude, altitude,
                orekit_utils.absolute_time_converter_utc_string(
                    shared_storage["time"])):
            shared_storage["iot_phonebook"][iot_id] = True
        else:
            shared_storage["iot_phonebook"][iot_id] = False
    # Sending updated phonebook
    iot_phonebook_message = nats_handler.create_message(
        shared_storage["iot_phonebook"], MessageSchemas.PHONEBOOK_MESSAGE)
    await nats_handler.send_message("internal.iot_phonebook",
                                    iot_phonebook_message)

    #Groundstation Phonebook Updater
    for ground_id in shared_storage["grstns"]:
        latitude = shared_storage["grstns"][ground_id]["location"]["latitude"]
        longitude = shared_storage["grstns"][ground_id]["location"][
            "longitude"]
        altitude = shared_storage["grstns"][ground_id]["location"]["altitude"]
        if orekit_utils.check_iot_in_range(
                self_orbit_propagator, latitude, longitude, altitude,
                orekit_utils.absolute_time_converter_utc_string(
                    shared_storage["time"])):
            shared_storage["grstn_phonebook"][ground_id] = True
        else:
            shared_storage["grstn_phonebook"][ground_id] = False
    # Sending updated phonebook
    grstn_phonebook_message = nats_handler.create_message(
        shared_storage["grstn_phonebook"], MessageSchemas.PHONEBOOK_MESSAGE)
    await nats_handler.send_message("internal.grnst_phonebook",
                                    grstn_phonebook_message)