14.13 ValidateFieldPos
This is a function which helps to ensure that agents stay on the field :). For example if you issue a gototarget
to go forward, their behaviour might say that they should move off the bounds of the field. In order to fix that this function takes in a desired target VecPosition
and adjusts it based on the bounds of the field. For example if the target X coordinate is -17 we set the target X coordinate to be -13. This is done here : target.setX(((-1*FIELD_X)/2)-0.1);
. You might ask why add to the bounds, this was chosen arbitrarily, perhaps adding or subtracting 1 would be better. A similar process is done for all 4 edges to ensure no agent can exceed the bounds. This function therefore needs to be called to update the target VecPosition
before it gets passed to any of the gototarget or kick functions.
VecPosition NaoBehavior::ValidateFieldPos(VecPosition target){
if(target.getX() <= (-1*FIELD_X)/2){
target.setX((-1*FIELD_X)/2-0.1);
}
else if(target.getX() >= FIELD_X/2){
target.setX(FIELD_X/2 +0.1);
}
if(target.getY() <= (-1*FIELD_Y)/2){
target.setY((-1*FIELD_Y)/2-0.1);
}
else if(target.getY() >= FIELD_Y/2){
target.setY(FIELD_Y/2 +0.1);
}
return target;
}