www.pudn.com > Product_Submit2004.rar > DudeManager.cc, change:2004-07-01,size:5982b


#include "DudeManager.h" 
#include "DUDES/DudeList.h" 
#include <fstream> 
 
using namespace std; 
 
DudeManager::DudeManager() { 
  currentDude = NULL; 
  currentDudeName_ = NULL; 
} 
void DudeManager::Push() { 
  if (currentDude==NULL) { 
    return; 
  } 
 
//mouthPosition_ = -3.1; // Close the mouth 
  //ledOn_[1] = false; 
  //ledOn_[4] = false; 
   
  #ifdef ERS_7 
  ledOn_[0] = false; // Indicates if I can see the ball (orange on back of head) 
  ledOn2_[6] = false; // Indicates opponents goal (right front green); 
  ledOn2_[12] = false; // Indicates own goal (right front white); 
 
  ledOn2_[7] = false; // Indicates chase veer (left front green); 
  ledOn2_[13] = false;  // Indicates chase ram (left front white); 
  ledOn2_[18] = false; // Indicates chase slap (left front blue); 
  ledOn2_[19] = false; // Indicates chase slap (right front blue); 
  #endif 
       
  wo_ball_ = NULL; 
  wo_sharedBall_ = NULL; 
  wo_self_ = NULL; 
  vo_ball_ = NULL; 
  vo_oppositionGoal_ = NULL; 
  vo_ownGoal_ = NULL; 
  vo_frontLeftBeacon_ = NULL; 
  vo_frontRightBeacon_ = NULL; 
  vo_backLeftBeacon_ = NULL; 
  vo_backRightBeacon_ = NULL; 
  vo_greenPinkBeacon_ = NULL; 
  vo_pinkGreenBeacon_ = NULL; 
  for (int i=0; i<numWorldObjectsBVR_; i++) { 
    if (worldObjectsBVR_[i].object_== WorldObject::WM_OT_SELF) { 
      wo_self_ = &worldObjectsBVR_[i]; 
       //Turn green lights on if heading uncertain (1 light = getting lost ... 2 lights = lost) 
      //if (wo_self_->uncertHeading_ > 0.1) 
       //ledOn_[4] = true; 
      //if (wo_self_->uncertHeading_ > 0.2) 
       //ledOn_[1] = true; 
    } 
    if (worldObjectsBVR_[i].object_== WorldObject::WM_OT_BALL_IND) 
      wo_ball_ = &worldObjectsBVR_[i]; 
    if (worldObjectsBVR_[i].object_== WorldObject::WM_OT_BALL_COOP) 
      wo_sharedBall_ = &worldObjectsBVR_[i]; 
  } 
  for (int i=0; i<numVisionObjects_; i++) { 
    if (visionObjects_[i].type_== VisionObject::OT_BALL) { 
      vo_ball_ = &visionObjects_[i];  
      #ifdef ERS_7 
      //ledOn_[0] = true; // Can See Ball 
      #endif 
    } else if (robotState_.GetTeam() == RobotState::RT_RED) { 
      if (visionObjects_[i].type_ == VisionObject::OT_GOAL_B) { 
        vo_oppositionGoal_ = &visionObjects_[i]; 
        #ifdef ERS_7 
          ledOn2_[6] = true; // See oppGoal 
        #endif 
      } else if (visionObjects_[i].type_ == VisionObject::OT_GOAL_Y) { 
        vo_ownGoal_ = &visionObjects_[i]; 
        #ifdef ERS_7 
          ledOn2_[12] = true; // See ownGoal 
        #endif 
      } else if (visionObjects_[i].type_ == VisionObject::OT_BEACON_PB) { 
        vo_frontRightBeacon_ = &visionObjects_[i]; 
      } else if (visionObjects_[i].type_ == VisionObject::OT_BEACON_BP) { 
        vo_frontLeftBeacon_ = &visionObjects_[i]; 
      } else if (visionObjects_[i].type_ == VisionObject::OT_BEACON_PY) { 
        vo_backRightBeacon_ = &visionObjects_[i]; 
      } else if (visionObjects_[i].type_ == VisionObject::OT_BEACON_YP) { 
        vo_backLeftBeacon_ = &visionObjects_[i]; 
      } 
    } else if (robotState_.GetTeam() == RobotState::RT_BLUE) { 
      if (visionObjects_[i].type_ == VisionObject::OT_GOAL_Y) { 
        vo_oppositionGoal_ = &visionObjects_[i]; 
        #ifdef ERS_7 
          ledOn2_[6] = true; // See oppGoal 
        #endif 
      } else if (visionObjects_[i].type_ == VisionObject::OT_GOAL_B) { 
        vo_ownGoal_ = &visionObjects_[i]; 
        #ifdef ERS_7 
          ledOn2_[12] = true; // See ownGoal 
        #endif 
      } else if (visionObjects_[i].type_ == VisionObject::OT_BEACON_YP) { 
        vo_frontRightBeacon_ = &visionObjects_[i]; 
      } else if (visionObjects_[i].type_ == VisionObject::OT_BEACON_PY) { 
        vo_frontLeftBeacon_ = &visionObjects_[i]; 
      } else if (visionObjects_[i].type_ == VisionObject::OT_BEACON_BP) { 
        vo_backRightBeacon_ = &visionObjects_[i]; 
      } else if (visionObjects_[i].type_ == VisionObject::OT_BEACON_PB) { 
        vo_backLeftBeacon_ = &visionObjects_[i]; 
      } 
    } 
    if (visionObjects_[i].type_ == VisionObject::OT_BEACON_GP) { 
      vo_greenPinkBeacon_ = &visionObjects_[i]; 
    } else if (visionObjects_[i].type_ == VisionObject::OT_BEACON_PG) { 
      vo_pinkGreenBeacon_ = &visionObjects_[i]; 
    } 
  } 
  if (vo_ball_ != NULL) { 
    lastBallHeading_ = vo_ball_->heading_; 
    lastBallDistance_ = vo_ball_->distance_; 
    double headPan = MICRO_TO_DEG(sensorValues_[S_HEAD_PAN]); 
    double headTilt = MICRO_TO_DEG(sensorValues_[S_HEAD_TILT1]+sensorValues_[S_HEAD_TILT2]); 
    //cout << vo_ball_->distance_ << RAD_TO_DEG(vo_ball_->elevation_) << " " << headTilt << " " << RAD_TO_DEG(vo_ball_->heading_) << " " << headPan << endl << flush; 
  } 
  if (aimAtMiddleOfBall_ && vo_ball_ != NULL) { 
    vo_ball_->centreY_ = (int)((vo_ball_->topBlob_->minY + vo_ball_->topBlob_->maxY)/2.0); 
  } 
  aimAtMiddleOfBall_ = false; 
 
  ballPrediction_.ProcessFrame(); 
 
  if (robotState_.GetState() == RobotState::ST_READY) { 
    currentDude->NewGoHomeModel(); 
  } else if (robotState_.GetState() == RobotState::ST_SET)	{ 
    currentDude->NewReadyModel(); 
	}	else if (robotState_.GetState() == RobotState::ST_PLAYING) { 
		currentDude->NewPlayingModel(); 
	} 
 
  emergencyTurnAround_=false; 
} 
void DudeManager::ChangeDude(char* name) { 
  if (currentDude!=NULL) {  
    delete currentDude; 
    delete currentDudeName_; 
  } 
  cout << "*** Loading " << name << " ***" << endl << flush; 
  currentDude = CreateDude(name); 
  currentDudeName_ = new char[20]; 
  memcpy(currentDudeName_, name, strlen(name)+1); 
  //NOTE! Each dude must load its OWN .cfg file 
} 
 
void DudeManager::PrintBehaviourTrace() { 
  if (currentDude==NULL) return; 
  cout << "Dude: " << currentDudeName_ << endl << flush; 
  Trick* currentTrick = currentDude->GetCurrentTrick(); 
  while (currentTrick != NULL) { 
    cout << "  " << currentTrick->GetName() << endl << flush; 
    currentTrick = currentTrick->GetCurrentTrick(); 
  }     
}