Page 59 - Designing Autonomous Mobile Robots : Inside the Mindo f an Intellegent Machine
P. 59
Chapter 3
Mathematical functions
Generally you will need only the basic mathematic functions for the techniques
described later. These include signed addition, subtraction, multiplication, division,
squares, and square roots. Note that whatever variable types you choose, interim
calculations may overrun the type limits. Routines must therefore be able to handle
this internally without returning errors.
Geometric and vector functions
In the coming chapters we will discuss various processes in terms of adding vectors
to each other and of converting vectors to Cartesian coordinates and vice-versa. For
clarity and brevity, the mathematical details of how this is done will not be included
in the discussions. The library must support this capability. For many indoor applica-
tions, a two-dimensional frame of reference is completely adequate, but for outdoor
systems the library must include the Z axis in all vector functions. At a minimum,
the library must allow support for the following very basic functions:
■ Add one or more vectors together and return a single vector.
■ Add one or more vectors to a coordinate and return the resulting coordinate.
■ Calculate the vector between two coordinates.
■ Calculate the included angle between vectors with the same base.
■ Calculate the angular sum between vectors with the same base.
If integers are to be used, then all functions should take rounding into consideration
to achieve maximum accuracy. If this is not done, a phenomenon known as digital
integration can occur, which can cause significant error in long-term results.
Once a basic library is produced, it can be supplemented as required. Before I code
anything in a routine, I find it useful to include a paragraph or so of comments
defining what the routine is to do, what variables it uses, what units they are in, and
anything else that a user might need to know about it. These comments are useful
both in structuring the routine and in later maintaining and using it.
42

