Changes between Version 13 and Version 14 of pps/tutorial
- Timestamp:
- Sep 13, 2010, 2:42:55 PM (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
pps/tutorial
v13 v14 1 1 = Basic PPS Tutorial = 2 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 [wiki:download#Source ] page and make sure you have all dependencies installed.2 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 [wiki:download#Source download] page and make sure you have all dependencies installed. 3 3 4 4 == Preparations == … … 15 15 3. Now get the latest revision of the tutorial: 16 16 {{{ 17 svn co https://svn.orxonox.net/game/code/branches/tutorial 17 svn co https://svn.orxonox.net/game/code/branches/tutorial2 tutorial 18 18 }}} 19 19 4. Prepare to build: … … 21 21 mkdir tutorial/build 22 22 cd tutorial/build 23 cmake-2.6. 2..23 cmake-2.6.4 .. 24 24 }}} 25 25 5. Now build for the first time (may take some time, further builds will be faster): … … 36 36 37 37 == Before you start coding == 38 Before you start coding there's one [wiki:howto/XMLPort page] which is extremely useful lfor the following tasks. You might want to have a look at it.38 Before you start coding there's one [wiki:howto/XMLPort page] which is extremely useful for the following tasks. You might want to have a look at it. 39 39 40 == The Drone ==40 == The AutonomousDrone == 41 41 {{{ 42 42 #!html 43 43 <p style="text-align: left; color: red">Note: Do not just copy & paste! Most commands / codelines need to be edited.</p> Otherwise you'll get tons of compiler errors ;) 44 44 }}} 45 We created for you the skeleton of an autonomous drone. You can find the code in the files 'src/orxonox/worldentities/ Drone.{cc|h}' and 'src/orxonox/controllers/DroneController.{cc|h}'.45 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}'. 46 46 47 1. open the file Drone.cc and have a look at the code48 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)47 1. Open the file AutonomousDrone.cc and have a look at the code. 48 2. 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 file (global, inside the namespace). 49 49 {{{ 50 50 CreateFactory(ClassX) 51 51 }}} 52 3. make sure the each drone object gets registered to the core by adding a call of RegisterObject(Classname) inside the constructor52 3. Make sure the each drone object gets registered to the core by adding a call of RegisterObject(Classname) inside the constructor 53 53 {{{ 54 54 RegisterObject(ClassXY) 55 55 }}} 56 4. now go to the XMLPort function and add the calls for the three variables primaryThrust_, auxilaryThrust_ and rotationThrust_.56 4. 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. 57 57 {{{ 58 58 XMLPortParam(Classname, "xml-attribute-name (i.e. variablename)", setFunction, getFunction, xmlelement, mode) 59 59 }}} 60 '''Note: You need to add set- and get-functions for auxil aryThrust_ and rotationThrust_ inside theDrone.h file (have a look at {get/set}PrimaryThrust).'''61 5. now you need to add the Drone to the build system. Open the file src/orxonox/worldentities/CMakeLists.txt and add Drone.cc to the ORXONOX_SRC_FILES. This makes cmake consider theDrone.cc file for further builds.60 '''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).''' 61 5. 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. 62 62 63 That's it for the Drone class63 That's it for the AutonomousDrone class. 64 64 65 == The DroneController ==66 Now you will finish the DroneController which gets called each tick and steers the drone.67 1. open the file DroneController.cc and look at it68 2. have a look at the constructor and make sure nothing is missing (think of the core)65 == The AutonomousDroneController == 66 Now you will finish the AutonomousDroneController which gets called each tick and steers the drone. 67 1. Open the file AutonomousDroneController.cc and look at it. 68 2. Have a look at the constructor and make sure nothing is missing (think of the core). 69 69 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: 70 70 {{{ … … 73 73 // many other functions (have a look at src/util/Math.h for details) 74 74 }}} 75 4. repeat step 5 (CMakeLists) of the Drone for theDroneController.75 4. repeat step 5 (CMakeLists) of the AutonomousDrone for the AutonomousDroneController. 76 76 77 77 == The XML Part == 78 78 Now that you finished the classes you can recompile the project. Afterwards open the level file: 79 1. open tutorial/data/levels/tutorial.oxw80 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:79 1. Open tutorial/data/levels/tutorial.oxw 80 2. 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: 81 81 {{{ 82 82 <ClassX variable1="2" string1="blabla" coord1="1,0,0"> 83 83 </ClassX> 84 84 }}} 85 3. now add the appropriate entries for the variables you defined in Drone/4. (Have a look at data/levels/spaceshiptemplates_physics.oxwfor example values)86 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:85 3. 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) 86 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: 87 87 {{{ 88 88 <attached> … … 92 92 this adds a model with the mesh drone.mesh and the defined textures at the position of our drone object. 93 93 94 5. because the physics engine needs a collision shape to work with, we will add the following entry (before </ClassX>):94 5. Because the physics engine needs a collision shape to work with, we will add the following entry (before </ClassX>): 95 95 {{{ 96 96 <collisionShapes> 97 <BoxCollisionShape position="0,0,0" 97 <BoxCollisionShape position="0,0,0" halfExtents="10, 10, 10" /> 98 98 </collisionShapes> 99 99 }}} 100 this will tell the physics engine what dimensions our drone has (in this case its just a cube) 101 6. 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.)100 this will tell the physics engine what dimensions our drone has (in this case its just a cube). 101 6. 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.) 102 102 {{{ 103 103 mass = 50 … … 107 107 Note: The Drone definition should now look like this: 108 108 {{{ 109 < Drone primaryThrust_="<...>" <...> mass=50 linearDamping=0.9 angularDamping=0.7>109 <AutonomousDrone primaryThrust="<...>" <...> mass=50 linearDamping=0.9 angularDamping=0.7> 110 110 }}} 111 111 112 == Have a look at your Drone ==112 == Have a look at your AutonomousDrone == 113 113 - Now recompile the code, start the game again and have a look at how your drone behaves. 114 114 - Don't worry if it does not react to your steering commands as expected. Try to modify some things. 115 - If you want to do some more things you can try to let the drone fly in circles or helixes 116 - Play around a little bit with the linear/angular-Damping parameters 115 - If you want to do some more things you can try to let the drone fly in circles or helixes. 116 - Play around a little bit with the linear/angular-Damping parameters. 117 117 118 118 == Commit your code to the repository == 119 119 We may want to use your steering function later on, so commit it now: 120 1. make sure you have a recent version of the branch120 1. Make sure you have a recent version of the branch 121 121 {{{ 122 122 ~/orxonox/tutorial$ svn up 123 123 }}} 124 2. in order to avoid conflicts copy your file (DroneController.cc)124 2. In order to avoid conflicts copy your file (AutonomousDroneController.cc) 125 125 {{{ 126 ~/orxonox/tutorial$ svn cp src/orxonox/objects/controllers/ DroneController.cc src/orxonox/objects/controllers/DroneController.cc_myUserName126 ~/orxonox/tutorial$ svn cp src/orxonox/objects/controllers/AutonomousDroneController.cc src/orxonox/objects/controllers/AutonomousDroneController_myUserName.cc 127 127 }}} 128 3. make sure you dont commit any changes of the original file, so revert your local changes on it:128 3. Make sure you don't commit any changes of the original file, so revert your local changes on it: 129 129 {{{ 130 ~/orxonox/tutorial$ svn revert src/orxonox/objects/controllers/ DroneController.cc130 ~/orxonox/tutorial$ svn revert src/orxonox/objects/controllers/AutonomousDroneController.cc 131 131 }}} 132 4. now commit132 4. Now commit 133 133 {{{ 134 ~/orxonox/tutorial$ svn ci -m "this is my version of the Drone steering function" src/orxonox/controllers/DroneController.cc_myUserName134 ~/orxonox/tutorial$ svn ci -m "this is my version of the Drone steering function" src/orxonox/controllers/AutonomousDroneController_myUserName.cc 135 135 }}}