-
Notifications
You must be signed in to change notification settings - Fork 20
Generating Code (C)
C++ Guides: GAMS Primer | Simulation Primer | Generating Code | Creating Algorithms | Creating Platforms | Creating Threads | Creating Transports | Debugging
After running simulations and seeing what is possible, developers tend to want to know how to extend things for their own purposes. In this section, we'll go over the gpc.pl script and how we use it to generate various classes and controllers that can be used in simulations or directly on real-world robotics.
gpc.pl is a versatile perl script that can generate most MADARA and GAMS artifacts. With gpc.pl, you can generate everything from threads and networking transports to robotics platforms and decentralized algorithms.
$GAMS_ROOT/scripts/projects/gpc.pl -p $HOME/projects/generatedThe default generation for gpc.pl just requires a path to a project area. If any directory in the path specified by -p does not exist, then the directories will be created recursively. Consequently, in -p $HOME/projects/generated, the gpc.pl would generate both the projects directory and the generated directory within the projects directory. If all of the directories exist, nothing will be generated and you may have to use the --force option, if you want that directory to be populated with project files that you can build with g++ or clang.
What is generated in the directory? In addition to a MakefileProjectCreator project (which can generate solutions in Visual Studio, make, etc.), you will get a custom GAMS agent controller that can be compiled. Basically, the new project will have access to everything you see in the image below.
After you've generated your directory, you can then change into that directory with cd and use gpc.pl without requiring the -p parameter to specify the project location. gpc.pl by default uses the current directory (where you're currently at in the filesystem).
cd $HOME/projects/generated
./action.sh compileBy default, compilation on Linux will be with g++ or whatever compiler you chose during the GAMS build process (what you did during installation). Other options that are available for compilation can be found via ./action.sh help, but the most common one tends to be clang if you want to compile with clang.
After you've compiled with action.sh, you can then run the custom_controller binary in the bin directory of your project.
cd $HOME/projects/generated
bin/custom_controller -hThe custom controller gives you access to any GAMS algorithm that exists and also any of the default platforms (such as osc-quad for a quadcopter that can run in the Unreal Engine). See the -h option above for all of the useful default command line arguments that are included in gpc.pl generation.
As mentioned in earlier sections, you can generate most of the extensible artifacts provided by the MADARA and GAMS APIs. Some examples of these useful C++ processes are below:
~: cd $HOME/projects/generated
~/projects/generated: $GAMS_ROOT/scripts/projects/gpc.pl --new-algorithm NewAlgorithm
~/projects/generated: $GAMS_ROOT/scripts/projects/gpc.pl --new-platform NewPlatform --new-platform-thread PlatformThread
~/projects/generated: $GAMS_ROOT/scripts/projects/gpc.pl --new-thread NewThread
~/projects/generated: $GAMS_ROOT/scripts/projects/gpc.pl --new-transport NewTransport
~/projects/generated: $GAMS_ROOT/scripts/projects/gpc.pl --on-receive ReceiveFilter
~/projects/generated: $GAMS_ROOT/scripts/projects/gpc.pl --on-send SendFilter
~/projects/generated: $GAMS_ROOT/scripts/projects/gpc.pl --buffer-filter BufferFilterWhere can you find the generated code? Everything will be located in the src folder within your $HOME/projects/generated directory. The generated directories should include the following listing:
cd $HOME/projects/generated/src
~/projects/generated/src: ls
algorithms controller.cpp filters platforms transports
containers Namespaces.h threadsThe algorithm you generated with --new-algorithm will be located in src/algorithms/NewAlgorithm.h|cpp. The new platform generated with --new-platform will be located in src/platforms/NewPlatform.h|cpp. The --new-platform-thread generation will be at src/platforms/threads/NewPlatformThread.h|cpp. The on-send, on-receive, and buffer filters will be within the src/filters directory in their respective files. Controller-level threads will be in src/threads, and any MADARA transports you generate will go in src/transports.
- Generating, Scaling, and Visualizing Autonomy
- Creating Algorithms
- Creating Platforms
- Creating Threads
C++ Guides: GAMS Primer | Simulation Primer | Generating Code | Creating Algorithms | Creating Platforms | Creating Threads | Creating Transports | Debugging
