User:Callahanp: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
No edit summary
Line 2: Line 2:


== What I'm doing: ==
== What I'm doing: ==
===Flightgear Code Introduction===
   
   
Recently I began the effort to fully understand the skills needed to contribute to the Flightgear project's codebase.  I'm beginning to look through various parts of the Flightgear code-base to understand how the parts fit together and how supporting libraries are used in the project.
I'm documenting my efforts. see [http://wiki.flightgear.org/User:Callahanp/Flightgear_and_Simgear_Code Flightgear and Simgear Code] Take a look if you're on the same path.
I'll be working on the interface between Flightgear and low level hardware in a panel or cockpit.  It is my understanding that others, including core Flightgear developers are also working on this and my efforts will  follow, derive from, depend on and I hope contribute in some small way to their work.
I'll be working on the interface between Flightgear and low level hardware in a panel or cockpit.  It is my understanding that others, including core Flightgear developers are also working on this and my efforts will  follow, derive from, depend on and I hope contribute in some small way to their work.


Recently I began the effort to fully understand the skills needed to contribute to the Flightgear project's codebase.  I know c++ from a course in the early 90's.  I'm looking at Kdevelop and QTquick as development tools.
=== Flightgear Codebase ===
My area of interest is in Flightgear's code includes:
* telnet
* phi
* reset & re-initialize
* any method to set or get a property
* the property tree itself
* configuration files
* command line parameters
I'm beginning to look through various parts of the Flightgear code-base to understand how the parts fit together and how supporting libraries are used in the project.  I'd like to learn how aircraft data and graphics are integrated into the working program, and how, why and where Nasal scripting is used.  To this end, I have
* Built a full debug version of the next branch
* Installed
** [https://gdbgui.com/ gdbgui]
** [https://atom.io/ atom] for basic code exploration.
Later I'll try QtCreator
Here's my directory structure for building
*$HOME
** A separate disk to make it easy to reinstall linux.  $HOME is the same as /home/$USER
*$HOME/fg
** Scripts I need to build and flightgear such as download_and_compile.sh, and /run/debug script
** This is actually a symlink to a folder on a separate disk from /home. 
** I do this so I can build the software I want without continually expanding my home disk's size.
** The fg directory contains a folder for each different build of Flightgear.
*** next for running next
*** nextrti for running next with OpenRTI
*** nextd for debugging next
*** stable
*** stabled
** Each of these directories contains clones for flightgear, simgear and other projects like OSG and OpenRTI as needed.
Rather than use excessive bandwidth, when I need a fresh copy, I just run download_and_compile.sh in a folder that already has a copy of the sources. Then I copy the folder over to the one I want to refresh and remove the build folder within the new one.  Then run the script again to produce the executable version I want. As currently structured, download_and_compile.sh requires a separate set of sources for each different version built.
Here's the atom/run/debug script I use for debugging
cd $HOME/fg/
#!/bin/bash
# ~/fg/debug
$cmd = "$HOME/fg/nextd/install/flightgear/bin/fgfs \
  --fg-root=$HOME/fg/nextd/install/flightgear/bin/../fgdata/ \
  --log-level=2 \
  --fg-scenery=$HOME/fg/nextd/install/flightgear/bin/../fgdata/Scenery \
  --fg-aircraft=$HOME/fg/nextd/install/flightgear/bin/../fgdata/Aircraft \
  --fg-aircraft=$HOME/.fgfs/Aircraft/org.flightgear.fgaddon/Aircraft \
  --httpd=5401 --telnet=5400 --airport=KSFO"
  $gdbgui "$cmd"
When the source window appears, press the "r" key to start debugging.
I start by stepping through bootstrap and other modules until flightgear is up and running.
I'm making some notes.  There are three sections:
* '''Path''' will trace the path through modules that provide significant functionality to the Simulator until the aircraft is shown holding short or parked somewhere. only the module's source path and a brief explanation or list of why it's on the "path".
* '''Modules''' lists all the classes and methods or functions executed on the "path" as well as those that are not executed in the path.
* '''Utility Calls''' will contain notes on various library calls, noting what the call looks like, where the library comes from, what the call does and where else it might be used. These will be functions with a purpose that is not limited to flight simulation.
====The Path to "Holding Short"====
When you start flight gear, several activities take place
* logging is set up
* command line arguments are checked, read and saved
* a global object is created to hold state and references to managing functions of several types
* a tree of properties is built on the global object
* various static objects are created and initialized
* scenery data is downloaded using terrasync
* airport and aircraft data is scanned and made available
* scenery data is read and made available
* an interpreter is started
* connections to multiplayer servers are made
* a scene is established as a "view" with scenery, Airport data and the Aircraft
* an event loop is started to adjust the view based on changes in controls, weather, aircraft position and attitude
{| class="wikitable"
|-
! Module
! colspan="3" | Description & Steps
|-
| src/Main/bootstrap Main
| Bootstrap provides the top level of the stack for executing either fgviewerMain or fgMainInit.
* Enable Floating Point features with InitFPE
* Set locale settings specific to using C or C++
* Uninstall if requested
|
* Initialize logging
* Initialize some static objects in OSG to prevent crashes on exit
* set the std:: terminate function
|
* set the atexit function
* pass control to the viewer with fgViewerMain or initialize using '''fgMainInit'''
* catch throwables and other fatal error conditions, providing appropriate error messages
|-
| src/Main/Main || fgMainInit( int argc, char **argv )
* set logging level and enable logging
* setup globals as an instance of FGGlobals. 
** see  src/Main/globals.cxx constructor FGGlobals::FGGlobals()
* make sure there's a valid FG_HOME directory and set up logging there
* set the version & log the version, build type and Jenkins or Hudson build id
* seed the random number generator
* set up a few things in globals
* decide if we're using a launcher
** see below src/Main/Main.cxx Launcher for details
* set read-only mode when more than one flightgear instance is found
* load configuration data
** see src/Main/Main.cxx'''fgInitConfig'''
* initalize aircraft paths
** see: src/Main/fg_init.cxx fgInitAircraftPaths and fgInitAircraft
|
* create an instance of the addon manager
** see below src/Add-ons/AddonManager.cxx
* check that the paths are allowed when they come from an untrusted source
* create an instance of an embedded resource manager
** see below simgear::EmbeddedResourceManager createInstance
** and initFlightGearEmbeddedResources
* get the preferred language and set the locale
* initialize the windows/graphics environment
** see viewer/fg_os_osgviewer.cxx fgosinit(int* argc, char** argv)
* register fgIdleFunction
** see fgRegisterIdleHandler in Main/fg_os_common.cxx and fgIdleFUnction in Main/main.cxx
* Initialize sockets
** simgear::Socket::initSockets()
* setup alpha channel for Clouds3D
** fgOSOpenWindow(true /* request stencil buffer */);
** fgOSResetProperties();
|
* fntInit();
* globals->get_renderer()->preinit();
* ATIScreenSizeHack
* fgOutputSettings();
* disable the screensaver
* pass control off to the master event handler
** See viewer/fg_os_osgviewer.cxx fgOSMainLoop() (next)
* cleanup
** frame_signal.clear();
** fgOSCloseWindow();
** simgear::clearEffectCache();
** delete globals;
** globals = NULL;
* delete the NavCache here. This will cause the destruction of many cached objects (eg, airports, navaids, runways).
** delete flightgear::NavDataCache::instance();
* return to bootstrap.cxx Main  return result;
|-
| viewer/fg_os_osgviewer.cxx || fgOSMainLoop()
* Release the viewer's context at end of frame hint
** viewer->setReleaseContextAtEndOfFrameHint(false)
* If the viewer is not realized yet, realize it. We still see nothing in the window
** viewer->realize()
|colspan="2"| here's the loop:
* get the idle handler
** fgIdleHandler idleFunc = globals->get_renderer()->getEventHandler()->getIdleHandler();
* run the idle handler  It's not clear what this is. It's either fgMainLoop or fgIdleFunction
** (*idleFunc)()
* update the screen
** globals->get_renderer()->update();
* timestamp the frame
** viewer->frame( globals->get_sim_time_sec() );
|-
| Main/main.cxx || fgIdleFunc
* normal startup has states 0, 2, 3, 4, 5, 7, 8, 9, 10, 900 1000
* reset startup has 2000, 2005, 2007, 8, 9, 10, 900, 1000
* state 1000 sets  fgMainLoop as the idle function. a reset sets it back to fgIdleFunc
* state 0 checks the openGL version and sets video options
** see checkOpenGLVersion() and  fgSetVideoOptions()
* state 2 sets /sim/rendering/initialized true and initializes terrasync with initTerrasync()
* state 3 loads nav data
** fgInitNav()
* state 4 initalizes scenery, but there's not call here
* state 5
** initializes some general items with fgInitGeneral()
** adds the TimeManager
*** globals->add_new_subsystem<TimeManager>(SGSubsystemMgr::INIT)
** initializes property based commands
*** fgInitCommands(); and fgInitSceneCommands();
** registers Subsystem Commands
*** flightgear::registerSubsystemCommands(globals->get_commands());
** initializes the material manager
*** globals->set_matlib( new SGMaterialLib )
*** simgear::SGModelLib::setPanelFunc(FGPanelNode::load)
|
* state 7
** Initializes Position
*** flightgear::initPosition(); and flightgear::initTowerLocationListener();
** Initializes somethingin SGModelLib
*** simgear::SGModelLib::init(globals->get_fg_root().local8BitStr(), globals->get_props());
** initializes the time manager instantiated in state 5
***auto timeManager = globals->get_subsystem<TimeManager>(); timeManager->init();
* state 8
* Create subsystems
** fgCreateSubsystems(isReset)
* log the time spent creating subsystems
* state 9
** bind subsystems
** globals->get_subsystem_mgr()->bind();
***
* state 10
** initialize subsystems
*** SGSubsystem::InitStatus status = globals->get_subsystem_mgr()->incrementalInit();
** remains in state 10 until  SGSubsystem::INIT_DONE
* state 900
** do what needs doing after systems are initialized
*** fgPostInitSubsystems(); 
|
* state 1000
** setup OpenGl view Parameters
*** globals->get_renderer()->setupView();
** resize the window to startup size
***  globals->get_renderer()->resize(x,y)
** unsure what this does
*** WindowSystemAdapter::getWSA()->windows[0]->gc->add(new simgear::canvas::VGInitOperation() )
* increment /sim/session
* State 1000 takes a break and continues with the next call
** sglog().setStartupLoggingEnabled(false)
* turns off logging for startup
* sets sim/scenery loaded to false
* changes the idle function
** registerMainLoop();
* state 2000
** Reset the application
*** fgStartNewReset();
* state 2005 same as state 5
* state 2007 same as state 7
Note fgResetIdleState() sets the state to 2000 and re-registers fgIdleFunction as the idle handler.
|-
| Main/main.cxx || fgMainLoop( void )| We seem to have arrived.  We're at the hold short point.
|}
'''Minor functions on the Path to Holding Short'''
{| class="wikitable"
|-
! Module !! Description !! Steps
|-
| src/Main/globals || Provides a global object to contain references to objects and data needed in initializing, running and terminating flightgear
|
* Provides global access to
** the property tree
** subsystem, event, command and resource manager objects and methods
** position, current view and aircraft orientation data
** FG_ROOT and FG_HOME directory paths
** time, comm channel, waypoint, and user settings data
* uses foreach from the boost library
|-
| <boost/foreach.h> || Example ||
|-
| <algorithm> || Example || Example
|-
| std::string version(FLIGHTGEAR_VERSION) ||  ||
|-
| sg_srandom_time(); ||  ||
|-
| src/Main/Main.cxx'''fgInitConfig''' ||  ||
|-
|  src/Main/Main.cxx Launcher ||  ||
|-
| src/Add-ons/AddonManager.cxx  ||  addons::AddonManager::createInstance() ||
|-
| initFlightGearEmbeddedResources ||  || see  file build/flightgear/src/EmbeddedResources/FlightGear-resources.cxx,automatically generated by fgrcc
|-
| viewer/fg_os_osgviewer.cxx fgosinit(int* argc, char** argv) ||  ||
|-
| Main/fg_os_common.cxx  || fgRegisterIdleHandler( & fgIdleFunction ||
|-
| detectSIMD() || bootstrap.cxx || returns true if the cpu supports sse2.
|-
| gethostname(_hostname, 256) || unistd.h glibc || returns the hostname of your computer
|-
| signal(SIGPIPE, SIG_IGN) || signal.h || directs SIGPIPE to the SIG_IGN signal handler - Portability: use sigaction() instead
|-
|  signal(SIGSEGV, segfault_handler) || signal.h  || Flightgear formats the message with a backtrace and exits with std:abort()
|-
|  segfault_handler (int signo) || bootstrap.cxx  ||
|-
|  '''initFPE'''(flightgear::Options::checkForArg(argc, argv, "enable-fpe")) || main/options.cxx<br>  bootstrap.cxx || checks the command line arguments for the enable-fpe option. Calls InitFPE with the result. <br> see bootstrap.cxx for more details
|-
|  signal(SIGFPE, handleFPE) || signal.h<br/> bootstrap.cxx || We handle Floating Point Exceptions
|-
| setlocale(LC_ALL, "") <br/> setlocale(LC_NUMERIC, "C") <br/> setlocale(LC_COLLATE, "C") ||  ||
|-
| return fgUninstall() || fg_init.cxx || Command line options are checked to determine if uninstall should be called.
|-
| sglog() || /simgear/debug/logstream.cxx || This initializes the log. see logstream.cxx for details
|-
| std::set_terminate(fg_terminate); || <exception> <br> bootstrap.cxx || sets the standard template library terminate routine<br>
|-
| atexit(fgExitCleanup) || stdlib.h<br> bootstrap.cxx || registers the given function to be called at normal process termination, either via exit(3) or via return from the program's main().  Functions so registered are called in the reverse order of their registration; no arguments are passed
|-
|  fgviewerMain(argc, argv) || flightgear/Viewer/fgviewer.cxx  || see viewer topics for details.  This is called in bootstrap.cxx if the command line arguments include --viewer
|-
| '''fgMainInit(argc, argv)''' || '''Main/main.cxx''' || Starts to initialize flightgear.  This is called in bootstrap.cxx if command line arguments do ''not'' contain --viewer
|-
| catch block || various || termination for most or all errors. Read the end of bootstrap.cxx for more information
|-
|  flightgear::shutdownQtApp() || bootstrap<br/> Qt ||  Done separately from atexit. see bootstrap.cxx for more information
|-
| crInstall(&info)<br>crUninstall() || [http://crashrpt.sourceforge.net CrashRpt.h] || #if defined(HAVE_CRASHRPT). This only happens on windows.
|-
sglog().setLogLevels( SG_ALL, SG_INFO )<br>sglog().setStartupLoggingEnabled(true); || /simgear/debug/logstream.cxx || Pretty obvious what this does. || '''What does sglog() actually return?'''
|}


=== Progress on Cockpit Building ===
=== Progress on Cockpit Building ===
Line 336: Line 28:
* [[User:Callahanp/Snippets |Snippets]] of text that may or may not be used somewhere
* [[User:Callahanp/Snippets |Snippets]] of text that may or may not be used somewhere


===== Contact =====
=== Contact ===


Maybe our projects overlap and maybe I can be of help you in some small way. I love bouncing ideas back and forth in personal or public e-mails.  Feel free to contact me about your non-commercial simulation projects. <br> '''[[Special:EmailUser/Callahanp | Email Callahanp through the wiki]]'''
  '''[[Special:EmailUser/Callahanp | Email Callahanp through the wiki]]'''


I show up occasionally on #flightgear on irc.flightgear.org and am a member of several public forums related to cockpit building.
I show up occasionally on #flightgear on irc.flightgear.org and am a member of several public forums related to cockpit building.
Line 384: Line 76:
Rule 1. Brevity.
Rule 1. Brevity.


Rule 2. Real Hardware.  If I haven't done it yet I'll talk about it on my personal wiki page.  That's where stuff like that belongs.   
Rule 2. Real Hardware & Software.  If I haven't done it yet I'll talk about it on my personal wiki page.  That's where stuff like that belongs.   


Rule 3. Project Planning, Building Teams, and anything else about developing a hobby project belong elsewhere.  If you want to write about these things, go ahead, but don't do it in a Howto on building something specific like a cockpit.  If you haven't done the project yet you'll get it wrong. Plus, you'll sound like a...
Rule 3. Project Planning, Building Teams, and anything else about developing a hobby project belong elsewhere.  If you want to write about these things, go ahead, but don't do it in a Howto on building something specific like a cockpit.  If you haven't done the project yet you'll get it wrong. Plus, you'll sound like a...

Revision as of 01:26, 17 February 2018

I am a flight simulation hobbyist currently working on building instruments, gauges, radios and controls for a C172.

What I'm doing:

Flightgear Code Introduction

Recently I began the effort to fully understand the skills needed to contribute to the Flightgear project's codebase. I'm beginning to look through various parts of the Flightgear code-base to understand how the parts fit together and how supporting libraries are used in the project.

I'm documenting my efforts. see Flightgear and Simgear Code Take a look if you're on the same path.

I'll be working on the interface between Flightgear and low level hardware in a panel or cockpit. It is my understanding that others, including core Flightgear developers are also working on this and my efforts will follow, derive from, depend on and I hope contribute in some small way to their work.


Progress on Cockpit Building

As of Feb 1, 2018:

  • I've done only a few prototype circuits
  • have been working to develop skills I'll need to produce a realistic cockpit.
  • Developing skills in Fusion 360 to support 3d Printing and 3d machine tools.
  • Working on tests for a cluster based on Raspberry Pi Zeros
  • Beginning to use a 3d Router
  • Milling into thin prisms and hand polishing disks of plexiglass for illuminating dials in Sim Instruments

As part of my Cockpit Building efforts, I'm also working on

Contact

 Email Callahanp through the wiki

I show up occasionally on #flightgear on irc.flightgear.org and am a member of several public forums related to cockpit building.

Callahanp (talk) 09:45, 11 November 2017 (EST)

My Skills

  • Programming in whatever language is available
  • Databases
  • Making the following list of chips do what they do:
  • MCP23XXX Multiplexer
  • MAX7219 Serially Interfaced, 8-Digit LED Display Driver
  • Designing a few types of circuits that work on a breadboard (see electronics below)
My Developing Skills -- Beginner
  • Grokking Flightgear's code base.
  • Very basic machining on a lathe or mill - no significant experience
  • Electronics - Basics - DC, High & Low speed digital circuits, motor control, emi suppression and mitigation
  • Soldering - Learn to deal with small components
  • Designing circuits that make it from breadboard to cockpit.
  • Getting a cokpit project off the ground
  • C++ - Updating coding skills from an early version of C++
  • Avoiding Writing Howtos
My Developing Skills -- Making Good Progress
  • Fusion 360 3dCad
  • 3d Router

The Howtos -- Oh yeah... those...

I'm working on these along side building my cockpit. Some of the early attempts were not that useful. My current approach is to build and document actual hardware. I hope this will be more helpful.

Current Projects:

See below for the my personal rules about these howtos going forward. I had to write these because it was becoming a morass and time waster.

The following is yet another work in progress

Writing Advice to Callahanp from Callahanp  or How to write a Howto.

Rule 1. Brevity.

Rule 2. Real Hardware & Software. If I haven't done it yet I'll talk about it on my personal wiki page. That's where stuff like that belongs.

Rule 3. Project Planning, Building Teams, and anything else about developing a hobby project belong elsewhere. If you want to write about these things, go ahead, but don't do it in a Howto on building something specific like a cockpit. If you haven't done the project yet you'll get it wrong. Plus, you'll sound like a...

Rule 4. Grand visions, Vaporware, Abstract thinking, Advice and other nonsense don't belong anywhere.

Rule 5. Get rid of your darlings. Those witty turns of phrase, that elegant prose, the puns, jokes and asides. Fun to write maybe but not so fun to read. They're distractions. These are things a skillful writer can weave into an uninterrupted smooth train of thought but you're not that good a writer. Don't even try,

'nuff said.