Version 10 (modified by FelixSchulthess, 16 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
- Create your orxonox directory (if not already existing):
mkdir ~/orxonox cd ~/orxonox
- 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/data/media
- Now get the latest revision of the tutorial:
svn co https://svn.orxonox.net/orxonox/branches/tutorial
- Prepare to build:
mkdir tutorial/build cd tutorial/build cmake-2.6.2 ..
- 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
- 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
- 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}'.
- open the file Drone.cc and have a look at the code
- 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)
- make sure the each drone object gets registered to the core by adding a call of RegisterObject(Classname) inside the constructor
RegisterObject(ClassXY)
- now go to the XMLPort function and add the calls for the three variables primaryThrust_, auxilaryThrust_ and rotationThrust_.
XMLPortParamVariable(Classname, "xml-attribute-name", variablename, 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.
- open the file DroneController.cc and look at it
- have a look at the constructor and make sure nothing is missing (think of the core)
- 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:
- open media/levels/tutorial.oxw
- 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>
- 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)
- 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.
- because the physic engine needs a collision shape to work we will add the following entry (before </ClassX>):
<collisionShapes> <BoxCollisionShape position="0,0,0" halfExtents="10, 10, 10" /> </collisionShapes>
this will tell the phyic engine what dimensions our drone has (in this case its just a cube) - now we define the mass and to 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 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 to try 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:
- make sure you have a recent version of the branch
~/orxonox/tutorial$ svn up
- in order to avoid conflicts copy your file (DroneController.cc)
~/orxonox/tutorial$ svn cp src/orxonox/controllers/DroneController.cc src/orxonox/controllers/DroneController.cc_myUserName
- make sure you dont commit any changes of the original file, so revert your local changes on it:
~/orxonox/tutorial$ svn revert src/orxonox/controllers/DroneController.cc
- now commit
~/orxonox/tutorial$ svn ci -m"this is my version of the Drone steering function"