Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Version 3 (modified by scheusso, 15 years ago) (diff)

Basic PPS Tutorial

This is a basic tutorial for new PPS students to get familiar with our framework and build environment. The process is described for tardis here. If you use another system first go to the download page and make sure you have all dependencies installed.

Preparations

We check out the source and media repository and build for the first time

  1. Create your orxonox directory (if not already existing):
    mkdir ~/orxonox
    cd ~/orxonox
    
  2. Now check out the latest revision of the media repository (you will probably be asked for a username and password once):
    svn co https://svn.orxonox.net/game/data/trunk data_extern
    
  3. Now get the latest revision of the tutorial:
    svn co https://svn.orxonox.net/game/code/branches/tutorial
    
  4. Prepare to build:
    mkdir tutorial/build
    cd tutorial/build
    cmake-2.6.2 ..
    
  5. Now build for the first time (may take some time, further builds will be faster):
    make -j4  #-j4 means to create 4 parallel compile processes
    
  6. Additionally you can use KDevelop3? as IDE to develop (if you don't want to use the console ;))

Start the game for the first time

  1. Enter to the appropriate folder and start the game. You will see a menu popping up, just press the Standalone button.
    cd ~/orxonox/tutorial/build
    ./run
    

The Drone

We created for you the skeleton of an autonomous drone. You can find the code in the files 'src/orxonox/objects/worldentities/Drone.{cc|h}' and 'src/orxonox/objects/controllers/DroneController.{cc|h}'.

  1. open the file Drone.cc and have a look at the code
  2. in order to be able to create a Drone object from the xml file or somewhere else just by the class name you need to add a call of CreateFactory(Classname) somewhere inside the cc file (global, inside the namespace)
    CreateFactory(ClassX)
    
  3. make sure the each drone object gets registered to the core by adding a call of RegisterObject(Classname) inside the constructor
    RegisterObject(ClassXY)
    
  4. now go to the XMLPort function and add the calls for the three variables primaryThrust_, auxilaryThrust_ and rotationThrust_.
    XMLPortParam(Classname, "xml-attribute-name (i.e. variablename)", setFunction, getFunction, xmlelement, mode)
    

That's it for the Drone class

The DroneController

Now you will finish the DroneController which gets called each tick and steers the drone.

  1. open the file DroneController.cc and look at it
  2. have a look at the constructor and make sure nothing is missing (think of the core)
  3. now look at the tick function. it gets called each time before a new frame is drawn. you can put in some steering code here. if you want you can use some functions provided by Math.h:
    rnd() // return a random value between 0 and 1
    sin() // should be clear (also cos)
    // many other functions (have a look at src/util/Math.h for details)
    

The XML Part

Now that you finished the classes you can recompile the project. Afterwards open the level file:

  1. open media/levels/tutorial.oxw
  2. we want to add a drone to the level now, so put in an entry for it (below the Light definition). look at this example:
    <ClassX variable1="2" string1="blabla" coord1="1,0,0">
    </ClassX>
    
  3. now add the appropriate entries for the variables you defined in Drone/4. (Have a look at media/levels/spaceshiptemplates_physics.oxw for example values)
  4. as we want our drone to be visible we have to attach a model to it. add the following code between the above 2 lines:
      <attached>
        <Model scale="10" mesh="drone.mesh"/>
      </attached>
    
    this adds a model with the mesh drone.mesh and the defined textures at the position of our drone object.
  1. because the physics engine needs a collision shape to work with, we will add the following entry (before </ClassX>):
      <collisionShapes>
        <BoxCollisionShape position="0,0,0"      halfExtents="10, 10, 10" />
      </collisionShapes>
    
    this will tell the physics engine what dimensions our drone has (in this case its just a cube)
  2. now we define the mass and two damping parameters of our drone. Append definitions for the following variables as attributes to your drone (as in 3.)
    mass = 50
    linearDamping = 0.9
    angularDamping = 0.7
    

Have a look at your Drone

  • Now recompile the code, start the game again and have a look at how your drone behaves.
  • Don't worry if it does not react to your steering commands as expected. Try to modify some things.
  • If you want to do some more things you can try to let the drone fly in circles or helixes
  • Play around a little bit with the linear/angular-Damping parameters

Commit your code to the repository

We may want to use your steering function later on, so commit it now:

  1. make sure you have a recent version of the branch
    ~/orxonox/tutorial$ svn up
    
  2. in order to avoid conflicts copy your file (DroneController.cc)
    ~/orxonox/tutorial$ svn cp src/orxonox/objects/controllers/DroneController.cc src/orxonox/objects/controllers/DroneController.cc_myUserName
    
  3. make sure you dont commit any changes of the original file, so revert your local changes on it:
    ~/orxonox/tutorial$ svn revert src/orxonox/objects/controllers/DroneController.cc
    
  4. now commit
    ~/orxonox/tutorial$ svn ci -m"this is my version of the Drone steering function" src/orxonox/controllers/DroneController.cc_myUserName