204 lines
8.9 KiB
HTML
204 lines
8.9 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<!--
|
|
copyright : (C) 2003-2004 Bernhard Wymann
|
|
email : berniw@bluewin.ch
|
|
version : $Id$
|
|
|
|
Permission is granted to copy, distribute and/or modify this document
|
|
under the terms of the GNU Free Documentation License, Version 1.2
|
|
or any later version published by the Free Software Foundation;
|
|
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
|
|
Texts. A copy of the license is included in the section entitled "GNU
|
|
Free Documentation License".
|
|
|
|
-->
|
|
<head>
|
|
<title>Define Multiple Robots</title>
|
|
<link rel="stylesheet" type="text/css" href="../../../css/format.css"/>
|
|
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"/>
|
|
<meta name="description" content="how to implement multiple robots"/>
|
|
<meta name="author" content="Bernhard Wymann"/>
|
|
<meta name="keywords" content="torcs, berniw, bernhard wymann, robot, multiple"/>
|
|
<script src="../../../js/utilities.js" type="text/javascript"></script>
|
|
</head>
|
|
|
|
<body bgcolor="#ffffff">
|
|
<table class="maincontent">
|
|
<tr>
|
|
<td class="maincontent">
|
|
|
|
<h1>2.3 Define Multiple Robots</h1>
|
|
|
|
<h3>Overview</h3>
|
|
<p>
|
|
First ask yourself the question, why we want more than one driver in one module? It's because we can share
|
|
the program code and data between the drivers of our module. If we write our driver general enough,
|
|
we can load parameters for the different tracks and cars, so no code difference is necessary.
|
|
</p>
|
|
|
|
<h3>Car Definition</h3>
|
|
<p>
|
|
In chapter 1.1 we had chosen a cg-nascar-fwd as our car. When you edited <span style="color:red;">bt</span>.cpp, you might
|
|
have recognized that in this file is no clue which car we want to use. The information about the
|
|
cars is stored in the <span style="color:red;">bt</span>.xml file. So let's have a look at it.
|
|
</p>
|
|
<p>
|
|
The following three lines just define the name and the structure. You'll not need to change them.
|
|
</p>
|
|
<p><pre class="lbcolor"><params name="<span style="color:red;">bt</span>" type="robotdef">
|
|
<section name="Robots">
|
|
<section name="index"></pre>
|
|
</p>
|
|
<p>
|
|
The next line
|
|
</p>
|
|
<p><pre class="lbcolor"> <section name="1"></pre>
|
|
</p>
|
|
<p>
|
|
defines the index of the driver. Because we can have more than one driver per module,
|
|
each one is uniquely identified by its index. You will receive it e. g. in your</p>
|
|
<p>
|
|
<tt>static void drive(int <span style="color:green;">index</span>, tCarElt* car, tSituation *s)</tt>
|
|
</p>
|
|
<p>
|
|
function from TORCS, so you know for which car you need to drive.
|
|
It has to match with the index you assign to modInfo[i].index in <span style="color:red;">bt</span>.cpp,
|
|
but you will see that later. The next two lines contain the name and description of you driver, they
|
|
have to match with the modInfo[i] entries (don't ask me why it has to be defined here and in the
|
|
<span style="color:red;">bt</span>.cpp).
|
|
</p>
|
|
<p><pre class="lbcolor"> <attstr name="name" val="<span style="color:red;">bt 1</span>"></attstr>
|
|
<attstr name="desc" val=""></attstr></pre>
|
|
</p>
|
|
<p>
|
|
The next three entries are your teams name, your name and the car to use.
|
|
</p>
|
|
<p>
|
|
<p><pre class="lbcolor"> <attstr name="team" val="<span style="color:red;">berniw</span>"></attstr>
|
|
<attstr name="author" val="<span style="color:red;">Bernhard Wymann</span>"></attstr>
|
|
<attstr name="car name" val="cg-nascar-rwd"></attstr></pre>
|
|
</p>
|
|
<p>
|
|
Now you can choose a racing number and define the color of the drivers entry in the leaders board (if you don't
|
|
know how to enable the leaders board during the race, hit F1 for help).
|
|
</p>
|
|
|
|
<p><pre class="lbcolor"> <attnum name="race number" val="<span style="color:red;">61</span>"></attnum>
|
|
<attnum name="red" val="<span style="color:red;">1.0</span>"></attnum>
|
|
<attnum name="green" val="<span style="color:red;">0.0</span>"></attnum>
|
|
<attnum name="blue" val="<span style="color:red;">1.0</span>"></attnum>
|
|
</section>
|
|
</section>
|
|
</section>
|
|
</params></pre>
|
|
</p>
|
|
|
|
<h3>Adding Cars</h3>
|
|
<p>
|
|
We will now add two car entries to the file <span style="color:red;">bt</span>.xml (one module is allowed
|
|
to handle up to ten robots). This will not yet
|
|
work in the simulation, because we need to change also <span style="color:red;">bt</span>.cpp. You can
|
|
simply copy the part between <section name="1"> and </section> two times and change the
|
|
race numbers, the leaders board color if you like, the car you choose and of course the index. To follow
|
|
the tutorial choose indices 0, 1 and 2 and the names "<span style="color:red;">bt</span> 1",
|
|
"<span style="color:red;">bt</span> 2" and "<span style="color:red;">bt</span> 3". If you want other cars do
|
|
</p>
|
|
<p>
|
|
<tt>
|
|
$ ls /usr/local/games/torcs/cars
|
|
</tt>
|
|
</p>
|
|
<p>
|
|
to get a list of the installed cars. The file <span style="color:red;">bt</span>.xml should finally
|
|
look similar to this:
|
|
</p>
|
|
<p><pre class="lcolor"><?xml version="1.0" encoding="UTF-8"?>
|
|
<!--
|
|
file : bt.xml
|
|
created : Thu Dec 12 02:34:31 CET 2002
|
|
copyright : (C) 2002 Bernhard Wymann
|
|
-->
|
|
|
|
<!-- This program is free software; you can redistribute it and/or modify -->
|
|
<!-- it under the terms of the GNU General Public License as published by -->
|
|
<!-- the Free Software Foundation; either version 2 of the License, or -->
|
|
<!-- (at your option) any later version. -->
|
|
|
|
<!DOCTYPE params SYSTEM "../../libs/tgf/params.dtd">
|
|
|
|
<params name="bt" type="robotdef">
|
|
<section name="Robots">
|
|
<section name="index">
|
|
|
|
<section name="0">
|
|
<attstr name="name" val="bt 1"></attstr>
|
|
<attstr name="desc" val=""></attstr>
|
|
<attstr name="team" val="berniw"></attstr>
|
|
<attstr name="author" val="Bernhard Wymann"></attstr>
|
|
<attstr name="car name" val="cg-nascar-rwd"></attstr>
|
|
<attnum name="race number" val="61"></attnum>
|
|
<attnum name="red" val="1.0"></attnum>
|
|
<attnum name="green" val="0.0"></attnum>
|
|
<attnum name="blue" val="1.0"></attnum>
|
|
</section>
|
|
|
|
<section name="1">
|
|
<attstr name="name" val="bt 2"></attstr>
|
|
<attstr name="desc" val=""></attstr>
|
|
<attstr name="team" val="berniw"></attstr>
|
|
<attstr name="author" val="Bernhard Wymann"></attstr>
|
|
<attstr name="car name" val="xj-220"></attstr>
|
|
<attnum name="race number" val="62"></attnum>
|
|
<attnum name="red" val="1.0"></attnum>
|
|
<attnum name="green" val="0.0"></attnum>
|
|
<attnum name="blue" val="1.0"></attnum>
|
|
</section>
|
|
|
|
<section name="2">
|
|
<attstr name="name" val="bt 3"></attstr>
|
|
<attstr name="desc" val=""></attstr>
|
|
<attstr name="team" val="berniw"></attstr>
|
|
<attstr name="author" val="Bernhard Wymann"></attstr>
|
|
<attstr name="car name" val="155-DTM"></attstr>
|
|
<attnum name="race number" val="63"></attnum>
|
|
<attnum name="red" val="1.0"></attnum>
|
|
<attnum name="green" val="0.0"></attnum>
|
|
<attnum name="blue" val="1.0"></attnum>
|
|
</section>
|
|
|
|
</section>
|
|
</section>
|
|
</params></pre>
|
|
</p>
|
|
<h3>Summary</h3>
|
|
<ul style="list-style-type:disk; color:black;">
|
|
<li>You know how to define cars in <span style="color:red;">bt</span>.xml.</li>
|
|
<li>You know you can define up to ten cars.</li>
|
|
<li>To follow the tutorial you have chosen the indices 0, 1 and 2.</li>
|
|
</ul>
|
|
|
|
<br/>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<table class="navigation_foot">
|
|
<tr>
|
|
<td class="navigation_foot">
|
|
<a href="./comments.html">
|
|
<p style="text-align:left;">Back</p>
|
|
</a>
|
|
</td>
|
|
<td class="navigation_foot">
|
|
<a href="./multiple2.html">
|
|
<p style="text-align:right;">Now change the code.</p>
|
|
</a>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
|
|
</body>
|
|
</html>
|