Exemple #1
0
    def setMode(self, request, context):
        """Sets the mode of the drone which is represented as a string in the request"""

        self.vehicle.mode = VehicleMode(str(request.mode))
        self.vehicle.wait_ready('mode')

        return droneconnect_pb2.Null()
Exemple #2
0
def getPosition(stub):
    response = stub.getPosition(droneconnect_pb2.Null())
    print("lat: " + str(response.lat))
    print("long: " + str(response.lon))
    print("GPS altitude: " + str(response.gpsAltitude))
    print("Altitude relative to HOME: " + str(response.relativeAltitude))

    return
Exemple #3
0
    def setPath(self, request, context):
        """Uploads a series of positions to the drone in order to create a mission."""

        cmds = self.vehicle.commands
        coordFrame, alt = None, None

        # The idea behind stripping off the first position is to determine what reference frame to
        # to use.  Future proto changes will removed the coordinate frame boolean flag from the
        # request making the code unnecessary.  For now, this is the way it is.
        firstPosition = nth(request, 0)
        lat = firstPosition.lat
        lon = firstPosition.lon

        useRelativeAltitude = firstPosition.useRelativeAltitude

        if useRelativeAltitude:
            alt = firstPosition.relativeAltitude
            coordFrame = mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT
        else:
            alt = firstPosition.gpsAltitude
            coordFrame = mavutil.mavlink.MAV_FRAME_GLOBAL

        print(('First position at ({0},{1}) -> {2}'.format(lat, lon, alt)))

        # Make sure the drone is not in AUTO mode.
        self.vehicle.mode = VehicleMode("LOITER")
        self.clear_mission(cmds, coordFrame)

        # Add first position
        cmds.add(
            Command(0, 0, 0, coordFrame, mavutil.mavlink.MAV_CMD_NAV_WAYPOINT,
                    0, 0, 0, 0, 0, 0, lat, lon, alt))

        # Add the remaining positions
        for position in request:
            lat = position.lat
            lon = position.lon
            if useRelativeAltitude:
                alt = position.relativeAltitude
            else:
                alt = position.gpsAltitude
            print(('Point at ({0},{1}) -> {2}'.format(lat, lon, alt)))
            cmds.add(
                Command(0, 0, 0, coordFrame,
                        mavutil.mavlink.MAV_CMD_NAV_WAYPOINT, 0, 0, 0, 0, 0, 0,
                        lat, lon, alt))

        print("Uploading new commands to drone")
        cmds.upload()

        print("Starting mission")
        # Reset mission set to first (0) waypoint
        self.vehicle.commands.next = 0
        self.vehicle.mode = VehicleMode("AUTO")

        self.print_mission()

        return droneconnect_pb2.Null()
Exemple #4
0
def getSafety(stub):
    response = stub.getSafety(droneconnect_pb2.Null())
    safety = response.safety
    if safety:
        print("Safety is on.")
    elif safety == False:
        print("Safety is off!")

    return
Exemple #5
0
def droneReboot(stub):
    stub.reboot(droneconnect_pb2.Null())

    return
Exemple #6
0
def isArmed(stub):
    response = stub.isArmed(droneconnect_pb2.Null())
    print("Armed: " + str(response.arm))

    return
Exemple #7
0
def hasMode(stub):
    response = stub.hasMode(droneconnect_pb2.Null())
    print("Mode: " + response.mode)

    return
Exemple #8
0
    def setSafety(self, request, context):
        """Sets the safety switch on the drone, TRUE indicates safety is on."""
        self.vehicle.safety = request.safety

        return droneconnect_pb2.Null()
Exemple #9
0
    def setArmed(self, request, context):
        """Sets the armed state of the drone, TRUE indicates armed."""

        self.vehicle.armed = request.arm

        return droneconnect_pb2.Null()