Version 16 (modified by dafrick, 14 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 data 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 data repository (you will probably be asked for a username and password once):
svn co https://svn.orxonox.net/game/data/trunk data_extern
- Now get the latest revision of the tutorial:
svn co https://svn.orxonox.net/game/code/branches/tutorial2 tutorial
- Prepare to build:
mkdir tutorial/build cd tutorial/build cmake-2.6.4 ..
- 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 Quickstart button.
cd ~/orxonox/tutorial/build ./run
Before you start coding
Before you start coding there's one page? which is extremely useful for the following tasks. You might want to have a look at it.
The AutonomousDrone
Note: Do not just copy & paste! Most commands / codelines need to be edited.
Otherwise you'll get tons of compiler errors. ;)We created for you the skeleton of an autonomous drone. You can find the code in the files src/orxonox/worldentities/AutonomousDrone.{cc|h} and src/orxonox/controllers/AutonomousDroneController.{cc|h}.
- Open the file AutonomousDrone.cc and have a look at the code.
- In order to be able to create an AutonomousDrone 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 (global, inside the namespace).
CreateFactory(ClassX)
- Make sure that 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 two variables auxiliaryThrust_ and rotationThrust_. As you can see, the XMLPort function for the variable primaryThurst_ has already been specified.
XMLPortParam(Classname, "xml-attribute-name (i.e. variablename)", setFunction, getFunction, xmlelement, mode)
Note: You need to add set- and get-functions for auxiliaryThrust_ and rotationThrust_ inside the AutonomousDrone.h file (have a look at {get/set}PrimaryThrust). - Now you need to add the AutonomousDrone to the build system. Open the file src/orxonox/worldentities/CMakeLists.txt and add AutonomousDrone.cc to the ORXONOX_SRC_FILES. This makes cmake consider the AutonomousDrone.cc file for further builds.
That's it for the AutonomousDrone class.
The AutonomousDroneController
Now you will finish the AutonomousDroneController which gets called each tick and steers the drone.
- Open the file AutonomousDroneController.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)
- repeat step 5 (CMakeLists) of the AutonomousDrone for the AutonomousDroneController.
The XML Part
Now that you finished the classes you can recompile the project. Afterwards open the level file:
- Open tutorial/data/levels/tutorial.oxw.
- We want to add a drone to the level now, so put in an entry for it (below the comment that tells you to do so). 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 AutonomousDrone/4. (Have a look at data/levels/templates/spaceship_assff.oxt 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 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). - 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
Note: The Drone definition should now look like this:<AutonomousDrone primaryThrust="<...>" <...> mass=50 linearDamping=0.9 angularDamping=0.7>
Have a look at your AutonomousDrone
- 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:
- Make sure you have a recent version of the branch:
~/orxonox/tutorial$ svn up
- In order to avoid conflicts copy your file (AutonomousDroneController.cc):
~/orxonox/tutorial$ svn cp src/orxonox/objects/controllers/AutonomousDroneController.cc src/orxonox/objects/controllers/AutonomousDroneController_myUserName.cc
- Make sure you don't commit any changes of the original file, so revert your local changes on it:
~/orxonox/tutorial$ svn revert src/orxonox/objects/controllers/AutonomousDroneController.cc
- Now commit:
~/orxonox/tutorial$ svn ci -m "This is my version of the AutonomousDrone steering function" src/orxonox/controllers/AutonomousDroneController_myUserName.cc