Changes between Version 21 and Version 22 of pps/tutorial
- Timestamp:
- Apr 9, 2011, 8:51:22 PM (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
pps/tutorial
v21 v22 41 41 Our goal is to create a drone in Orxonox that, that does some kind of autonomous flying. 42 42 In Orxonox we try our best to separate different kinds of functionality. You will see, that this is also the case here. 43 In the case of the drone we want to create we separate the drone itself (called AutonomousDrone) from the entity that controls the drone (called the AutonomousDroneController) and the thing that gives shape and texture to our drone (basically that is the model). Or put more crudely, the AutonomousDrone is the physical entity, the AutonomousDroneController is its intelligence and the model is it's visual representation. This is done for several reasons, the most important being, that with this kind of separation we can have multiple controllers for just one drone, we could also have one controller for multiple types of flying objects. That makes your code more generic and leads to cleaner code, less dependencies and also less code.43 In the case of the drone, we want to create, we separate the drone itself (called AutonomousDrone) from the entity that controls the drone (called the AutonomousDroneController) and the thing that gives shape and texture to our drone (basically that is the model). Or put more crudely, the AutonomousDrone is the physical entity, the AutonomousDroneController is its intelligence and the model is it's visual representation. This is done for several reasons, the most important being, that with this kind of separation we can have multiple controllers for just one drone, we could also have one controller for multiple types of flying objects. And the behavior of our drone is independent of how it looks like. That makes your code more generic and leads to cleaner code, less dependencies and also less code in general. 44 44 45 45 == The AutonomousDrone == … … 48 48 {{{ 49 49 #!html 50 <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. ;)50 <p style="text-align: left; color: red">Note: Do not just copy & paste! Most commands / codelines need to be edited. But that doesn't mean you shouldn't copy & paste, but you should stink about whether what you paste should be modified and how.</p> 51 51 }}} 52 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}''. 52 Otherwise you'll get tons of compiler errors. ;) 53 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}'' in the trunk folder that you checked out from our repository. 53 54 54 55 1. Open the file ''AutonomousDrone.cc'' and have a look at the code (the file can be found in ''src/orxonox/worldentities/''). … … 57 58 CreateFactory(ClassX); 58 59 }}} 60 Note: You have to replace ''ClassX'' with the appropriate class. 59 61 3. Make sure that each drone object gets registered to the core by adding a call of ''RegisterObject(Classname)'' inside the constructor. 60 62 {{{ 61 63 RegisterObject(ClassX); 62 64 }}} 63 4. Now go to the function called ''XMLPort'' 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. Now add the calls for the other two variables accordingly, you can compare your function calls to the call for ''primaryThrust_'' to get a feel for, what you have been doing could be correct or not. 65 4. Now go to the function called ''XMLPort''. ''XMLPort'' allows you to specify how your class can be instantiated (i.e. how an object can be created) purely through XML. This is important when we want to create levels, which in Orxonox are specified in XML files. 66 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. Now add the calls for the other two variables accordingly, you can compare your function calls to the call for ''primaryThrust_'' to get a feel for, whether what you have been doing could be correct or not. 64 67 {{{ 65 68 XMLPortParam(Classname, "xml-attribute-name (i.e. variablename)", setFunction, getFunction, xmlelement, mode) 66 69 }}} 67 '''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).'''70 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). 68 71 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. 69 72 70 73 That's it for the AutonomousDrone class. 71 74 72 If you have been having problems, consider the following suggestions, that might help you resolve them.75 If you have been having '''problems''', consider the following suggestions, that might help you resolve them. 73 76 * Is the classname that you specified for ''CreateFactory(Classname)'' and ''RegisterObject(Classname)'' correct? If it is either ''Classname'', ''ClassX'' or ''ClassXY'', then it is incorrect, try to think about what it should be. If you can't find the solution ask one of the assistants. 74 77 * Have you created 2 set-functions and 2 get-functions for the two variables ''auxiliaryThrust_'' and ''rotationThrust_''?