Пример #1
0
class InteropClientConverter:
    def __init__(self, msl_alt, url, username, password):
        self.msl_alt = msl_alt
        self.url = url
        self.username = username
        self.password = password

        self.client = Client(url, username, password)

    def post_telemetry(self, location, heading):
        """
        Post the drone's telemetry information

        :param location: The location to post
        :type location: Location
        :param heading: The UAV's heading
        :type heading: Float
        """
        telem_upload_data = Telemetry(location.get_lat(), location.get_lon(),
                                      location.get_alt() + self.msl_alt,
                                      heading)

        self.client.post_telemetry(telem_upload_data)

    def get_obstacles(self):
        """
        Return the obstacles.

        Returned in the format: [StationaryObstacle], [MovingObstacle]
        """
        stationary_obstacles, moving_obstacles = self.client.get_obstacles()

        return stationary_obstacles, moving_obstacles

    def get_active_mission(self):
        """
        Get the active mission and return it. If no missions are active, return
        None

        Returned in the format: Mission
        """
        missions = self.client.get_missions()

        for mission in missions:
            if mission.active:
                return mission

        return None

    def get_client(self):
        """
        Return's the client
        """
        return self.client
class InteropClientConverter(object):
    def __init__(self):
        self.client = Client(GCSSettings.INTEROP_URL,
                             GCSSettings.INTEROP_USERNAME,
                             GCSSettings.INTEROP_PASSWORD)

    def post_telemetry(self, location, heading):
        """
        Post the drone's telemetry information

        :param location: The location to post
        :type location: Location
        :param heading: The UAV's heading
        :type heading: Float
        """
        telem_upload_data = Telemetry(location.get_lat(), location.get_lon(),
                                      location.get_alt() + GCSSettings.MSL_ALT,
                                      heading)

        self.client.post_telemetry(telem_upload_data)

    def get_obstacles(self):
        """
        Return the obstacles.

        Returned in the format: [StationaryObstacle], [MovingObstacle]
        """
        stationary_obstacles, moving_obstacles = self.client.get_obstacles()

        return stationary_obstacles, moving_obstacles

    def get_active_mission(self):
        """
        Get the active mission and return it. If no missions are active, return
        None

        :return: Active Mission
        :return type: Mission / None
        """
        missions = self.client.get_missions()

        for mission in missions:
            if mission.active:
                return mission

        return None

    def post_manual_standard_target(self, target, image_file_path):
        """
        POST a standard ODLC object to the interoperability server.

        :param target: The ODLC target object
        :type target: JSON, with the form:
        {
            "latitude" : float,
            "longitude" : float,
            "orientation" : string,
            "shape" : string,
            "background_color" : string,
            "alphanumeric" : string,
            "alphanumeric_color" : string,
        }

        :param image_file_path: The ODLC target image file name
        :type image_file_path: String

        :return: ID of the posted target
        """
        odlc_target = Odlc(
            type="standard",
            autonomous=False,
            latitude=target["latitude"],
            longitude=target["longitude"],
            orientation=target["orientation"],
            shape=target["shape"],
            background_color=target["background_color"],
            alphanumeric=target["alphanumeric"],
            alphanumeric_color=target["alphanumeric_color"],
            description='Flint Hill School -- ODLC Standard Target Submission')

        returned_odlc = self.client.post_odlc(odlc_target)

        with open(image_file_path) as img_file:
            self.client.post_odlc_image(returned_odlc.id, img_file.read())

    def post_manual_emergent_target(self, target, image_file_path):
        """
        POST an emergent ODLC object to the interoperability server.

        :param target: The ODLC target object
        :type target: JSON, with the form:
        {
            "latitude" : float,
            "longitude" : float,
            "emergent_description" : String
        }

        :param image_file_path: The ODLC target image file name
        :type image_file_path: String

        :return: ID of the posted target
        """
        odlc_target = Odlc(
            type="emergent",
            autonomous=False,
            latitude=target["latitude"],
            longitude=target["longitude"],
            description='Flint Hill School -- ODLC Emergent Target Submission: '
            + str(target["emergent_description"]))

        returned_odlc = self.client.post_odlc(odlc_target)

        with open(image_file_path) as img_file:
            self.client.post_odlc_image(returned_odlc.id, img_file.read())

    def post_autonomous_target(self, target_info):
        """
        POST a standard ODLC object to the interoperability server.

        :param target: The ODLC target object
        :type target: JSON, with the form:
        {
            "latitude" : float,
            "longitude" : float,
            "orientation" : string,
            "shape" : string,
            "background_color" : string,
            "alphanumeric" : string,
            "alphanumeric_color" : string,
        }

        :param image_file_path: The ODLC target image file name
        :type image_file_path: String

        :return: ID of the posted target
        """

        image_file_path = target_info["target"][0]["current_crop_path"]
        odlc_target = Odlc(
            type="standard",
            autonomous=True,
            latitude=target_info["target"][0]["latitude"],
            longitude=target_info["target"][0]["longitude"],
            orientation=target_info["target"][0]["target_orientation"],
            shape=target_info["target"][0]["target_shape_type"],
            background_color=target_info["target"][0]["target_shape_color"],
            alphanumeric=target_info["target"][0]["target_letter"],
            alphanumeric_color=target_info["target"][0]["target_letter_color"],
            description="Flint Hill School -- ODLC Standard Target Submission")

        returned_odlc = self.client.post_odlc(odlc_target)

        with open(image_file_path) as img_file:
            self.client.post_odlc_image(returned_odlc.id, img_file.read())
Пример #3
0
async_missions = async_client.get_missions().result()

# # Check one mission returned.
# self.assertEqual(1, len(missions))
# self.assertEqual(1, len(async_missions))
# # Check a few fields.
# self.assertTrue(missions[0].active)
# self.assertTrue(async_missions[0].active)
# self.assertEqual(1, missions[0].id)
# self.assertEqual(1, async_missions[0].id)
# self.assertEqual(38.14792, missions[0].home_pos.latitude)
# self.assertEqual(38.14792, async_missions[0].home_pos.latitude)

admin_client.get('/api/clear_cache')
"""Test getting obstacles."""
stationary, moving = client.get_obstacles()
async_future = async_client.get_obstacles()
async_stationary, async_moving = async_future.result()

# # No exceptions is a good sign, let's see if the data matches the fixture.
# self.assertEqual(2, len(stationary))
# self.assertEqual(2, len(async_stationary))
# self.assertEqual(1, len(moving))
# self.assertEqual(1, len(async_moving))

# # Lat, lon, and altitude of the moving obstacles change, so we don't
# # check those.
# self.assertEqual(50, moving[0].sphere_radius)
# self.assertEqual(50, async_moving[0].sphere_radius)

# radii = [o.cylinder_radius for o in stationary]