idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
41,600 | def devop_read ( self , args , bustype ) : if len ( args ) < 5 : print ( "Usage: devop read <spi|i2c> name bus address regstart count" ) return name = args [ 0 ] bus = int ( args [ 1 ] , base = 0 ) address = int ( args [ 2 ] , base = 0 ) reg = int ( args [ 3 ] , base = 0 ) count = int ( args [ 4 ] , base = 0 ) self . master . mav . device_op_read_send ( self . target_system , self . target_component , self . request_id , bustype , bus , address , name , reg , count ) self . request_id += 1 | read from device |
41,601 | def devop_write ( self , args , bustype ) : usage = "Usage: devop write <spi|i2c> name bus address regstart count <bytes>" if len ( args ) < 5 : print ( usage ) return name = args [ 0 ] bus = int ( args [ 1 ] , base = 0 ) address = int ( args [ 2 ] , base = 0 ) reg = int ( args [ 3 ] , base = 0 ) count = int ( args [ 4 ] , base = 0 ) args = args [ 5 : ] if len ( args ) < count : print ( usage ) return bytes = [ 0 ] * 128 for i in range ( count ) : bytes [ i ] = int ( args [ i ] , base = 0 ) self . master . mav . device_op_write_send ( self . target_system , self . target_component , self . request_id , bustype , bus , address , name , reg , count , bytes ) self . request_id += 1 | write to a device |
41,602 | def get_absolute ( self , points ) : is_list = isinstance ( points , list ) points = ensure_numeric ( points , num . float ) if len ( points . shape ) == 1 : msg = 'Single point must have two elements' if not len ( points ) == 2 : raise ValueError ( msg ) msg = 'Input must be an N x 2 array or list of (x,y) values. ' msg += 'I got an %d x %d array' % points . shape if not points . shape [ 1 ] == 2 : raise ValueError ( msg ) if not self . is_absolute ( ) : points = copy . copy ( points ) points [ : , 0 ] += self . xllcorner points [ : , 1 ] += self . yllcorner if is_list : points = points . tolist ( ) return points | Given a set of points geo referenced to this instance return the points as absolute values . |
41,603 | def cmd_cameraview ( self , args ) : state = self if args and args [ 0 ] == 'set' : if len ( args ) < 3 : state . view_settings . show_all ( ) else : state . view_settings . set ( args [ 1 ] , args [ 2 ] ) state . update_col ( ) else : print ( 'usage: cameraview set' ) | camera view commands |
41,604 | def scale_rc ( self , servo , min , max , param ) : min_pwm = self . get_mav_param ( '%s_MIN' % param , 0 ) max_pwm = self . get_mav_param ( '%s_MAX' % param , 0 ) if min_pwm == 0 or max_pwm == 0 : return 0 if max_pwm == min_pwm : p = 0.0 else : p = ( servo - min_pwm ) / float ( max_pwm - min_pwm ) v = min + p * ( max - min ) if v < min : v = min if v > max : v = max return v | scale a PWM value |
41,605 | def raise_msg_to_str ( msg ) : if not is_string_like ( msg ) : msg = '\n' . join ( map ( str , msg ) ) return msg | msg is a return arg from a raise . Join with new lines |
41,606 | def _create_wx_app ( ) : wxapp = wx . GetApp ( ) if wxapp is None : wxapp = wx . App ( False ) wxapp . SetExitOnFrameDelete ( True ) _create_wx_app . theWxApp = wxapp | Creates a wx . App instance if it has not been created sofar . |
41,607 | def draw_if_interactive ( ) : DEBUG_MSG ( "draw_if_interactive()" , 1 , None ) if matplotlib . is_interactive ( ) : figManager = Gcf . get_active ( ) if figManager is not None : figManager . canvas . draw_idle ( ) | This should be overriden in a windowing environment if drawing should be done in interactive python mode |
41,608 | def new_gc ( self ) : DEBUG_MSG ( 'new_gc()' , 2 , self ) self . gc = GraphicsContextWx ( self . bitmap , self ) self . gc . select ( ) self . gc . unselect ( ) return self . gc | Return an instance of a GraphicsContextWx and sets the current gc copy |
41,609 | def get_wx_font ( self , s , prop ) : DEBUG_MSG ( "get_wx_font()" , 1 , self ) key = hash ( prop ) fontprop = prop fontname = fontprop . get_name ( ) font = self . fontd . get ( key ) if font is not None : return font wxFontname = self . fontnames . get ( fontname , wx . ROMAN ) wxFacename = '' size = self . points_to_pixels ( fontprop . get_size_in_points ( ) ) font = wx . Font ( int ( size + 0.5 ) , wxFontname , self . fontangles [ fontprop . get_style ( ) ] , self . fontweights [ fontprop . get_weight ( ) ] , False , wxFacename ) self . fontd [ key ] = font return font | Return a wx font . Cache instances in a font dictionary for efficiency |
41,610 | def select ( self ) : if sys . platform == 'win32' : self . dc . SelectObject ( self . bitmap ) self . IsSelected = True | Select the current bitmap into this wxDC instance |
41,611 | def unselect ( self ) : if sys . platform == 'win32' : self . dc . SelectObject ( wx . NullBitmap ) self . IsSelected = False | Select a Null bitmasp into this wxDC instance |
41,612 | def set_linewidth ( self , w ) : DEBUG_MSG ( "set_linewidth()" , 1 , self ) self . select ( ) if w > 0 and w < 1 : w = 1 GraphicsContextBase . set_linewidth ( self , w ) lw = int ( self . renderer . points_to_pixels ( self . _linewidth ) ) if lw == 0 : lw = 1 self . _pen . SetWidth ( lw ) self . gfx_ctx . SetPen ( self . _pen ) self . unselect ( ) | Set the line width . |
41,613 | def set_linestyle ( self , ls ) : DEBUG_MSG ( "set_linestyle()" , 1 , self ) self . select ( ) GraphicsContextBase . set_linestyle ( self , ls ) try : self . _style = GraphicsContextWx . _dashd_wx [ ls ] except KeyError : self . _style = wx . LONG_DASH if wx . Platform == '__WXMSW__' : self . set_linewidth ( 1 ) self . _pen . SetStyle ( self . _style ) self . gfx_ctx . SetPen ( self . _pen ) self . unselect ( ) | Set the line style to be one of |
41,614 | def get_wxcolour ( self , color ) : DEBUG_MSG ( "get_wx_color()" , 1 , self ) if len ( color ) == 3 : r , g , b = color r *= 255 g *= 255 b *= 255 return wx . Colour ( red = int ( r ) , green = int ( g ) , blue = int ( b ) ) else : r , g , b , a = color r *= 255 g *= 255 b *= 255 a *= 255 return wx . Colour ( red = int ( r ) , green = int ( g ) , blue = int ( b ) , alpha = int ( a ) ) | return a wx . Colour from RGB format |
41,615 | def Copy_to_Clipboard ( self , event = None ) : "copy bitmap of canvas to system clipboard" bmp_obj = wx . BitmapDataObject ( ) bmp_obj . SetBitmap ( self . bitmap ) if not wx . TheClipboard . IsOpened ( ) : open_success = wx . TheClipboard . Open ( ) if open_success : wx . TheClipboard . SetData ( bmp_obj ) wx . TheClipboard . Close ( ) wx . TheClipboard . Flush ( ) | copy bitmap of canvas to system clipboard |
41,616 | def draw_idle ( self ) : DEBUG_MSG ( "draw_idle()" , 1 , self ) self . _isDrawn = False if hasattr ( self , '_idletimer' ) : self . _idletimer . Restart ( IDLE_DELAY ) else : self . _idletimer = wx . FutureCall ( IDLE_DELAY , self . _onDrawIdle ) | Delay rendering until the GUI is idle . |
41,617 | def draw ( self , drawDC = None ) : DEBUG_MSG ( "draw()" , 1 , self ) self . renderer = RendererWx ( self . bitmap , self . figure . dpi ) self . figure . draw ( self . renderer ) self . _isDrawn = True self . gui_repaint ( drawDC = drawDC ) | Render the figure using RendererWx instance renderer or using a previously defined renderer if none is specified . |
41,618 | def start_event_loop ( self , timeout = 0 ) : if hasattr ( self , '_event_loop' ) : raise RuntimeError ( "Event loop already running" ) id = wx . NewId ( ) timer = wx . Timer ( self , id = id ) if timeout > 0 : timer . Start ( timeout * 1000 , oneShot = True ) bind ( self , wx . EVT_TIMER , self . stop_event_loop , id = id ) self . _event_loop = wx . EventLoop ( ) self . _event_loop . Run ( ) timer . Stop ( ) | Start an event loop . This is used to start a blocking event loop so that interactive functions such as ginput and waitforbuttonpress can wait for events . This should not be confused with the main GUI event loop which is always running and has nothing to do with this . |
41,619 | def stop_event_loop ( self , event = None ) : if hasattr ( self , '_event_loop' ) : if self . _event_loop . IsRunning ( ) : self . _event_loop . Exit ( ) del self . _event_loop | Stop an event loop . This is used to stop a blocking event loop so that interactive functions such as ginput and waitforbuttonpress can wait for events . |
41,620 | def _get_imagesave_wildcards ( self ) : 'return the wildcard string for the filesave dialog' default_filetype = self . get_default_filetype ( ) filetypes = self . get_supported_filetypes_grouped ( ) sorted_filetypes = filetypes . items ( ) sorted_filetypes . sort ( ) wildcards = [ ] extensions = [ ] filter_index = 0 for i , ( name , exts ) in enumerate ( sorted_filetypes ) : ext_list = ';' . join ( [ '*.%s' % ext for ext in exts ] ) extensions . append ( exts [ 0 ] ) wildcard = '%s (%s)|%s' % ( name , ext_list , ext_list ) if default_filetype in exts : filter_index = i wildcards . append ( wildcard ) wildcards = '|' . join ( wildcards ) return wildcards , extensions , filter_index | return the wildcard string for the filesave dialog |
41,621 | def gui_repaint ( self , drawDC = None ) : DEBUG_MSG ( "gui_repaint()" , 1 , self ) if self . IsShownOnScreen ( ) : if drawDC is None : drawDC = wx . ClientDC ( self ) drawDC . DrawBitmap ( self . bitmap , 0 , 0 ) else : pass | Performs update of the displayed image on the GUI canvas using the supplied device context . If drawDC is None a ClientDC will be used to redraw the image . |
41,622 | def _onPaint ( self , evt ) : DEBUG_MSG ( "_onPaint()" , 1 , self ) drawDC = wx . PaintDC ( self ) if not self . _isDrawn : self . draw ( drawDC = drawDC ) else : self . gui_repaint ( drawDC = drawDC ) evt . Skip ( ) | Called when wxPaintEvt is generated |
41,623 | def _onSize ( self , evt ) : DEBUG_MSG ( "_onSize()" , 2 , self ) self . _width , self . _height = self . GetClientSize ( ) self . bitmap = wx . EmptyBitmap ( self . _width , self . _height ) self . _isDrawn = False if self . _width <= 1 or self . _height <= 1 : return dpival = self . figure . dpi winch = self . _width / dpival hinch = self . _height / dpival self . figure . set_size_inches ( winch , hinch ) self . Refresh ( eraseBackground = False ) FigureCanvasBase . resize_event ( self ) | Called when wxEventSize is generated . |
41,624 | def _onIdle ( self , evt ) : 'a GUI idle event' evt . Skip ( ) FigureCanvasBase . idle_event ( self , guiEvent = evt ) | a GUI idle event |
41,625 | def _onKeyDown ( self , evt ) : key = self . _get_key ( evt ) evt . Skip ( ) FigureCanvasBase . key_press_event ( self , key , guiEvent = evt ) | Capture key press . |
41,626 | def _onKeyUp ( self , evt ) : key = self . _get_key ( evt ) evt . Skip ( ) FigureCanvasBase . key_release_event ( self , key , guiEvent = evt ) | Release key . |
41,627 | def _onLeftButtonUp ( self , evt ) : x = evt . GetX ( ) y = self . figure . bbox . height - evt . GetY ( ) evt . Skip ( ) if self . HasCapture ( ) : self . ReleaseMouse ( ) FigureCanvasBase . button_release_event ( self , x , y , 1 , guiEvent = evt ) | End measuring on an axis . |
41,628 | def _onMouseWheel ( self , evt ) : x = evt . GetX ( ) y = self . figure . bbox . height - evt . GetY ( ) delta = evt . GetWheelDelta ( ) rotation = evt . GetWheelRotation ( ) rate = evt . GetLinesPerAction ( ) step = rate * float ( rotation ) / delta evt . Skip ( ) if wx . Platform == '__WXMAC__' : if not hasattr ( self , '_skipwheelevent' ) : self . _skipwheelevent = True elif self . _skipwheelevent : self . _skipwheelevent = False return else : self . _skipwheelevent = True FigureCanvasBase . scroll_event ( self , x , y , step , guiEvent = evt ) | Translate mouse wheel events into matplotlib events |
41,629 | def _onLeave ( self , evt ) : evt . Skip ( ) FigureCanvasBase . leave_notify_event ( self , guiEvent = evt ) | Mouse has left the window . |
41,630 | def resize ( self , width , height ) : 'Set the canvas size in pixels' self . canvas . SetInitialSize ( wx . Size ( width , height ) ) self . window . GetSizer ( ) . Fit ( self . window ) | Set the canvas size in pixels |
41,631 | def _onMenuButton ( self , evt ) : x , y = self . GetPositionTuple ( ) w , h = self . GetSizeTuple ( ) self . PopupMenuXY ( self . _menu , x , y + h - 4 ) evt . Skip ( ) | Handle menu button pressed . |
41,632 | def _handleSelectAllAxes ( self , evt ) : if len ( self . _axisId ) == 0 : return for i in range ( len ( self . _axisId ) ) : self . _menu . Check ( self . _axisId [ i ] , True ) self . _toolbar . set_active ( self . getActiveAxes ( ) ) evt . Skip ( ) | Called when the select all axes menu item is selected . |
41,633 | def _handleInvertAxesSelected ( self , evt ) : if len ( self . _axisId ) == 0 : return for i in range ( len ( self . _axisId ) ) : if self . _menu . IsChecked ( self . _axisId [ i ] ) : self . _menu . Check ( self . _axisId [ i ] , False ) else : self . _menu . Check ( self . _axisId [ i ] , True ) self . _toolbar . set_active ( self . getActiveAxes ( ) ) evt . Skip ( ) | Called when the invert all menu item is selected |
41,634 | def _onMenuItemSelected ( self , evt ) : current = self . _menu . IsChecked ( evt . GetId ( ) ) if current : new = False else : new = True self . _menu . Check ( evt . GetId ( ) , new ) self . _toolbar . set_active ( self . getActiveAxes ( ) ) evt . Skip ( ) | Called whenever one of the specific axis menu items is selected |
41,635 | def getActiveAxes ( self ) : active = [ ] for i in range ( len ( self . _axisId ) ) : if self . _menu . IsChecked ( self . _axisId [ i ] ) : active . append ( i ) return active | Return a list of the selected axes . |
41,636 | def updateButtonText ( self , lst ) : axis_txt = '' for e in lst : axis_txt += '%d,' % ( e + 1 ) self . SetLabel ( "Axes: %s" % axis_txt [ : - 1 ] ) | Update the list of selected axes in the menu button |
41,637 | def _create_menu ( self ) : DEBUG_MSG ( "_create_menu()" , 1 , self ) self . _menu = MenuButtonWx ( self ) self . AddControl ( self . _menu ) self . AddSeparator ( ) | Creates the menu - implemented as a button which opens a pop - up menu since wxPython does not allow a menu as a control |
41,638 | def _create_controls ( self , can_kill ) : DEBUG_MSG ( "_create_controls()" , 1 , self ) self . SetToolBitmapSize ( wx . Size ( 16 , 16 ) ) self . AddSimpleTool ( _NTB_X_PAN_LEFT , _load_bitmap ( 'stock_left.xpm' ) , 'Left' , 'Scroll left' ) self . AddSimpleTool ( _NTB_X_PAN_RIGHT , _load_bitmap ( 'stock_right.xpm' ) , 'Right' , 'Scroll right' ) self . AddSimpleTool ( _NTB_X_ZOOMIN , _load_bitmap ( 'stock_zoom-in.xpm' ) , 'Zoom in' , 'Increase X axis magnification' ) self . AddSimpleTool ( _NTB_X_ZOOMOUT , _load_bitmap ( 'stock_zoom-out.xpm' ) , 'Zoom out' , 'Decrease X axis magnification' ) self . AddSeparator ( ) self . AddSimpleTool ( _NTB_Y_PAN_UP , _load_bitmap ( 'stock_up.xpm' ) , 'Up' , 'Scroll up' ) self . AddSimpleTool ( _NTB_Y_PAN_DOWN , _load_bitmap ( 'stock_down.xpm' ) , 'Down' , 'Scroll down' ) self . AddSimpleTool ( _NTB_Y_ZOOMIN , _load_bitmap ( 'stock_zoom-in.xpm' ) , 'Zoom in' , 'Increase Y axis magnification' ) self . AddSimpleTool ( _NTB_Y_ZOOMOUT , _load_bitmap ( 'stock_zoom-out.xpm' ) , 'Zoom out' , 'Decrease Y axis magnification' ) self . AddSeparator ( ) self . AddSimpleTool ( _NTB_SAVE , _load_bitmap ( 'stock_save_as.xpm' ) , 'Save' , 'Save plot contents as images' ) self . AddSeparator ( ) bind ( self , wx . EVT_TOOL , self . _onLeftScroll , id = _NTB_X_PAN_LEFT ) bind ( self , wx . EVT_TOOL , self . _onRightScroll , id = _NTB_X_PAN_RIGHT ) bind ( self , wx . EVT_TOOL , self . _onXZoomIn , id = _NTB_X_ZOOMIN ) bind ( self , wx . EVT_TOOL , self . _onXZoomOut , id = _NTB_X_ZOOMOUT ) bind ( self , wx . EVT_TOOL , self . _onUpScroll , id = _NTB_Y_PAN_UP ) bind ( self , wx . EVT_TOOL , self . _onDownScroll , id = _NTB_Y_PAN_DOWN ) bind ( self , wx . EVT_TOOL , self . _onYZoomIn , id = _NTB_Y_ZOOMIN ) bind ( self , wx . EVT_TOOL , self . _onYZoomOut , id = _NTB_Y_ZOOMOUT ) bind ( self , wx . EVT_TOOL , self . _onSave , id = _NTB_SAVE ) bind ( self , wx . EVT_TOOL_ENTER , self . _onEnterTool , id = self . GetId ( ) ) if can_kill : bind ( self , wx . EVT_TOOL , self . _onClose , id = _NTB_CLOSE ) bind ( self , wx . EVT_MOUSEWHEEL , self . _onMouseWheel ) | Creates the button controls and links them to event handlers |
41,639 | def set_active ( self , ind ) : DEBUG_MSG ( "set_active()" , 1 , self ) self . _ind = ind if ind != None : self . _active = [ self . _axes [ i ] for i in self . _ind ] else : self . _active = [ ] self . _menu . updateButtonText ( ind ) | ind is a list of index numbers for the axes which are to be made active |
41,640 | def getURIWithRedirect ( self , url ) : tries = 0 while tries < 5 : conn = httplib . HTTPConnection ( self . server ) conn . request ( "GET" , url ) r1 = conn . getresponse ( ) if r1 . status in [ 301 , 302 , 303 , 307 ] : location = r1 . getheader ( 'Location' ) if self . debug : print ( "redirect from %s to %s" % ( url , location ) ) url = location conn . close ( ) tries += 1 continue data = r1 . read ( ) conn . close ( ) if sys . version_info . major < 3 : return data else : encoding = r1 . headers . get_content_charset ( default ) return data . decode ( encoding ) return None | fetch a URL with redirect handling |
41,641 | def cmd_rc ( self , args ) : if len ( args ) != 2 : print ( "Usage: rc <channel|all> <pwmvalue>" ) return value = int ( args [ 1 ] ) if value > 65535 or value < - 1 : raise ValueError ( "PWM value must be a positive integer between 0 and 65535" ) if value == - 1 : value = 65535 channels = self . override if args [ 0 ] == 'all' : for i in range ( 16 ) : channels [ i ] = value else : channel = int ( args [ 0 ] ) if channel < 1 or channel > 16 : print ( "Channel must be between 1 and 8 or 'all'" ) return channels [ channel - 1 ] = value self . set_override ( channels ) | handle RC value override |
41,642 | def complete_variable ( text ) : if text == '' : return list ( rline_mpstate . status . msgs . keys ( ) ) if text . endswith ( ":2" ) : suffix = ":2" text = text [ : - 2 ] else : suffix = '' try : if mavutil . evaluate_expression ( text , rline_mpstate . status . msgs ) is not None : return [ text + suffix ] except Exception as ex : pass try : m1 = re . match ( "^(.*?)([A-Z0-9][A-Z0-9_]*)[.]([A-Za-z0-9_]*)$" , text ) except Exception as ex : return [ ] if m1 is not None : prefix = m1 . group ( 1 ) mtype = m1 . group ( 2 ) fname = m1 . group ( 3 ) if mtype in rline_mpstate . status . msgs : ret = [ ] for f in rline_mpstate . status . msgs [ mtype ] . get_fieldnames ( ) : if f . startswith ( fname ) : ret . append ( prefix + mtype + '.' + f + suffix ) return ret return [ ] try : m2 = re . match ( "^(.*?)([A-Z0-9][A-Z0-9_]*)$" , text ) except Exception as ex : return [ ] prefix = m2 . group ( 1 ) mtype = m2 . group ( 2 ) ret = [ ] for k in list ( rline_mpstate . status . msgs . keys ( ) ) : if k . startswith ( mtype ) : ret . append ( prefix + k + suffix ) return ret | complete a MAVLink variable or expression |
41,643 | def complete_rule ( rule , cmd ) : global rline_mpstate rule_components = rule . split ( ' ' ) if len ( cmd ) == 0 : return rule_expand ( rule_components [ 0 ] , "" ) for i in range ( len ( cmd ) - 1 ) : if not rule_match ( rule_components [ i ] , cmd [ i ] ) : return [ ] expanded = rule_expand ( rule_components [ len ( cmd ) - 1 ] , cmd [ - 1 ] ) return expanded | complete using one rule |
41,644 | def createPlotPanel ( self ) : self . figure = Figure ( ) self . axes = self . figure . add_subplot ( 111 ) self . canvas = FigureCanvas ( self , - 1 , self . figure ) self . canvas . SetSize ( wx . Size ( 300 , 300 ) ) self . axes . axis ( 'off' ) self . figure . subplots_adjust ( left = 0 , right = 1 , top = 1 , bottom = 0 ) self . sizer = wx . BoxSizer ( wx . VERTICAL ) self . sizer . Add ( self . canvas , 1 , wx . EXPAND , wx . ALL ) self . SetSizerAndFit ( self . sizer ) self . Fit ( ) | Creates the figure and axes for the plotting panel . |
41,645 | def rescaleX ( self ) : self . ratio = self . figure . get_size_inches ( ) [ 0 ] / float ( self . figure . get_size_inches ( ) [ 1 ] ) self . axes . set_xlim ( - self . ratio , self . ratio ) self . axes . set_ylim ( - 1 , 1 ) | Rescales the horizontal axes to make the lengthscales equal . |
41,646 | def calcFontScaling ( self ) : self . ypx = self . figure . get_size_inches ( ) [ 1 ] * self . figure . dpi self . xpx = self . figure . get_size_inches ( ) [ 0 ] * self . figure . dpi self . fontSize = self . vertSize * ( self . ypx / 2.0 ) self . leftPos = self . axes . get_xlim ( ) [ 0 ] self . rightPos = self . axes . get_xlim ( ) [ 1 ] | Calculates the current font size and left position for the current window . |
41,647 | def checkReszie ( self ) : if not self . resized : oldypx = self . ypx oldxpx = self . xpx self . ypx = self . figure . get_size_inches ( ) [ 1 ] * self . figure . dpi self . xpx = self . figure . get_size_inches ( ) [ 0 ] * self . figure . dpi if ( oldypx != self . ypx ) or ( oldxpx != self . xpx ) : self . resized = True else : self . resized = False | Checks if the window was resized . |
41,648 | def createHeadingPointer ( self ) : self . headingTri = patches . RegularPolygon ( ( 0.0 , 0.80 ) , 3 , 0.05 , color = 'k' , zorder = 4 ) self . axes . add_patch ( self . headingTri ) self . headingText = self . axes . text ( 0.0 , 0.675 , '0' , color = 'k' , size = self . fontSize , horizontalalignment = 'center' , verticalalignment = 'center' , zorder = 4 ) | Creates the pointer for the current heading . |
41,649 | def adjustHeadingPointer ( self ) : self . headingText . set_text ( str ( self . heading ) ) self . headingText . set_size ( self . fontSize ) | Adjust the value of the heading pointer . |
41,650 | def createNorthPointer ( self ) : self . headingNorthTri = patches . RegularPolygon ( ( 0.0 , 0.80 ) , 3 , 0.05 , color = 'k' , zorder = 4 ) self . axes . add_patch ( self . headingNorthTri ) self . headingNorthText = self . axes . text ( 0.0 , 0.675 , 'N' , color = 'k' , size = self . fontSize , horizontalalignment = 'center' , verticalalignment = 'center' , zorder = 4 ) | Creates the north pointer relative to current heading . |
41,651 | def adjustNorthPointer ( self ) : self . headingNorthText . set_size ( self . fontSize ) headingRotate = mpl . transforms . Affine2D ( ) . rotate_deg_around ( 0.0 , 0.0 , self . heading ) + self . axes . transData self . headingNorthText . set_transform ( headingRotate ) if ( self . heading > 90 ) and ( self . heading < 270 ) : headRot = self . heading - 180 else : headRot = self . heading self . headingNorthText . set_rotation ( headRot ) self . headingNorthTri . set_transform ( headingRotate ) if ( self . heading <= 10.0 ) or ( self . heading >= 350.0 ) : self . headingNorthText . set_text ( '' ) else : self . headingNorthText . set_text ( 'N' ) | Adjust the position and orientation of the north pointer . |
41,652 | def createRPYText ( self ) : self . rollText = self . axes . text ( self . leftPos + ( self . vertSize / 10.0 ) , - 0.97 + ( 2 * self . vertSize ) - ( self . vertSize / 10.0 ) , 'Roll: %.2f' % self . roll , color = 'w' , size = self . fontSize ) self . pitchText = self . axes . text ( self . leftPos + ( self . vertSize / 10.0 ) , - 0.97 + self . vertSize - ( 0.5 * self . vertSize / 10.0 ) , 'Pitch: %.2f' % self . pitch , color = 'w' , size = self . fontSize ) self . yawText = self . axes . text ( self . leftPos + ( self . vertSize / 10.0 ) , - 0.97 , 'Yaw: %.2f' % self . yaw , color = 'w' , size = self . fontSize ) self . rollText . set_path_effects ( [ PathEffects . withStroke ( linewidth = 1 , foreground = 'k' ) ] ) self . pitchText . set_path_effects ( [ PathEffects . withStroke ( linewidth = 1 , foreground = 'k' ) ] ) self . yawText . set_path_effects ( [ PathEffects . withStroke ( linewidth = 1 , foreground = 'k' ) ] ) | Creates the text for roll pitch and yaw . |
41,653 | def updateRPYLocations ( self ) : self . rollText . set_position ( ( self . leftPos + ( self . vertSize / 10.0 ) , - 0.97 + ( 2 * self . vertSize ) - ( self . vertSize / 10.0 ) ) ) self . pitchText . set_position ( ( self . leftPos + ( self . vertSize / 10.0 ) , - 0.97 + self . vertSize - ( 0.5 * self . vertSize / 10.0 ) ) ) self . yawText . set_position ( ( self . leftPos + ( self . vertSize / 10.0 ) , - 0.97 ) ) self . rollText . set_size ( self . fontSize ) self . pitchText . set_size ( self . fontSize ) self . yawText . set_size ( self . fontSize ) | Update the locations of roll pitch yaw text . |
41,654 | def updateRPYText ( self ) : 'Updates the displayed Roll, Pitch, Yaw Text' self . rollText . set_text ( 'Roll: %.2f' % self . roll ) self . pitchText . set_text ( 'Pitch: %.2f' % self . pitch ) self . yawText . set_text ( 'Yaw: %.2f' % self . yaw ) | Updates the displayed Roll Pitch Yaw Text |
41,655 | def createCenterPointMarker ( self ) : self . axes . add_patch ( patches . Rectangle ( ( - 0.75 , - self . thick ) , 0.5 , 2.0 * self . thick , facecolor = 'orange' , zorder = 3 ) ) self . axes . add_patch ( patches . Rectangle ( ( 0.25 , - self . thick ) , 0.5 , 2.0 * self . thick , facecolor = 'orange' , zorder = 3 ) ) self . axes . add_patch ( patches . Circle ( ( 0 , 0 ) , radius = self . thick , facecolor = 'orange' , edgecolor = 'none' , zorder = 3 ) ) | Creates the center pointer in the middle of the screen . |
41,656 | def createHorizonPolygons ( self ) : vertsTop = [ [ - 1 , 0 ] , [ - 1 , 1 ] , [ 1 , 1 ] , [ 1 , 0 ] , [ - 1 , 0 ] ] self . topPolygon = Polygon ( vertsTop , facecolor = 'dodgerblue' , edgecolor = 'none' ) self . axes . add_patch ( self . topPolygon ) vertsBot = [ [ - 1 , 0 ] , [ - 1 , - 1 ] , [ 1 , - 1 ] , [ 1 , 0 ] , [ - 1 , 0 ] ] self . botPolygon = Polygon ( vertsBot , facecolor = 'brown' , edgecolor = 'none' ) self . axes . add_patch ( self . botPolygon ) | Creates the two polygons to show the sky and ground . |
41,657 | def calcHorizonPoints ( self ) : ydiff = math . tan ( math . radians ( - self . roll ) ) * float ( self . ratio ) pitchdiff = self . dist10deg * ( self . pitch / 10.0 ) vertsTop = [ ( - self . ratio , ydiff - pitchdiff ) , ( - self . ratio , 1 ) , ( self . ratio , 1 ) , ( self . ratio , - ydiff - pitchdiff ) , ( - self . ratio , ydiff - pitchdiff ) ] self . topPolygon . set_xy ( vertsTop ) vertsBot = [ ( - self . ratio , ydiff - pitchdiff ) , ( - self . ratio , - 1 ) , ( self . ratio , - 1 ) , ( self . ratio , - ydiff - pitchdiff ) , ( - self . ratio , ydiff - pitchdiff ) ] self . botPolygon . set_xy ( vertsBot ) | Updates the verticies of the patches for the ground and sky . |
41,658 | def createPitchMarkers ( self ) : self . pitchPatches = [ ] for i in [ - 9 , - 8 , - 7 , - 6 , - 5 , - 4 , - 3 , - 2 , - 1 , 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] : width = self . calcPitchMarkerWidth ( i ) currPatch = patches . Rectangle ( ( - width / 2.0 , self . dist10deg * i - ( self . thick / 2.0 ) ) , width , self . thick , facecolor = 'w' , edgecolor = 'none' ) self . axes . add_patch ( currPatch ) self . pitchPatches . append ( currPatch ) self . vertSize = 0.09 self . pitchLabelsLeft = [ ] self . pitchLabelsRight = [ ] i = 0 for j in [ - 90 , - 60 , - 30 , 30 , 60 , 90 ] : self . pitchLabelsLeft . append ( self . axes . text ( - 0.55 , ( j / 10.0 ) * self . dist10deg , str ( j ) , color = 'w' , size = self . fontSize , horizontalalignment = 'center' , verticalalignment = 'center' ) ) self . pitchLabelsLeft [ i ] . set_path_effects ( [ PathEffects . withStroke ( linewidth = 1 , foreground = 'k' ) ] ) self . pitchLabelsRight . append ( self . axes . text ( 0.55 , ( j / 10.0 ) * self . dist10deg , str ( j ) , color = 'w' , size = self . fontSize , horizontalalignment = 'center' , verticalalignment = 'center' ) ) self . pitchLabelsRight [ i ] . set_path_effects ( [ PathEffects . withStroke ( linewidth = 1 , foreground = 'k' ) ] ) i += 1 | Creates the rectangle patches for the pitch indicators . |
41,659 | def adjustPitchmarkers ( self ) : pitchdiff = self . dist10deg * ( self . pitch / 10.0 ) rollRotate = mpl . transforms . Affine2D ( ) . rotate_deg_around ( 0.0 , - pitchdiff , self . roll ) + self . axes . transData j = 0 for i in [ - 9 , - 8 , - 7 , - 6 , - 5 , - 4 , - 3 , - 2 , - 1 , 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] : width = self . calcPitchMarkerWidth ( i ) self . pitchPatches [ j ] . set_xy ( ( - width / 2.0 , self . dist10deg * i - ( self . thick / 2.0 ) - pitchdiff ) ) self . pitchPatches [ j ] . set_transform ( rollRotate ) j += 1 i = 0 for j in [ - 9 , - 6 , - 3 , 3 , 6 , 9 ] : self . pitchLabelsLeft [ i ] . set_y ( j * self . dist10deg - pitchdiff ) self . pitchLabelsRight [ i ] . set_y ( j * self . dist10deg - pitchdiff ) self . pitchLabelsLeft [ i ] . set_size ( self . fontSize ) self . pitchLabelsRight [ i ] . set_size ( self . fontSize ) self . pitchLabelsLeft [ i ] . set_rotation ( self . roll ) self . pitchLabelsRight [ i ] . set_rotation ( self . roll ) self . pitchLabelsLeft [ i ] . set_transform ( rollRotate ) self . pitchLabelsRight [ i ] . set_transform ( rollRotate ) i += 1 | Adjusts the location and orientation of pitch markers . |
41,660 | def createAARText ( self ) : self . airspeedText = self . axes . text ( self . rightPos - ( self . vertSize / 10.0 ) , - 0.97 + ( 2 * self . vertSize ) - ( self . vertSize / 10.0 ) , 'AS: %.1f m/s' % self . airspeed , color = 'w' , size = self . fontSize , ha = 'right' ) self . altitudeText = self . axes . text ( self . rightPos - ( self . vertSize / 10.0 ) , - 0.97 + self . vertSize - ( 0.5 * self . vertSize / 10.0 ) , 'ALT: %.1f m ' % self . relAlt , color = 'w' , size = self . fontSize , ha = 'right' ) self . climbRateText = self . axes . text ( self . rightPos - ( self . vertSize / 10.0 ) , - 0.97 , 'CR: %.1f m/s' % self . climbRate , color = 'w' , size = self . fontSize , ha = 'right' ) self . airspeedText . set_path_effects ( [ PathEffects . withStroke ( linewidth = 1 , foreground = 'k' ) ] ) self . altitudeText . set_path_effects ( [ PathEffects . withStroke ( linewidth = 1 , foreground = 'k' ) ] ) self . climbRateText . set_path_effects ( [ PathEffects . withStroke ( linewidth = 1 , foreground = 'k' ) ] ) | Creates the text for airspeed altitude and climb rate . |
41,661 | def updateAARLocations ( self ) : self . airspeedText . set_position ( ( self . rightPos - ( self . vertSize / 10.0 ) , - 0.97 + ( 2 * self . vertSize ) - ( self . vertSize / 10.0 ) ) ) self . altitudeText . set_position ( ( self . rightPos - ( self . vertSize / 10.0 ) , - 0.97 + self . vertSize - ( 0.5 * self . vertSize / 10.0 ) ) ) self . climbRateText . set_position ( ( self . rightPos - ( self . vertSize / 10.0 ) , - 0.97 ) ) self . airspeedText . set_size ( self . fontSize ) self . altitudeText . set_size ( self . fontSize ) self . climbRateText . set_size ( self . fontSize ) | Update the locations of airspeed altitude and Climb rate . |
41,662 | def updateAARText ( self ) : 'Updates the displayed airspeed, altitude, climb rate Text' self . airspeedText . set_text ( 'AR: %.1f m/s' % self . airspeed ) self . altitudeText . set_text ( 'ALT: %.1f m ' % self . relAlt ) self . climbRateText . set_text ( 'CR: %.1f m/s' % self . climbRate ) | Updates the displayed airspeed altitude climb rate Text |
41,663 | def createBatteryBar ( self ) : self . batOutRec = patches . Rectangle ( ( self . rightPos - ( 1.3 + self . rOffset ) * self . batWidth , 1.0 - ( 0.1 + 1.0 + ( 2 * 0.075 ) ) * self . batHeight ) , self . batWidth * 1.3 , self . batHeight * 1.15 , facecolor = 'darkgrey' , edgecolor = 'none' ) self . batInRec = patches . Rectangle ( ( self . rightPos - ( self . rOffset + 1 + 0.15 ) * self . batWidth , 1.0 - ( 0.1 + 1 + 0.075 ) * self . batHeight ) , self . batWidth , self . batHeight , facecolor = 'lawngreen' , edgecolor = 'none' ) self . batPerText = self . axes . text ( self . rightPos - ( self . rOffset + 0.65 ) * self . batWidth , 1 - ( 0.1 + 1 + ( 0.075 + 0.15 ) ) * self . batHeight , '%.f' % self . batRemain , color = 'w' , size = self . fontSize , ha = 'center' , va = 'top' ) self . batPerText . set_path_effects ( [ PathEffects . withStroke ( linewidth = 1 , foreground = 'k' ) ] ) self . voltsText = self . axes . text ( self . rightPos - ( self . rOffset + 1.3 + 0.2 ) * self . batWidth , 1 - ( 0.1 + 0.05 + 0.075 ) * self . batHeight , '%.1f V' % self . voltage , color = 'w' , size = self . fontSize , ha = 'right' , va = 'top' ) self . ampsText = self . axes . text ( self . rightPos - ( self . rOffset + 1.3 + 0.2 ) * self . batWidth , 1 - self . vertSize - ( 0.1 + 0.05 + 0.1 + 0.075 ) * self . batHeight , '%.1f A' % self . current , color = 'w' , size = self . fontSize , ha = 'right' , va = 'top' ) self . voltsText . set_path_effects ( [ PathEffects . withStroke ( linewidth = 1 , foreground = 'k' ) ] ) self . ampsText . set_path_effects ( [ PathEffects . withStroke ( linewidth = 1 , foreground = 'k' ) ] ) self . axes . add_patch ( self . batOutRec ) self . axes . add_patch ( self . batInRec ) | Creates the bar to display current battery percentage . |
41,664 | def updateBatteryBar ( self ) : self . batOutRec . set_xy ( ( self . rightPos - ( 1.3 + self . rOffset ) * self . batWidth , 1.0 - ( 0.1 + 1.0 + ( 2 * 0.075 ) ) * self . batHeight ) ) self . batInRec . set_xy ( ( self . rightPos - ( self . rOffset + 1 + 0.15 ) * self . batWidth , 1.0 - ( 0.1 + 1 + 0.075 ) * self . batHeight ) ) self . batPerText . set_position ( ( self . rightPos - ( self . rOffset + 0.65 ) * self . batWidth , 1 - ( 0.1 + 1 + ( 0.075 + 0.15 ) ) * self . batHeight ) ) self . batPerText . set_fontsize ( self . fontSize ) self . voltsText . set_text ( '%.1f V' % self . voltage ) self . ampsText . set_text ( '%.1f A' % self . current ) self . voltsText . set_position ( ( self . rightPos - ( self . rOffset + 1.3 + 0.2 ) * self . batWidth , 1 - ( 0.1 + 0.05 ) * self . batHeight ) ) self . ampsText . set_position ( ( self . rightPos - ( self . rOffset + 1.3 + 0.2 ) * self . batWidth , 1 - self . vertSize - ( 0.1 + 0.05 + 0.1 ) * self . batHeight ) ) self . voltsText . set_fontsize ( self . fontSize ) self . ampsText . set_fontsize ( self . fontSize ) if self . batRemain >= 0 : self . batPerText . set_text ( int ( self . batRemain ) ) self . batInRec . set_height ( self . batRemain * self . batHeight / 100.0 ) if self . batRemain / 100.0 > 0.5 : self . batInRec . set_facecolor ( 'lawngreen' ) elif self . batRemain / 100.0 <= 0.5 and self . batRemain / 100.0 > 0.2 : self . batInRec . set_facecolor ( 'yellow' ) elif self . batRemain / 100.0 <= 0.2 and self . batRemain >= 0.0 : self . batInRec . set_facecolor ( 'r' ) elif self . batRemain == - 1 : self . batInRec . set_height ( self . batHeight ) self . batInRec . set_facecolor ( 'k' ) | Updates the position and values of the battery bar . |
41,665 | def createStateText ( self ) : self . modeText = self . axes . text ( self . leftPos + ( self . vertSize / 10.0 ) , 0.97 , 'UNKNOWN' , color = 'grey' , size = 1.5 * self . fontSize , ha = 'left' , va = 'top' ) self . modeText . set_path_effects ( [ PathEffects . withStroke ( linewidth = self . fontSize / 10.0 , foreground = 'black' ) ] ) | Creates the mode and arm state text . |
41,666 | def updateStateText ( self ) : self . modeText . set_position ( ( self . leftPos + ( self . vertSize / 10.0 ) , 0.97 ) ) self . modeText . set_text ( self . mode ) self . modeText . set_size ( 1.5 * self . fontSize ) if self . armed : self . modeText . set_color ( 'red' ) self . modeText . set_path_effects ( [ PathEffects . withStroke ( linewidth = self . fontSize / 10.0 , foreground = 'yellow' ) ] ) elif ( self . armed == False ) : self . modeText . set_color ( 'lightgreen' ) self . modeText . set_bbox ( None ) self . modeText . set_path_effects ( [ PathEffects . withStroke ( linewidth = 1 , foreground = 'black' ) ] ) else : self . modeText . set_color ( 'grey' ) self . modeText . set_bbox ( None ) self . modeText . set_path_effects ( [ PathEffects . withStroke ( linewidth = self . fontSize / 10.0 , foreground = 'black' ) ] ) | Updates the mode and colours red or green depending on arm state . |
41,667 | def createWPText ( self ) : self . wpText = self . axes . text ( self . leftPos + ( 1.5 * self . vertSize / 10.0 ) , 0.97 - ( 1.5 * self . vertSize ) + ( 0.5 * self . vertSize / 10.0 ) , '0/0\n(0 m, 0 s)' , color = 'w' , size = self . fontSize , ha = 'left' , va = 'top' ) self . wpText . set_path_effects ( [ PathEffects . withStroke ( linewidth = 1 , foreground = 'black' ) ] ) | Creates the text for the current and final waypoint and the distance to the new waypoint . |
41,668 | def updateWPText ( self ) : self . wpText . set_position ( ( self . leftPos + ( 1.5 * self . vertSize / 10.0 ) , 0.97 - ( 1.5 * self . vertSize ) + ( 0.5 * self . vertSize / 10.0 ) ) ) self . wpText . set_size ( self . fontSize ) if type ( self . nextWPTime ) is str : self . wpText . set_text ( '%.f/%.f\n(%.f m, ~ s)' % ( self . currentWP , self . finalWP , self . wpDist ) ) else : self . wpText . set_text ( '%.f/%.f\n(%.f m, %.f s)' % ( self . currentWP , self . finalWP , self . wpDist , self . nextWPTime ) ) | Updates the current waypoint and distance to it . |
41,669 | def createWPPointer ( self ) : self . headingWPTri = patches . RegularPolygon ( ( 0.0 , 0.55 ) , 3 , 0.05 , facecolor = 'lime' , zorder = 4 , ec = 'k' ) self . axes . add_patch ( self . headingWPTri ) self . headingWPText = self . axes . text ( 0.0 , 0.45 , '1' , color = 'lime' , size = self . fontSize , horizontalalignment = 'center' , verticalalignment = 'center' , zorder = 4 ) self . headingWPText . set_path_effects ( [ PathEffects . withStroke ( linewidth = 1 , foreground = 'k' ) ] ) | Creates the waypoint pointer relative to current heading . |
41,670 | def adjustWPPointer ( self ) : self . headingWPText . set_size ( self . fontSize ) headingRotate = mpl . transforms . Affine2D ( ) . rotate_deg_around ( 0.0 , 0.0 , - self . wpBearing + self . heading ) + self . axes . transData self . headingWPText . set_transform ( headingRotate ) angle = self . wpBearing - self . heading if angle < 0 : angle += 360 if ( angle > 90 ) and ( angle < 270 ) : headRot = angle - 180 else : headRot = angle self . headingWPText . set_rotation ( - headRot ) self . headingWPTri . set_transform ( headingRotate ) self . headingWPText . set_text ( '%.f' % ( angle ) ) | Adjust the position and orientation of the waypoint pointer . |
41,671 | def createAltHistoryPlot ( self ) : self . altHistRect = patches . Rectangle ( ( self . leftPos + ( self . vertSize / 10.0 ) , - 0.25 ) , 0.5 , 0.5 , facecolor = 'grey' , edgecolor = 'none' , alpha = 0.4 , zorder = 4 ) self . axes . add_patch ( self . altHistRect ) self . altPlot , = self . axes . plot ( [ self . leftPos + ( self . vertSize / 10.0 ) , self . leftPos + ( self . vertSize / 10.0 ) + 0.5 ] , [ 0.0 , 0.0 ] , color = 'k' , marker = None , zorder = 4 ) self . altMarker , = self . axes . plot ( self . leftPos + ( self . vertSize / 10.0 ) + 0.5 , 0.0 , marker = 'o' , color = 'k' , zorder = 4 ) self . altText2 = self . axes . text ( self . leftPos + ( 4 * self . vertSize / 10.0 ) + 0.5 , 0.0 , '%.f m' % self . relAlt , color = 'k' , size = self . fontSize , ha = 'left' , va = 'center' , zorder = 4 ) | Creates the altitude history plot . |
41,672 | def updateAltHistory ( self ) : self . altHist . append ( self . relAlt ) self . timeHist . append ( self . relAltTime ) histLim = 10 currentTime = time . time ( ) point = 0 for i in range ( 0 , len ( self . timeHist ) ) : if ( self . timeHist [ i ] > ( currentTime - 10.0 ) ) : break self . altHist = self . altHist [ i : ] self . timeHist = self . timeHist [ i : ] x = [ ] y = [ ] tmin = min ( self . timeHist ) tmax = max ( self . timeHist ) x1 = self . leftPos + ( self . vertSize / 10.0 ) y1 = - 0.25 altMin = 0 altMax = max ( self . altHist ) if altMax > self . altMax : self . altMax = altMax else : altMax = self . altMax if tmax != tmin : mx = 0.5 / ( tmax - tmin ) else : mx = 0.0 if altMax != altMin : my = 0.5 / ( altMax - altMin ) else : my = 0.0 for t in self . timeHist : x . append ( mx * ( t - tmin ) + x1 ) for alt in self . altHist : val = my * ( alt - altMin ) + y1 if val < - 0.25 : val = - 0.25 elif val > 0.25 : val = 0.25 y . append ( val ) self . altHistRect . set_x ( self . leftPos + ( self . vertSize / 10.0 ) ) self . altPlot . set_data ( x , y ) self . altMarker . set_data ( self . leftPos + ( self . vertSize / 10.0 ) + 0.5 , val ) self . altText2 . set_position ( ( self . leftPos + ( 4 * self . vertSize / 10.0 ) + 0.5 , val ) ) self . altText2 . set_size ( self . fontSize ) self . altText2 . set_text ( '%.f m' % self . relAlt ) | Updates the altitude history plot . |
41,673 | def on_idle ( self , event ) : self . checkReszie ( ) if self . resized : self . rescaleX ( ) self . calcFontScaling ( ) self . calcHorizonPoints ( ) self . updateRPYLocations ( ) self . updateAARLocations ( ) self . adjustPitchmarkers ( ) self . adjustHeadingPointer ( ) self . adjustNorthPointer ( ) self . updateBatteryBar ( ) self . updateStateText ( ) self . updateWPText ( ) self . adjustWPPointer ( ) self . updateAltHistory ( ) self . canvas . draw ( ) self . canvas . Refresh ( ) self . resized = False time . sleep ( 0.05 ) | To adjust text and positions on rescaling the window when resized . |
41,674 | def on_timer ( self , event ) : state = self . state self . loopStartTime = time . time ( ) if state . close_event . wait ( 0.001 ) : self . timer . Stop ( ) self . Destroy ( ) return self . checkReszie ( ) if self . resized : self . on_idle ( 0 ) while state . child_pipe_recv . poll ( ) : objList = state . child_pipe_recv . recv ( ) for obj in objList : self . calcFontScaling ( ) if isinstance ( obj , Attitude ) : self . oldRoll = self . roll self . pitch = obj . pitch * 180 / math . pi self . roll = obj . roll * 180 / math . pi self . yaw = obj . yaw * 180 / math . pi self . updateRPYText ( ) self . calcHorizonPoints ( ) self . adjustPitchmarkers ( ) elif isinstance ( obj , VFR_HUD ) : self . heading = obj . heading self . airspeed = obj . airspeed self . climbRate = obj . climbRate self . updateAARText ( ) self . adjustHeadingPointer ( ) self . adjustNorthPointer ( ) elif isinstance ( obj , Global_Position_INT ) : self . relAlt = obj . relAlt self . relAltTime = obj . curTime self . updateAARText ( ) self . updateAltHistory ( ) elif isinstance ( obj , BatteryInfo ) : self . voltage = obj . voltage self . current = obj . current self . batRemain = obj . batRemain self . updateBatteryBar ( ) elif isinstance ( obj , FlightState ) : self . mode = obj . mode self . armed = obj . armState self . updateStateText ( ) elif isinstance ( obj , WaypointInfo ) : self . currentWP = obj . current self . finalWP = obj . final self . wpDist = obj . currentDist self . nextWPTime = obj . nextWPTime if obj . wpBearing < 0.0 : self . wpBearing = obj . wpBearing + 360 else : self . wpBearing = obj . wpBearing self . updateWPText ( ) self . adjustWPPointer ( ) elif isinstance ( obj , FPS ) : self . fps = obj . fps if ( time . time ( ) > self . nextTime ) : self . canvas . draw ( ) self . canvas . Refresh ( ) self . Refresh ( ) self . Update ( ) if ( self . fps > 0 ) : fpsTime = 1 / self . fps self . nextTime = fpsTime + self . loopStartTime else : self . nextTime = time . time ( ) | Main Loop . |
41,675 | def on_KeyPress ( self , event ) : if event . GetKeyCode ( ) == wx . WXK_UP : self . dist10deg += 0.1 print ( 'Dist per 10 deg: %.1f' % self . dist10deg ) elif event . GetKeyCode ( ) == wx . WXK_DOWN : self . dist10deg -= 0.1 if self . dist10deg <= 0 : self . dist10deg = 0.1 print ( 'Dist per 10 deg: %.1f' % self . dist10deg ) elif event . GetKeyCode ( ) == 49 : widgets = [ self . modeText , self . wpText ] self . toggleWidgets ( widgets ) elif event . GetKeyCode ( ) == 50 : widgets = [ self . batOutRec , self . batInRec , self . voltsText , self . ampsText , self . batPerText ] self . toggleWidgets ( widgets ) elif event . GetKeyCode ( ) == 51 : widgets = [ self . rollText , self . pitchText , self . yawText ] self . toggleWidgets ( widgets ) elif event . GetKeyCode ( ) == 52 : widgets = [ self . airspeedText , self . altitudeText , self . climbRateText ] self . toggleWidgets ( widgets ) elif event . GetKeyCode ( ) == 53 : widgets = [ self . altHistRect , self . altPlot , self . altMarker , self . altText2 ] self . toggleWidgets ( widgets ) elif event . GetKeyCode ( ) == 54 : widgets = [ self . headingTri , self . headingText , self . headingNorthTri , self . headingNorthText , self . headingWPTri , self . headingWPText ] self . toggleWidgets ( widgets ) self . canvas . draw ( ) self . canvas . Refresh ( ) self . Refresh ( ) self . Update ( ) | To adjust the distance between pitch markers . |
41,676 | def fenceloader ( self ) : if not self . target_system in self . fenceloader_by_sysid : self . fenceloader_by_sysid [ self . target_system ] = mavwp . MAVFenceLoader ( ) return self . fenceloader_by_sysid [ self . target_system ] | fence loader by sysid |
41,677 | def mavlink_packet ( self , m ) : if m . get_type ( ) == "FENCE_STATUS" : self . last_fence_breach = m . breach_time self . last_fence_status = m . breach_status elif m . get_type ( ) in [ 'SYS_STATUS' ] : bits = mavutil . mavlink . MAV_SYS_STATUS_GEOFENCE present = ( ( m . onboard_control_sensors_present & bits ) == bits ) if self . present == False and present == True : self . say ( "fence present" ) elif self . present == True and present == False : self . say ( "fence removed" ) self . present = present enabled = ( ( m . onboard_control_sensors_enabled & bits ) == bits ) if self . enabled == False and enabled == True : self . say ( "fence enabled" ) elif self . enabled == True and enabled == False : self . say ( "fence disabled" ) self . enabled = enabled healthy = ( ( m . onboard_control_sensors_health & bits ) == bits ) if self . healthy == False and healthy == True : self . say ( "fence OK" ) elif self . healthy == True and healthy == False : self . say ( "fence breach" ) self . healthy = healthy if not self . present : self . console . set_status ( 'Fence' , 'FEN' , row = 0 , fg = 'black' ) elif self . enabled == False : self . console . set_status ( 'Fence' , 'FEN' , row = 0 , fg = 'grey' ) elif self . enabled == True and self . healthy == True : self . console . set_status ( 'Fence' , 'FEN' , row = 0 , fg = 'green' ) elif self . enabled == True and self . healthy == False : self . console . set_status ( 'Fence' , 'FEN' , row = 0 , fg = 'red' ) | handle and incoming mavlink packet |
41,678 | def load_fence ( self , filename ) : try : self . fenceloader . target_system = self . target_system self . fenceloader . target_component = self . target_component self . fenceloader . load ( filename . strip ( '"' ) ) except Exception as msg : print ( "Unable to load %s - %s" % ( filename , msg ) ) return print ( "Loaded %u geo-fence points from %s" % ( self . fenceloader . count ( ) , filename ) ) self . send_fence ( ) | load fence points from a file |
41,679 | def list_fence ( self , filename ) : self . fenceloader . clear ( ) count = self . get_mav_param ( 'FENCE_TOTAL' , 0 ) if count == 0 : print ( "No geo-fence points" ) return for i in range ( int ( count ) ) : p = self . fetch_fence_point ( i ) if p is None : return self . fenceloader . add ( p ) if filename is not None : try : self . fenceloader . save ( filename . strip ( '"' ) ) except Exception as msg : print ( "Unable to save %s - %s" % ( filename , msg ) ) return print ( "Saved %u geo-fence points to %s" % ( self . fenceloader . count ( ) , filename ) ) else : for i in range ( self . fenceloader . count ( ) ) : p = self . fenceloader . point ( i ) self . console . writeln ( "lat=%f lng=%f" % ( p . lat , p . lng ) ) if self . status . logdir is not None : fname = 'fence.txt' if self . target_system > 1 : fname = 'fence_%u.txt' % self . target_system fencetxt = os . path . join ( self . status . logdir , fname ) self . fenceloader . save ( fencetxt . strip ( '"' ) ) print ( "Saved fence to %s" % fencetxt ) self . have_list = True | list fence points optionally saving to a file |
41,680 | def poll ( self ) : if self . out_queue . qsize ( ) <= 0 : return None evt = self . out_queue . get ( ) while isinstance ( evt , win_layout . WinLayout ) : win_layout . set_layout ( evt , self . set_layout ) if self . out_queue . qsize ( ) == 0 : return None evt = self . out_queue . get ( ) return evt | check for events returning one event |
41,681 | def find_object ( self , key , layers ) : state = self . state if layers is None or layers == '' : layers = state . layers . keys ( ) for layer in layers : if key in state . layers [ layer ] : return state . layers [ layer ] [ key ] return None | find an object to be modified |
41,682 | def add_object ( self , obj ) : state = self . state if not obj . layer in state . layers : state . layers [ obj . layer ] = { } state . layers [ obj . layer ] [ obj . key ] = obj state . need_redraw = True if ( not self . legend_checkbox_menuitem_added and isinstance ( obj , SlipFlightModeLegend ) ) : self . add_legend_checkbox_menuitem ( ) self . legend_checkbox_menuitem_added = True self . SetMenuBar ( self . menu . wx_menu ( ) ) | add an object to a layer |
41,683 | def set_ground_width ( self , ground_width ) : state = self . state state . ground_width = ground_width state . panel . re_center ( state . width / 2 , state . height / 2 , state . lat , state . lon ) | set ground width of view |
41,684 | def show_popup ( self , selected , pos ) : state = self . state if selected . popup_menu is not None : import copy popup_menu = selected . popup_menu if state . default_popup is not None and state . default_popup . combine : popup_menu = copy . deepcopy ( popup_menu ) popup_menu . add ( MPMenuSeparator ( ) ) popup_menu . combine ( state . default_popup . popup ) wx_menu = popup_menu . wx_menu ( ) state . frame . PopupMenu ( wx_menu , pos ) | show popup menu for an object |
41,685 | def cmd_watch ( args ) : if len ( args ) == 0 : mpstate . status . watch = None return mpstate . status . watch = args print ( "Watching %s" % mpstate . status . watch ) | watch a mavlink packet pattern |
41,686 | def load_module ( modname , quiet = False , ** kwargs ) : modpaths = [ 'MAVProxy.modules.mavproxy_%s' % modname , modname ] for ( m , pm ) in mpstate . modules : if m . name == modname and not modname in mpstate . multi_instance : if not quiet : print ( "module %s already loaded" % modname ) return True ex = None for modpath in modpaths : try : m = import_package ( modpath ) reload ( m ) module = m . init ( mpstate , ** kwargs ) if isinstance ( module , mp_module . MPModule ) : mpstate . modules . append ( ( module , m ) ) if not quiet : if kwargs : print ( "Loaded module %s with kwargs = %s" % ( modname , kwargs ) ) else : print ( "Loaded module %s" % ( modname , ) ) return True else : ex = "%s.init did not return a MPModule instance" % modname break except ImportError as msg : ex = msg if mpstate . settings . moddebug > 1 : import traceback print ( traceback . format_exc ( ) ) help_traceback = "" if mpstate . settings . moddebug < 3 : help_traceback = " Use 'set moddebug 3' in the MAVProxy console to enable traceback" print ( "Failed to load module: %s.%s" % ( ex , help_traceback ) ) return False | load a module |
41,687 | def process_mavlink ( slave ) : try : buf = slave . recv ( ) except socket . error : return try : global mavversion if slave . first_byte and mavversion is None : slave . auto_mavlink_version ( buf ) msgs = slave . mav . parse_buffer ( buf ) except mavutil . mavlink . MAVError as e : mpstate . console . error ( "Bad MAVLink slave message from %s: %s" % ( slave . address , e . message ) ) return if msgs is None : return if mpstate . settings . mavfwd and not mpstate . status . setup_mode : for m in msgs : mpstate . master ( ) . write ( m . get_msgbuf ( ) ) if mpstate . status . watch : for msg_type in mpstate . status . watch : if fnmatch . fnmatch ( m . get_type ( ) . upper ( ) , msg_type . upper ( ) ) : mpstate . console . writeln ( '> ' + str ( m ) ) break mpstate . status . counters [ 'Slave' ] += 1 | process packets from MAVLink slaves forwarding to the master |
41,688 | def log_writer ( ) : while True : mpstate . logfile_raw . write ( bytearray ( mpstate . logqueue_raw . get ( ) ) ) timeout = time . time ( ) + 10 while not mpstate . logqueue_raw . empty ( ) and time . time ( ) < timeout : mpstate . logfile_raw . write ( mpstate . logqueue_raw . get ( ) ) while not mpstate . logqueue . empty ( ) and time . time ( ) < timeout : mpstate . logfile . write ( mpstate . logqueue . get ( ) ) if mpstate . settings . flushlogs or time . time ( ) >= timeout : mpstate . logfile . flush ( ) mpstate . logfile_raw . flush ( ) | log writing thread |
41,689 | def main_loop ( ) : global screensaver_cookie if not mpstate . status . setup_mode and not opts . nowait : for master in mpstate . mav_master : if master . linknum != 0 : break print ( "Waiting for heartbeat from %s" % master . address ) send_heartbeat ( master ) master . wait_heartbeat ( timeout = 0.1 ) set_stream_rates ( ) while True : if mpstate is None or mpstate . status . exit : return if ( mpstate . settings . inhibit_screensaver_when_armed and screensaver_interface is not None ) : if mpstate . status . armed and screensaver_cookie is None : screensaver_cookie = screensaver_interface . Inhibit ( "MAVProxy" , "Vehicle is armed" ) elif not mpstate . status . armed and screensaver_cookie is not None : screensaver_interface . UnInhibit ( screensaver_cookie ) screensaver_cookie = None while not mpstate . input_queue . empty ( ) : line = mpstate . input_queue . get ( ) mpstate . input_count += 1 cmds = line . split ( ';' ) if len ( cmds ) == 1 and cmds [ 0 ] == "" : mpstate . empty_input_count += 1 for c in cmds : process_stdin ( c ) for master in mpstate . mav_master : if master . fd is None : if master . port . inWaiting ( ) > 0 : process_master ( master ) periodic_tasks ( ) rin = [ ] for master in mpstate . mav_master : if master . fd is not None and not master . portdead : rin . append ( master . fd ) for m in mpstate . mav_outputs : rin . append ( m . fd ) for sysid in mpstate . sysid_outputs : m = mpstate . sysid_outputs [ sysid ] rin . append ( m . fd ) if rin == [ ] : time . sleep ( 0.0001 ) continue for fd in mpstate . select_extra : rin . append ( fd ) try : ( rin , win , xin ) = select . select ( rin , [ ] , [ ] , mpstate . settings . select_timeout ) except select . error : continue if mpstate is None : return for fd in rin : if mpstate is None : return for master in mpstate . mav_master : if fd == master . fd : process_master ( master ) if mpstate is None : return continue for m in mpstate . mav_outputs : if fd == m . fd : process_mavlink ( m ) if mpstate is None : return continue for sysid in mpstate . sysid_outputs : m = mpstate . sysid_outputs [ sysid ] if fd == m . fd : process_mavlink ( m ) if mpstate is None : return continue if fd in mpstate . select_extra : try : ( fn , args ) = mpstate . select_extra [ fd ] fn ( args ) except Exception as msg : if mpstate . settings . moddebug == 1 : print ( msg ) mpstate . select_extra . pop ( fd ) | main processing loop |
41,690 | def set_mav_version ( mav10 , mav20 , autoProtocol , mavversionArg ) : if ( mav10 == True or mav20 == True ) and autoProtocol == True : print ( "Error: Can't have [--mav10, --mav20] and --auto-protocol both True" ) sys . exit ( 1 ) if mav10 == True and mav20 == True : print ( "Error: Can't have --mav10 and --mav20 both True" ) sys . exit ( 1 ) if mavversionArg is not None and ( mav10 == True or mav20 == True or autoProtocol == True ) : print ( "Error: Can't use --mavversion with legacy (--mav10, --mav20 or --auto-protocol) options" ) sys . exit ( 1 ) global mavversion if mavversionArg == "1.0" or mav10 == True : os . environ [ 'MAVLINK09' ] = '1' mavversion = "1" else : os . environ [ 'MAVLINK20' ] = '1' mavversion = "2" | Set the Mavlink version based on commandline options |
41,691 | def mav_param ( self ) : compid = self . settings . target_component if compid == 0 : compid = 1 sysid = ( self . settings . target_system , compid ) if not sysid in self . mav_param_by_sysid : self . mav_param_by_sysid [ sysid ] = mavparm . MAVParmDict ( ) return self . mav_param_by_sysid [ sysid ] | map mav_param onto the current target system parameters |
41,692 | def get_wx_window_layout ( wx_window ) : dsize = wx . DisplaySize ( ) pos = wx_window . GetPosition ( ) size = wx_window . GetSize ( ) name = wx_window . GetTitle ( ) return WinLayout ( name , pos , size , dsize ) | get a WinLayout for a wx window |
41,693 | def set_wx_window_layout ( wx_window , layout ) : try : wx_window . SetSize ( layout . size ) wx_window . SetPosition ( layout . pos ) except Exception as ex : print ( ex ) | set a WinLayout for a wx window |
41,694 | def set_layout ( wlayout , callback ) : global display_size global window_list global loaded_layout global pending_load global vehiclename if not wlayout . name in window_list and loaded_layout is not None and wlayout . name in loaded_layout : callback ( loaded_layout [ wlayout . name ] ) window_list [ wlayout . name ] = ManagedWindow ( wlayout , callback ) display_size = wlayout . dsize if pending_load : pending_load = False load_layout ( vehiclename ) | set window layout |
41,695 | def layout_filename ( fallback ) : global display_size global vehiclename ( dw , dh ) = display_size if 'HOME' in os . environ : dirname = os . path . join ( os . environ [ 'HOME' ] , ".mavproxy" ) if not os . path . exists ( dirname ) : try : os . mkdir ( dirname ) except Exception : pass elif 'LOCALAPPDATA' in os . environ : dirname = os . path . join ( os . environ [ 'LOCALAPPDATA' ] , "MAVProxy" ) else : return None if vehiclename : fname = os . path . join ( dirname , "layout-%s-%ux%u" % ( vehiclename , dw , dh ) ) if not fallback or os . path . exists ( fname ) : return fname return os . path . join ( dirname , "layout-%ux%u" % ( dw , dh ) ) | get location of layout file |
41,696 | def save_layout ( vehname ) : global display_size global window_list global vehiclename if display_size is None : print ( "No layouts to save" ) return vehiclename = vehname fname = layout_filename ( False ) if fname is None : print ( "No file to save layout to" ) return layout = { } try : layout = pickle . load ( open ( fname , "rb" ) ) except Exception : pass count = 0 for name in window_list : layout [ name ] = window_list [ name ] . layout count += 1 pickle . dump ( layout , open ( fname , "wb" ) ) print ( "Saved layout for %u windows" % count ) | save window layout |
41,697 | def load_layout ( vehname ) : global display_size global window_list global loaded_layout global pending_load global vehiclename if display_size is None : pending_load = True return vehiclename = vehname fname = layout_filename ( True ) if fname is None : print ( "No file to load layout from" ) return try : layout = pickle . load ( open ( fname , "rb" ) ) except Exception : layout = { } print ( "Unable to load %s" % fname ) loaded_layout = layout return count = 0 for name in window_list : if name in layout : try : window_list [ name ] . callback ( layout [ name ] ) count += 1 except Exception as ex : print ( ex ) loaded_layout = layout print ( "Loaded layout for %u windows" % count ) | load window layout |
41,698 | def on_apply ( self , event ) : for label in self . setting_map . keys ( ) : setting = self . setting_map [ label ] ctrl = self . controls [ label ] value = ctrl . GetValue ( ) if str ( value ) != str ( setting . value ) : oldvalue = setting . value if not setting . set ( value ) : print ( "Invalid value %s for %s" % ( value , setting . name ) ) continue if str ( oldvalue ) != str ( setting . value ) : self . parent_pipe . send ( setting ) | called on apply |
41,699 | def on_save ( self , event ) : dlg = wx . FileDialog ( None , self . settings . get_title ( ) , '' , "" , '*.*' , wx . FD_SAVE | wx . FD_OVERWRITE_PROMPT ) if dlg . ShowModal ( ) == wx . ID_OK : self . settings . save ( dlg . GetPath ( ) ) | called on save button |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.