Page 146 - Introduction to AI Robotics
P. 146

Programming a single potential field
                               4.4.4  4.4 Potential Fields Methodologies                              129
                                      Potential fields are actually easy to program, especially since the fields are
                                      ego-centric to the robot. The visualization of the entire field may appear
                                      to indicate that the robot and the objects are in a fixed, absolute coordinate
                                      system, but they are not. The robot computes the effect of the potential field,
                                      usually as a straight line, at every update, with no memory of where it was
                                      previously or where the robot has moved. This should become clear through
                                      the following examples.
                                        A primitive potential field is usually represented by a single function. The
                                      vector impacting the robot is computed each update. Consider the case of a
                                      robot with a single range sensor facing forward. The designer has decided
                                      that a repulsive field with a linear drop off is appropriate. The formula is:


                               (4.2)   V direction  =  180
                                                     (
                                                       (D  d)  for  d  = D               <
                                      V magnitude  =     D
                                                         0    for  d                     >                                   D
                                      where D is the maximum range of the field’s effect, or the maximum dis-
                                      tance at which the robot can detect the obstacle. (D isn’t always the detection
                                      range. It can be the range at which the robot should respond to a stimulus.
                                      For example, many sonars can detect obstacles 20 feet away, producing an al-
                                      most infinitesimal response in emergent behavior but requiring the runtime
                                      overhead of a function call. In practice, a roboticist might set a D of 2 meters.)

                                      Notice that the formula produces a result where 0.0   V magnitude    1.0.
                                        Below is a C code fragment that captures the repulsive field.


                                       typedef struct {
                                          double    magnitude;
                                          double direction;
                                       } vector;

                                       vector repulsive(double d, double D)
                                       {
                                          if (d <= D) {
                                            outputVector.direction = -180; //turn around!
                                            outputVector.magnitude = (D-d)/D; //linear dropoff
                                          }
                                          else {
   141   142   143   144   145   146   147   148   149   150   151