Package: pycosmosapi
COSMOS API clientThis 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 toCOSMOS-API.How to useAfter getting the token from COSMOS:api_token_example, you can connect and update the telemetry with:importcosmos_apiapi_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 yourvehicle_statevehicle_stateis apython dictvariable 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}OperationCosmos provide operation information to the drone via/api/drone/myoperationendpoint.
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 descriptionconstructorDescriptionSendthetelemetrytoCOSMOSserver,.

Parameters
----------
api_token:strAstringofthesharedapitokenobtainedfromtheserver.

Returns
-------
cosmos_api.TelemetryObjectAhelpertosenddronetelemetrytocosmosserver.Use with:telemetry_updater=cosmos_api.Telemetry(api_token)send_telemetryDescriptionPostthetelemetrytoCOSMOSserver,tothecorrectEndPointwithafunctionalheadergeneratedwiththesharedtoken.

Parameters
----------
vehicle_state:dictvehicle_stateadictionaryincludingdronetelemetryfield.

Returns
-------
requests.ResponseObjectTheresponsetothepostrequest.Pleaserefertorequestsdocumentationandbellowforerrorcodes.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_operationDescriptionGettheinformationoftheactiveoperationofthedrone.Thishelperwillreporterrorcode,andparsetheoperationcontent.

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

Returns
-------
cosmos_api.OperationObjectThecontentoftheoperationparsedunderOperation-Objectattribute.(seeOperationObjectdocumentation)Use with:operation=telemetry_updater.get_operation()classOperationDescription
A class used to access operation content.Attributesstatus_code: intserver status code error.MOCA: intMinimun Obstacle Cleared Altitude of the operation in meter.waypoints: list of WayPoint objectList of all the waypoint formated under the WayPoint Object.mission: jsonSpecific mission content. (TODO)Methodsdisplay():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()classWayPointDescription
A class used to acces Waypoint information.Attributesname: strWaypoint name on the MAP.slug: strShort name of the Waypoint.\latitude: doublelatitude of the waypoint in °.longitude: doublelongitude of the waypoint in °.altitude: floataltitude of the waypoint in meter.Methodsdisplay()Prints the waypoint content.coordinates()Return a tuple containing (latitude, longitude, altitude).