This chapter describes the basic steps for creating a new model. It describes how the source files should be laid out, how to register models with the server and how to work with GNU Autotools.
N.B. These instructions assume you are working from CVS, not a source snap-shot or distribution.Developers should consult Chapter 7 for detailed information on model class implementation. Developers are also advised to read Appendix B for Gazebo coding standards and conventions.
Source code for models is located under server/models/, with a separate directory for each model. Model directory names should match model class names, i.e., the SickLMS200 model is found the server/models/SickLMS200/ directory. Layout of files within the model directory is at the developers discretion; by convention, however, models are comprised of a single header file containing the model class declarations, and one or more source files containing the class definitions. Thus, the SickLMS200 model is comprised of SickLMS200.hh and SickLMS200.cc.
The recommended way to create a new model is to copy an existing model with similar functionality, and perform some judicious search-and-replacing. In addition to changing the class name (e.g. from SickLMS200 to MyModel), developers must also change the model's naked New function. E.g., NewSickLMS200() becomes NewMyModel(). This function is used to create instances of the model class at run-time.
Models must be registered with the server. Registration is handled by the ModelFactory class, which can be found in server/ModelFactory.cc. Registration is a two step process:
#if INCLUDE_MYMODEL extern Model* NewMyModel( World *world ); #endifThe INCLUDE macro will be defined automagically by Autotools (see below) if and only if the model should be included in the build.
#ifdef INCLUDE_MYMODEL if (strcmp(classname, "MyModel") == 0) return NewMyModel(world); #endifThis line allows the server to look up the model by name and construct an appropriate class instance at run-time.
Gazebo uses GNU Autotools to managing the build process; while Autotools can be daunting for newcomers, the rewards are well worth the effort. When using Autotools, there are two key notions to bear in mind:
The basic process for adding a new model to the Autotools setup is as follows.
$ ./bootstrapwith whatever arguments you would normally pass to configure.