summaryrefslogtreecommitdiffstats
path: root/source/Concept/Framework/modules/logic
diff options
context:
space:
mode:
authorsicarius <devnull@localhost>2007-02-26 22:25:01 +0100
committersicarius <devnull@localhost>2007-02-26 22:25:01 +0100
commitf61eb900879fe941460a284ff9e4681b0958b944 (patch)
treee32e6e091b0d025e071f3eab1dbf52c04d107d1d /source/Concept/Framework/modules/logic
parent343397ecf6e8ba9ca94fc61e27c241139eff120b (diff)
downloadrc2007-soccer-f61eb900879fe941460a284ff9e4681b0958b944.tar
rc2007-soccer-f61eb900879fe941460a284ff9e4681b0958b944.zip
SoccerTeam, Stuff from Magdeburg
Diffstat (limited to 'source/Concept/Framework/modules/logic')
-rwxr-xr-xsource/Concept/Framework/modules/logic/logic.c257
-rwxr-xr-xsource/Concept/Framework/modules/logic/logic.h23
2 files changed, 265 insertions, 15 deletions
diff --git a/source/Concept/Framework/modules/logic/logic.c b/source/Concept/Framework/modules/logic/logic.c
index f698495..239e426 100755
--- a/source/Concept/Framework/modules/logic/logic.c
+++ b/source/Concept/Framework/modules/logic/logic.c
@@ -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);
+
+ if(!this->HasBall() && ourBallTracker->HasBall())
+ {
+ this->hasBall = true;
+ this->OnBallOwned();
+ }
+ else if(this->HasBall() && !ourBallTracker->HasBall())
+ {
+ this->hasBall = false;
+ this->OnBallLost();
+ }
- // 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)) {
+ 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
+ {
+ UpdateAttackerMovement();
+ }
+ }
+
+ 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,200);
+ ourNavigator->RotateTo(315, DEFAULT_ROTATION_SPEED);
}
- else if(status == STATUS_KEEPER_TURN_RIGHT && !ourNavigator->IsMoving()) {
+ else
+ {
status = STATUS_KEEPER_TURN_LEFT;
- ourNavigator->RotateTo(45, 200);
+ ourNavigator->RotateTo(45, DEFAULT_ROTATION_SPEED);
}
}
- else { // is Player?
-
+}
+
+//-----------------------------------------------------------------------------
+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);
+ }
}
}
diff --git a/source/Concept/Framework/modules/logic/logic.h b/source/Concept/Framework/modules/logic/logic.h
index ad8bad7..031e0b6 100755
--- a/source/Concept/Framework/modules/logic/logic.h
+++ b/source/Concept/Framework/modules/logic/logic.h
@@ -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