SoccerTeam, Stuff from Magdeburg

This commit is contained in:
sicarius 2007-02-26 21:25:01 +00:00
parent 343397ecf6
commit f61eb90087
17 changed files with 666 additions and 122 deletions

View file

@ -3,16 +3,51 @@
//-----------------------------------------------------------------------------
void Logic::OnBallOwned()
{
bool wasKeeper = this->IsKeeper();
this->SetKeeper(false);
if(!WIRELESS_ACTIVE)
{
Aktuator* ourAktuator = parent->GetModule<Aktuator>(IO_AKTUATOR_MAIN);
ourAktuator->Kick();
this->SetKeeper(wasKeeper);
}
}
//-----------------------------------------------------------------------------
void Logic::OnBallLost()
{
Wireless* ourWireless = parent->GetModule<Wireless>(IO_WIRELESS_MAIN);
//ourWireless->Send(WIRELESS_CODE);
//ourWireless->Send();
}
//-----------------------------------------------------------------------------
void Logic::OnBecomeKeeper()
{
Position_Tracker* ourPositionTracker = parent->GetModule<Position_Tracker>(IO_POSITION_TRACKER_MAIN);
Navigator* ourNavigator = parent->GetModule<Navigator>(IO_NAVIGATOR_MAIN);
if(distance2d(HOME_LOC_X, HOME_LOC_Y, ourPositionTracker->GetPositionX(), ourPositionTracker->GetPositionY()) > DISTANCE_TOLERANCE)
{
status = STATUS_KEEPER_RETURN_HOME;
ourNavigator->DriveTo(HOME_LOC_X, HOME_LOC_Y, ourPositionTracker->GetOrientation(), DEFAULT_SPEED, 0);
}
else
{
UpdateKeeperMovement();
}
}
//-----------------------------------------------------------------------------
void Logic::OnBecomeAttacker()
{
Navigator* ourNavigator = parent->GetModule<Navigator>(IO_NAVIGATOR_MAIN);
ourNavigator->Stop();
UpdateAttackerMovement();
}
//-----------------------------------------------------------------------------
@ -20,21 +55,217 @@ void Logic::Update()
{
// We want to use a navigator
Navigator* ourNavigator = parent->GetModule<Navigator>(IO_NAVIGATOR_MAIN);
Ball_Tracker* ourBallTracker = parent->GetModule<Ball_Tracker>(IO_BALL_TRACKER_MAIN);
Display* ourDisplay = parent->GetModule<Display>(IO_DISPLAY_MAIN);
Position_Tracker* ourPositionTracker = parent->GetModule<Position_Tracker>(IO_POSITION_TRACKER_MAIN);
Obstacle_Tracker* ourObstacleTracker = parent->GetModule<Obstacle_Tracker>(IO_OBSTACLE_TRACKER_MAIN);
// is Keeper?
if(isKeeper) {
// turn around al little bit...
if((status == STATUS_KEEPER_TURN_LEFT && !ourNavigator->IsMoving()) ||
(status != STATUS_KEEPER_TURN_LEFT && status != STATUS_KEEPER_TURN_RIGHT)) {
status = STATUS_KEEPER_TURN_RIGHT;
ourNavigator->RotateTo(315,200);
if(!this->HasBall() && ourBallTracker->HasBall())
{
this->hasBall = true;
this->OnBallOwned();
}
else if(this->HasBall() && !ourBallTracker->HasBall())
{
this->hasBall = false;
this->OnBallLost();
}
switch(status)
{
case STATUS_ATTACKER_SEARCHING_AT_HOME:
case STATUS_ATTACKER_SEARCHING_AT_ENEMY:
if(ourBallTracker->KnowsBallDirection())
{
ourNavigator->Stop();
}
break;
case STATUS_KEEPER_HUNT_BALL:
if(ourBallTracker->KnowsBallDirection())
{
ourNavigator->Drive(ourBallTracker->GetBallDirection(), EMPTY_FLOAT, DEFAULT_SPEED, 0);
}
else
{
ourNavigator->Stop();
}
break;
}
if(!ourNavigator->IsMoving())
{
if(this->IsKeeper())
{
UpdateKeeperMovement();
}
else if(status == STATUS_KEEPER_TURN_RIGHT && !ourNavigator->IsMoving()) {
status = STATUS_KEEPER_TURN_LEFT;
ourNavigator->RotateTo(45, 200);
else
{
UpdateAttackerMovement();
}
}
else { // is Player?
if(ourNavigator->IsMoving())
{
if(ourObstacleTracker->IsObstacleOnPath())
{
avoidsObstacle = true;
for(uint8 i = 0; i < 5; i++)
{
if(ourObstacleTracker->IsObstacleOnPath(easyAngle(ourNavigator->GetDirection() - ((i - 2) * PI / 4.0f))))
{
}
ourNavigator->GetDirection();
}
}
}
}
//-----------------------------------------------------------------------------
void Logic::UpdateKeeperMovement()
{
Ball_Tracker* ourBallTracker = parent->GetModule<Ball_Tracker>(IO_BALL_TRACKER_MAIN);
Position_Tracker* ourPositionTracker = parent->GetModule<Position_Tracker>(IO_POSITION_TRACKER_MAIN);
Navigator* ourNavigator = parent->GetModule<Navigator>(IO_NAVIGATOR_MAIN);
if(ourBallTracker->KnowsBallDirection())
{
if(ourBallTracker->GetBallDirection() > KEEPER_LEFT_ANGLE &&
ourBallTracker->GetBallDirection() <= PI)
{
if(distance2d(DEFENCE_L_LOC_X, DEFENCE_L_LOC_Y, ourPositionTracker->GetPositionX(), ourPositionTracker->GetPositionY()) < DISTANCE_TOLERANCE)
{
float angleDifference = fabs(ourBallTracker->GetBallDirection() - ourPositionTracker->GetOrientation());
if(angleDifference > PI)
{
angleDifference = (2 * PI) - angleDifference;
}
if(angleDifference > ORIENTATION_TOLERANCE)
{
status = STATUS_KEEPER_TURN_TO_BALL;
ourNavigator->RotateTo(ourBallTracker->GetBallDirection(), DEFAULT_ROTATION_SPEED);
}
else
{
status = STATUS_KEEPER_HUNT_BALL;
ourNavigator->Drive(ourBallTracker->GetBallDirection(), EMPTY_FLOAT, DEFAULT_SPEED, 0);
}
}
else
{
status = STATUS_KEEPER_DRIVE_TO_DEFEND;
ourNavigator->DriveTo(DEFENCE_L_LOC_X, DEFENCE_L_LOC_Y, EMPTY_FLOAT, DEFAULT_SPEED, 0);
}
}
else if(ourBallTracker->GetBallDirection() < KEEPER_RIGHT_ANGLE &&
ourBallTracker->GetBallDirection() >= PI)
{
if(distance2d(DEFENCE_R_LOC_X, DEFENCE_R_LOC_Y, ourPositionTracker->GetPositionX(), ourPositionTracker->GetPositionY()) < DISTANCE_TOLERANCE)
{
float angleDifference = fabs(ourBallTracker->GetBallDirection() - ourPositionTracker->GetOrientation());
if(angleDifference > PI)
{
angleDifference = (2 * PI) - angleDifference;
}
if(angleDifference > ORIENTATION_TOLERANCE)
{
status = STATUS_KEEPER_TURN_TO_BALL;
ourNavigator->RotateTo(ourBallTracker->GetBallDirection(), DEFAULT_ROTATION_SPEED);
}
else
{
status = STATUS_KEEPER_HUNT_BALL;
ourNavigator->Drive(ourBallTracker->GetBallDirection(), EMPTY_FLOAT, DEFAULT_SPEED, 0);
}
}
else
{
status = STATUS_KEEPER_DRIVE_TO_DEFEND;
ourNavigator->DriveTo(DEFENCE_R_LOC_X, DEFENCE_R_LOC_Y, EMPTY_FLOAT, DEFAULT_SPEED, 0);
}
}
else
{
if(distance2d(HOME_LOC_X, HOME_LOC_Y, ourPositionTracker->GetPositionX(), ourPositionTracker->GetPositionY()) < DISTANCE_TOLERANCE)
{
float angleDifference = fabs(ourBallTracker->GetBallDirection() - ourPositionTracker->GetOrientation());
if(angleDifference > PI)
{
angleDifference = (2 * PI) - angleDifference;
}
if(angleDifference > ORIENTATION_TOLERANCE)
{
status = STATUS_KEEPER_TURN_TO_BALL;
ourNavigator->RotateTo(ourBallTracker->GetBallDirection(), DEFAULT_ROTATION_SPEED);
}
else
{
status = STATUS_KEEPER_HUNT_BALL;
ourNavigator->Drive(ourBallTracker->GetBallDirection(), EMPTY_FLOAT, DEFAULT_SPEED, 0);
}
}
else
{
status = STATUS_KEEPER_DRIVE_TO_DEFEND;
ourNavigator->DriveTo(HOME_LOC_X, HOME_LOC_Y, EMPTY_FLOAT, DEFAULT_SPEED, 0);
}
}
}
else
{
if(status == STATUS_KEEPER_TURN_LEFT)
{
status = STATUS_KEEPER_TURN_RIGHT;
ourNavigator->RotateTo(315, DEFAULT_ROTATION_SPEED);
}
else
{
status = STATUS_KEEPER_TURN_LEFT;
ourNavigator->RotateTo(45, DEFAULT_ROTATION_SPEED);
}
}
}
//-----------------------------------------------------------------------------
void Logic::UpdateAttackerMovement()
{
Ball_Tracker* ourBallTracker = parent->GetModule<Ball_Tracker>(IO_BALL_TRACKER_MAIN);
Position_Tracker* ourPositionTracker = parent->GetModule<Position_Tracker>(IO_POSITION_TRACKER_MAIN);
Navigator* ourNavigator = parent->GetModule<Navigator>(IO_NAVIGATOR_MAIN);
if(ourBallTracker->KnowsBallDirection())
{
float angleDifference = fabs(ourBallTracker->GetBallDirection() - ourPositionTracker->GetOrientation());
if(angleDifference > PI)
{
angleDifference = (2 * PI) - angleDifference;
}
if(angleDifference > ORIENTATION_TOLERANCE)
{
status = STATUS_ATTACKER_TURN_TO_BALL;
ourNavigator->RotateTo(ourBallTracker->GetBallDirection(), DEFAULT_ROTATION_SPEED);
}
else
{
status = STATUS_ATTACKER_DRIVE_TO_BALL;
ourNavigator->Drive(ourBallTracker->GetBallDirection(), EMPTY_FLOAT, DEFAULT_SPEED, 0);
}
}
else
{
if(ourPositionTracker->GetPositionX() > 0)
{
status = STATUS_ATTACKER_SEARCHING_AT_HOME;
ourNavigator->DriveTo(HOME_LOC_X, HOME_LOC_Y, EMPTY_FLOAT, DEFAULT_SPEED, 0);
}
else
{
status = STATUS_ATTACKER_SEARCHING_AT_ENEMY;
ourNavigator->DriveTo(ENEMY_LOC_X, ENEMY_LOC_Y, EMPTY_FLOAT, DEFAULT_SPEED, 0);
}
}
}

View file

@ -12,6 +12,8 @@ public:
this->moduleId = 0;
this->isKeeper = false;
this->status = 0;
this->hasBall = false;
this->avoidsObstacle = false;
}
Logic(uint32 logicId)
@ -20,16 +22,29 @@ public:
this->moduleId = logicId;
this->isKeeper = false;
this->status = 0;
this->hasBall = false;
this->avoidsObstacle = false;
}
protected:
bool isKeeper;
uint8 status;
bool hasBall;
bool avoidsObstacle;
enum LogicalStatus
{
STATUS_KEEPER_TURN_RIGHT,
STATUS_KEEPER_TURN_LEFT,
STATUS_KEEPER_RETURN_HOME,
STATUS_KEEPER_HUNT_BALL,
STATUS_KEEPER_TURN_TO_BALL,
STATUS_KEEPER_DRIVE_TO_DEFEND,
STATUS_ATTACKER_TURN_TO_BALL,
STATUS_ATTACKER_DRIVE_TO_BALL,
STATUS_ATTACKER_SEARCHING_AT_HOME,
STATUS_ATTACKER_SEARCHING_AT_ENEMY,
};
void OnBallOwned();
@ -51,7 +66,8 @@ public:
return !isKeeper;
}
void SetKeeper(bool newStatus) {
void SetKeeper(bool newStatus)
{
if(!this->isKeeper && newStatus)
{
this->OnBecomeKeeper();
@ -65,8 +81,11 @@ public:
bool HasBall()
{
//fill me!
return this->hasBall;
}
void UpdateKeeperMovement();
void UpdateAttackerMovement();
};
#endif