Download coen-2003-project-22..
Transcript
double positionX = myPosition.getX();
double positionY = myPosition.getY();
for(int i = 0; i < numRobots; i++)
{
if(i != (formationPosition - 1))
{
// The global position of the formation
coordinate position = myFormation.getPosition(i);
int oldX = position.getX();
int oldY = position.getY();
// Adjust to local positioning by subtracting the
current bot's position
double newX = oldX - positionX;
double newY = oldY - positionY;
// Put into rotaional (angle) coordinates
double otherRobot = ArMath::atan2(newY, newX);
if(!(((otherRobot - myRobot->getRobotRadius()) <
(angle - 5)) || ((otherRobot + myRobot->getRobotRadius()) > (angle +
5))))
{
return true;
break;
}
}
}
return false;
}
// Absolute value
double ActionAvoidObstacle::abs(double value)
{
if(value < 0)
return -value;
else
return value;
}
// stop avoiding when acheived goal
void ActionAvoidObstacle::goalDone()
{
obstacles.reset();
goal = true;
}
// start avoiding when there is a new goal
void ActionAvoidObstacle::newGoal()
{
goal = false;
}
/*
Definition for the BuildObstacleMap class
*/
68