def mode_callback(self, vehicle, name, mode): try: if mode.name != self.lastMode: logger.log("[callback]: Mode changed from %s -> %s" % (self.lastMode, mode.name)) self.lastMode = mode.name modeIndex = modes.getAPMModeIndexFromName( mode.name, self.vehicle) if modeIndex < 0: logger.log("couldn't find this mode index: %s" % self.mode.name) return else: self.currentModeIndex = modeIndex # If changing to Guided, we're probably in a smart shot so no # need to do anything here. If not, we need to run all this # cleanup stuff in case the stick and button remapping did not # properly clear from the last smart shot. if mode.name == 'GUIDED': return self.setNormalControl(modeIndex, mode) except Exception as e: logger.log('[shot]: mode callback error, %s' % e)
def mode_callback(self, vehicle, name, mode): try: if mode.name != self.lastMode: logger.log("[callback]: Mode changed from %s -> %s"%(self.lastMode, mode.name)) if mode.name == 'RTL': logger.log("[callback]: System entered RTL, we stay in there!") # self.enterShot(shots.APP_SHOT_RTL) elif self.currentShot != shots.APP_SHOT_NONE: # looks like somebody switched us out of guided! Exit our current shot if mode.name not in shots.SHOT_MODES: logger.log("[callback]: Detected that we are not in the correct apm mode for this shot. Exiting shot!") self.enterShot(shots.APP_SHOT_NONE) self.lastMode = mode.name # don't do the following for guided, since we're in a shot if self.lastMode == 'GUIDED' or mode.name == 'RTL': return modeIndex = modes.getAPMModeIndexFromName( self.lastMode, self.vehicle) if modeIndex < 0: logger.log("couldn't find this mode index: %s" % self.lastMode) return if self.currentShot == shots.APP_SHOT_NONE: self.buttonManager.setArtooShot( -1, modeIndex ) self.currentModeIndex = modeIndex except Exception as e: logger.log('[shot]: mode callback error, %s' % e)
def mode_callback(self, mode): if self.vehicle.mode.name != self.lastMode: logger.log("mode_callback: lastMode is %s, newMode is %s" % (self.lastMode, self.vehicle.mode.name)) if self.currentShot != shots.APP_SHOT_NONE: # looks like somebody switched us out of guided! Exit our current shot if self.lastMode == 'GUIDED': logger.log( "detected that we are not in guided, exiting shot!") self.enterShot(shots.APP_SHOT_NONE) # alternatively, RTL and LAND always exit shots elif self.vehicle.mode.name == 'RTL' or self.vehicle.mode.name == 'LAND': logger.log("RTL or land exited shot!") self.enterShot(shots.APP_SHOT_NONE) self.lastMode = self.vehicle.mode.name logger.log("vehicle changed to mode %s" % self.lastMode) # When user is in mission mode, set the camera to photo and open the camera_msgs tlog file if self.lastMode == 'AUTO': self.goproManager.sendGoProCommand( mavutil.mavlink.GOPRO_COMMAND_CAPTURE_MODE, (CAPTURE_MODE_PHOTO, 0, 0, 0)) self.cameraTLogFile = open('/log/camera_msgs.tlog', 'wb') self.isMission = True else: if (self.cameraTLogFile is not None): self.cameraTLogFile.close() self.cameraTLogFile = None self.isMission = False # don't do the following for guided, since we're in a shot if self.lastMode == 'GUIDED': return modeIndex = modes.getAPMModeIndexFromName(self.lastMode, self.vehicle) if modeIndex < 0: logger.log("couldn't find this mode index: %s" % self.lastMode) return if self.currentShot == shots.APP_SHOT_NONE: self.buttonManager.setArtooShot(-1, modeIndex) self.currentModeIndex = modeIndex
def mode_callback(self, mode): if self.vehicle.mode.name != self.lastMode: logger.log("mode_callback: lastMode is %s, newMode is %s"%(self.lastMode, self.vehicle.mode.name)) if self.currentShot != shots.APP_SHOT_NONE: # looks like somebody switched us out of guided! Exit our current shot if self.lastMode == 'GUIDED': logger.log("detected that we are not in guided, exiting shot!") self.enterShot(shots.APP_SHOT_NONE) # alternatively, RTL and LAND always exit shots elif self.vehicle.mode.name == 'RTL' or self.vehicle.mode.name == 'LAND': logger.log("RTL or land exited shot!") self.enterShot(shots.APP_SHOT_NONE) self.lastMode = self.vehicle.mode.name logger.log("vehicle changed to mode %s"%self.lastMode) # When user is in mission mode, set the camera to photo and open the camera_msgs tlog file if self.lastMode == 'AUTO': self.goproManager.sendGoProCommand(mavutil.mavlink.GOPRO_COMMAND_CAPTURE_MODE, (CAPTURE_MODE_PHOTO, 0 ,0 , 0)) self.cameraTLogFile = open('/log/camera_msgs.tlog', 'wb') self.isMission = True else: if (self.cameraTLogFile is not None): self.cameraTLogFile.close() self.cameraTLogFile = None self.isMission = False # don't do the following for guided, since we're in a shot if self.lastMode == 'GUIDED': return modeIndex = modes.getAPMModeIndexFromName( self.lastMode, self.vehicle) if modeIndex < 0: logger.log("couldn't find this mode index: %s"%self.lastMode) return if self.currentShot == shots.APP_SHOT_NONE: self.buttonManager.setArtooShot( -1, modeIndex ) self.currentModeIndex = modeIndex
def testLookupInvalidMode(self): """ Look up 'Invalid' """ i = modes.getAPMModeIndexFromName('Invalid', self.v) self.assertEqual(i, -1)
def testMalformedMode(self): """ Look up 'Mode(asta' """ i = modes.getAPMModeIndexFromName('Mode(asta', self.v) self.assertEqual(i, -1)
def testLookupModeParser(self): """ Look up 'Mode(10)' """ i = modes.getAPMModeIndexFromName('Mode(10)', self.v) self.assertEqual(i, 10)
def testLookupTestMe(self): """ Look up 'TEST_ME' """ i = modes.getAPMModeIndexFromName('TEST_ME', self.v) self.assertEqual(i, 317)
def testLookupAltHold(self): """ Look up 'ALT_HOLD' """ i = modes.getAPMModeIndexFromName('ALT_HOLD', self.v) self.assertEqual(i, 2)