@@ -1177,9 +1177,12 @@ def listener(self, name, m):
11771177 self .notify_attribute_listeners ('armed' , self .armed , cache = True )
11781178 self ._autopilot_type = m .autopilot
11791179 self ._vehicle_type = m .type
1180- if self ._is_mode_available (m .custom_mode ) == False :
1180+ if self ._is_mode_available (m .custom_mode , m . base_mode ) == False :
11811181 raise APIException ("mode %s not available on mavlink definition" % m .custom_mode )
1182- self ._flightmode = self ._mode_mapping_bynumber [m .custom_mode ]
1182+ if self ._autopilot_type == mavutil .mavlink .MAV_AUTOPILOT_PX4 :
1183+ self ._flightmode = mavutil .interpret_px4_mode (m .base_mode , m .custom_mode )
1184+ else :
1185+ self ._flightmode = self ._mode_mapping_bynumber [m .custom_mode ]
11831186 self .notify_attribute_listeners ('mode' , self .mode , cache = True )
11841187 self ._system_status = m .system_status
11851188 self .notify_attribute_listeners ('system_status' , self .system_status , cache = True )
@@ -1525,9 +1528,12 @@ def _mode_mapping(self):
15251528 def _mode_mapping_bynumber (self ):
15261529 return mavutil .mode_mapping_bynumber (self ._vehicle_type )
15271530
1528- def _is_mode_available (self , mode_code ):
1529- try :
1530- return mode_code in self ._mode_mapping_bynumber
1531+ def _is_mode_available (self , custommode_code , basemode_code = 0 ):
1532+ try :
1533+ if self ._autopilot_type == mavutil .mavlink .MAV_AUTOPILOT_PX4 :
1534+ mode = mavutil .interpret_px4_mode (basemode_code , custommode_code )
1535+ return mode in self ._mode_mapping
1536+ return custommode_code in self ._mode_mapping_bynumber
15311537 except :
15321538 return False
15331539
@@ -1546,7 +1552,10 @@ def mode(self):
15461552
15471553 @mode .setter
15481554 def mode (self , v ):
1549- self ._master .set_mode (self ._mode_mapping [v .name ])
1555+ if self ._autopilot_type == mavutil .mavlink .MAV_AUTOPILOT_PX4 :
1556+ self ._master .set_mode (v .name )
1557+ else :
1558+ self ._master .set_mode (self ._mode_mapping [v .name ])
15501559
15511560 @property
15521561 def location (self ):
0 commit comments