Package: imperix
Imperix Node SDK - PythonOverviewImperixis a new fleet controlphilosophy, not just aground control program.Imperixconnects an entire fleet to the internet using secured and encrypted communication protocols, and provides a command center interface to all units on the fleet.TheImperix Node SDKis a set of open-sourceSoftware Developer Kitsin common programming languages allowing users to connect and interface customautopilotsystems with theImperix Cloud.The core functionality of theSDKincludes:Authenticating node with theImperix CloudSynchronizing mission state with the cloudStreaming manual control commands from the cloudStreaming telemetry, video, and data to the cloudInstallationAll dependencies for theImperix Node SDKPython implementation are provided in therequirements.txtfile. To install the dependencies, run the following command:pip3install-rrequirements.txtSetupThe SDK requires anode configurationfilenode.cfgto be placed in the program's root directory. Thenode configurationrequires the following parameters:Unique node identifier string provided upon node registrationNode authorization access key provided upon node registrationImperix Commander API URL (standard)Streamer/Stream Controller IP address/URL available in fleet managerThenode.cfgfile may be downloaded from the Imperix Commander node configuration page.UsageTheImperix Node SDKis designed to authenticate the node and initialize communications in its own thread. Review detailed SDK documentation available on:https://docs.imperix.ai.To use the SDK functions, import the SDK into your Python workspace/project using:importasynciofromimperiximportNodeLinkAsync/Await OperationsThe NodeLink handlers and communication threads use theasynciopackage'sasync/awaitcalls for concurrent operations. In order to set this up correctly, an event loop must be created and handled.See the example below for a main file definition:# Developed by Aptus Engineering, Inc. <https://aptus.aero># See LICENSE.md file in project root directoryimportasynciofromimperiximportNodeLink# Set up callback functions# Called when mission is updatedasyncdefmissionUpdateCallback(mission):print(mission)# Called with manual control command is receivedasyncdefmanualControlCallback(control):print(control)# Instantiate node link with callbacksnode=NodeLink(missionUpdateCallback=missionUpdateCallback,manualControlCallback=manualControlCallback)asyncdefmain():# Connect and authenticateawaitnode.connect()# Main loop...whileTrue:awaitasyncio.sleep(1)print("hello")# Start event loopeventLoop=asyncio.get_event_loop()try:asyncio.ensure_future(main())# Main threadeventLoop.run_forever()exceptKeyboardInterrupt:passfinally:eventLoop.close()asyncio.get_event_loop().run_until_complete(NodeLinkThread(node))asyncio.get_event_loop().run_forever()Initialization and Recieve CommandsInitialize a communication stream with theImperix Cloudusing the following command:node=NodeLink(missionUpdateCallback=handleMissionUpdate,manualControlCallback=handleManualControl)Where:handleMissionUpdateis a callback/lambda function which accepts the updated mission as a dictionary.handleManualControlis a callback/lambda function which accepts manual control command as a dictionary.To connect to theImperix Cloud, use the following command:await node.connect(config='node.cfg')Whereconfigis the path to thenode configurationfile.Sending Mission UpdatesIn order to update mission parameters, call the function:awaitnode.updateMission(activeWaypoint=wptIdx,missionStatus=status)Where:wptIdxis a dict key to the waypoint index the node is currently moving to/on.statusis a string defining the current mission status. It can be one of:Standbyif the mission is loaded but not activeActiveif the node is performing the loaded mission.Completeif the node successfully finished the missionFailed:[ERROR]if the node failed the mission.[ERROR]must be replaced with the reason for mission failureStreaming DataThree kinds of data streams are available to send to theImperix Cloud. Users can send one of:Telemetry- live data representing critical node status, such as location, velocities, attitude, etc.Video/Image- live or pre-captured video/image feeds for live view on theImperix Commanderor for future analytics usingImperix Intelligence.Data- any JSON-serializable data strings, such as sensor readings, messages etc.In order to stream telemetry, construct a dictionary with keys indicating the following variables:ATT_ROLL (degrees)ATT_PITCH (degrees)ATT_HEADING (degrees)LOC_LATITUDE (degrees)LOC_LONGITUDE (degrees)LOC_ALTITUDE (meters)VEL_GROUNDSPEED (meters per second)VEL_AIRSPEED (meters per second)VEL_VERTICAL_SPEED (meters per second)VEL_ROLL_RATE (degrees per second)VEL_PITCH_RATE (degrees per second)VEL_YAW_RATE (degrees per second)STS_BATTERY (percentage 0-100)STS_SIGNAL (percentage 0-100)And call the function:awaitnode.transmitTelemetry(telemetry)Wheretelemetryis the dict with the above variables.In order to stream image, either provide the image as a 1 or 3 channel numpy array to the function:awaitnode.transmitImage(image,timeStamp=timestamp,feed=feed)Where:imageis the numpy image,timestampis adatetimeobject, orNoneto use current timestamp (live feed), andfeedis a string identifying the name of the video feed. Default isPRIMARY.A pre-compressed JPEG image binary (avaiable using OpenCV, or Pillow) can also be streamed by calling the function:awaitnode.transmitImageBinary(image,timeStamp=timestamp,feed=feed)Whereimageis the pre-compressed JPEG image binary as abytesobject.To stream an encoded MPEG(-4) video from a live camera, streaming can be started using the call:awaitnode.streamVideoFromSource(feed,source)Wheresourceis a string representing the camera source(eg. /dev/video0).Videos can also be streamed from files by replacing thesourceargument with the file name, and by passing theisFileflag to the call:awaitnode.streamVideoFromSource(feed,source,isFile=True)Finally, to stream data to theImperix Cloud, the following function may be called:awaitnode.transmitData(data)Wheredatais a dictionary with JSON-serializable keys-value pairs.Streaming Latency FeedbackA mechanism is built to allow in optimizing video/image frame-rate and latency. Every second, an image/video feedback packet is sent back to the node, whose data can be used to adjust the stream quality accordingly. The following variables can be used to access framerate and latency.node.imageFrameRatenode.imageLatencyEnding SessionIn order to close out of a session - to be used when disconnecting the node, performing updates, or shutting down the node, the following function may be called:awaitnode.disconnect()Shutting down the node, or exiting the program also automatically disconnects the node from theImperix Cloud.