Skip to main content

Telemetry helper for Cosmos API.

Project description

COSMOS API client

This is a simple client package to help you connect your drone to COSMOS API by:

  • Generating End-Points.
  • Generating and processing Post-Request to the End-point.
  • Parsing Operation content.

For a complete API description, please refer to COSMOS-API.

How to use

After getting the token from COSMOS: api_token_example, you can connect and update the telemetry with:

import cosmos_api

api_token = "api_token_example"
telemetry_updater = cosmos_api.Telemetry(api_token)
vehicle_state = {"activity": "idle", --- ,"battery": "90%"}
response = telemetry_updater.send_telemetry(vehicle_state)

How to build your vehicle_state

vehicle_state is a python dict variable which include the essential telemetry from the drone. This variable will be passed to the server as a json dump.

A basic template can be:

vehicle_state = {
        "activity": "idle",
        "stamp": 1602,
        "gps_0": {
            "fix": 3,
            "numsat": 10},
        "mode": "STABILIZE",
        "velocity": [0.0, -0.01, 0.0],
        "battery": {
            "level": 100,
            "current": 0.0,
            "voltage": 12.587},
        "state": "STANDBY",
        "location": {
            "global_frame": {
                "lat": 35.9341147,
                "lon": 139.5689006,
                "alt": 0}},
        "ground_speed": 0.0,
        "attitude": {
            "pitch": 0.0004752922395709902,
            "roll": 0.0007311428198590875,
            "yaw": -3.1402206420898438},
        "armed": False,
        "order_feedback": {
            "message": "",
            "type": ""},
        "heading": 180}

Operation

Cosmos provide operation information to the drone via /api/drone/myoperation endpoint. You can get all the information with:

operation = self.telemetry_updater.get_operation()
operation.display()

# Extract Waypoint with slug:
wp = operation.get_wp("A")
wp.display()
lat, lon, alt = wp.coordinates()

API description

constructor

  • Description
Send the telemetry to COSMOS server, .

Parameters
----------
api_token : str
    A string of the shared api token obtained from the server.

Returns
-------
cosmos_api.Telemetry Object
    A helper to send drone telemetry to cosmos server.
  • Use with:
telemetry_updater = cosmos_api.Telemetry(api_token)

send_telemetry

  • Description
Post the telemetry to COSMOS server, to the correct EndPoint with a functional header generated with the shared token.

Parameters
----------
vehicle_state : dict
    vehicle_state a dictionary including drone telemetry field.

Returns
-------
requests.Response Object
    The response to the post request. Please refer to requests documentation and bellow for error codes.
  • Use with:
response = telemetry_updater.send_telemetry(vehicle_state)
  • Server Code:
OK = 200: Telemetry posted correctly.
WRONGTELEMETRY = 400: Wrong or incomplete telemetry format.
WRONGTOKEN = 401: No drone registered under the used token.

get_operation

  • Description
Get the information of the active operation of the drone. This helper will report error code, and parse the operation content.

Parameters
----------
None

Returns
-------
cosmos_api.Operation Object
    The content of the operation parsed under Operation-Object attribute. (see Operation Object documentation)
  • Use with:
operation = telemetry_updater.get_operation()

class Operation

  • Description A class used to access operation content.

Attributes


  • status_code : int
    server status code error.
  • MOCA : int
    Minimun Obstacle Cleared Altitude of the operation in meter.
  • waypoints : list of WayPoint object
    List of all the waypoint formated under the WayPoint Object.
  • mission : json
    Specific mission content. (TODO)

Methods


  • display():
    Prints the operation content.

  • get_wp(waypoint_slug):
    Retrieve Waypoint by slug. Args: waypoint_slug (string) Return: waypoint (WayPoint object).

  • Use with:

operation = telemetry_updater.get_operation()
operation.display()
wp = operation.get_wp("A")
wp.display()
lat, lon, alt = wp.coordinates()

class WayPoint

  • Description A class used to acces Waypoint information.

Attributes


  • name : str
    Waypoint name on the MAP.
  • slug : str
    Short name of the Waypoint.\
  • latitude : double
    latitude of the waypoint in °.
  • longitude : double
    longitude of the waypoint in °.
  • altitude : float
    altitude of the waypoint in meter.

Methods


  • display()
    Prints the waypoint content.

  • coordinates()
    Return a tuple containing (latitude, longitude, altitude).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycosmosapi-0.0.3.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pycosmosapi-0.0.3-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file pycosmosapi-0.0.3.tar.gz.

File metadata

  • Download URL: pycosmosapi-0.0.3.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.6.12

File hashes

Hashes for pycosmosapi-0.0.3.tar.gz
Algorithm Hash digest
SHA256 7add6fa89e5e2092cc4d99eeff90a9c1b84549c71757038408169f032110b73f
MD5 4a9efefdfb68a27c4930dfb653705e78
BLAKE2b-256 7567df25393e329fc126c1bfd27e2dee8027e84a9ee382386e004a8fbbbcb73a

See more details on using hashes here.

File details

Details for the file pycosmosapi-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: pycosmosapi-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.6.12

File hashes

Hashes for pycosmosapi-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b601616bc0ad9f46c8340570b1a689d9ceb495821964d8ed107677fc79042884
MD5 716c2d55725df008e77fa3f3591b478d
BLAKE2b-256 1c32aebbd9f9ee4c9cd33297d4479fb6de843587e7a0c95824adf7aa99333d75

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page