<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Hello!<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">After setting up my new server, I noticed several of my robots camped off in a corner of the galaxy instead of fighting each other and I went on crawl through the robot code to figure out why.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">According to their ‘dstate’ debug output, they usually--not always, but that is a different story--thought they were doing something--engaging an enemy, protecting a planet, etc--while in fact they were turning in circles in the upper-right
most corner of KLI space.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">While not a complete answer to robot strangeness, I think one of the culprits is something wrong with the get_course()/get_acourse() functions in robotd/util.c<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">get_course does this to calculate the course:<br>
<br>
<o:p></o:p></p>
<p class="MsoNormal" style="text-indent:.5in">(unsigned char)(atan2((double) (x - me->p_x), (double) (me->p_y - y)) / 3.141592 * 128.);<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I am fairly certain per-C99 that the result of casting a negative floating point to any unsigned type is undefined, so exactly what happens may vary by architecture and compiler. On my ARM RaspberryPI compiling with gcc, the result is
always a value of 0.<o:p></o:p></p>
<p class="MsoNormal"><o:p></o:p></p>
<p class="MsoNormal">I separated the value of the calculation before and after the cast and added some logging to confirm:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Courier New"">Engaging: Galla get_intercept_course : x: 6735, y: 59554<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Courier New"">get_course (UNCORRECTED): ret = -102.354382 ,
<b>ret_crs = 0</b><o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I am not certain how the course system works, but guessing from the fact that it needs to fit in an unsigned char, I am thinking that 127 + the absolute value would be a good guess like this updated log output:<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"><br>
<span style="font-family:"Courier New"">get_course (CORRECTED): ret = -102.354382 ,
<b>ret_crs = 229</b><o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">After making that change, my robots still do plenty of other strange things now and again, but at least they don’t seem to be stuck in the corner of the galaxy spinning in circles.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I have two questions:<br>
<br>
(1) Does all that sound correct?<br>
<br>
(2) How is the unsigned char-based course system expected to work? 360 degrees carved into 255 slices? Or Something else?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">My changes are not in a state to check in, but if this sounds reasonable, I will polish them up.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Cheers,<o:p></o:p></p>
<p class="MsoNormal">Thomas Lackey<o:p></o:p></p>
</div>
</body>
</html>