// Drive during race. void Driver::drive(tSituation *s) { memset(&car->ctrl, 0, sizeof(tCarCtrl)); update(s); //pit->setPitstop(true); if (isStuck()) { car->_steerCmd = -mycardata->getCarAngle() / car->_steerLock; car->_gearCmd = -1; // Reverse gear. car->_accelCmd = 1.0f; // 100% accelerator pedal. car->_brakeCmd = 0.0f; // No brakes. car->_clutchCmd = 0.0f; // Full clutch (gearbox connected with engine). } else { car->_steerCmd = filterSColl(getSteer()); car->_gearCmd = getGear(); car->_brakeCmd = filterABS(filterBrakeSpeed(filterBColl(filterBPit(getBrake())))); if (car->_brakeCmd == 0.0f) { car->_accelCmd = filterTCL(filterTrk(filterOverlap(getAccel()))); } else { car->_accelCmd = 0.0f; } car->_clutchCmd = getClutch(); } }
/* Drive during race. */ static void drive(int index, tCarElt* car, tSituation *s) { float angle; const float SC = 1.0; // memset((void *)&car->ctrl, 0, sizeof(tCarCtrl)); memset(&car->ctrl, 0, sizeof(tCarCtrl)); if (isStuck(car)) { angle = -RtTrackSideTgAngleL(&(car->_trkPos)) + car->_yaw; NORM_PI_PI(angle); // put the angle back in the range from -PI to PI car->ctrl.steer = angle / car->_steerLock; car->ctrl.gear = -1; // reverse gear car->ctrl.accelCmd = 0.3; // 30% accelerator pedal car->ctrl.brakeCmd = 0.0; // no brakes } else { angle = RtTrackSideTgAngleL(&(car->_trkPos)) - car->_yaw; NORM_PI_PI(angle); // put the angle back in the range from -PI to PI angle -= SC*car->_trkPos.toMiddle/car->_trkPos.seg->width; car->ctrl.steer = angle / car->_steerLock; car->ctrl.gear = 1; // first gear car->ctrl.accelCmd = 0.3; // 30% accelerator pedal car->ctrl.brakeCmd = 0.0; // no brakes } }
/** Determine whether AI is stuck, by checking if it stays on the same node for * a long period of time (see \ref m_on_node), or \ref isStuck() is true. * \param dt Time step size. * \return True if AI is stuck */ void ArenaAI::checkIfStuck(const float dt) { if (m_is_stuck) return; if (m_kart->getKartAnimation() || isWaiting()) { m_on_node.clear(); m_time_since_driving = 0.0f; } m_on_node.insert(getCurrentNode()); m_time_since_driving += dt; if ((m_time_since_driving >= (m_cur_difficulty == RaceManager::DIFFICULTY_EASY ? 2.0f : 1.5f) && m_on_node.size() < 2 && !m_is_uturn && fabsf(m_kart->getSpeed()) < 3.0f) || isStuck() == true) { // AI is stuck, reset now and try to get unstuck at next frame m_on_node.clear(); m_time_since_driving = 0.0f; AIBaseController::reset(); m_is_stuck = true; } else if (m_time_since_driving >= (m_cur_difficulty == RaceManager::DIFFICULTY_EASY ? 2.0f : 1.5f)) { m_on_node.clear(); // Reset for any correct movement m_time_since_driving = 0.0f; } } // checkIfStuck
//----------------------------------------------------------------------------- void ArenaAI::checkIfStuck(const float dt) { if (m_is_stuck) return; if (m_kart->getKartAnimation() || isWaiting()) { m_on_node.clear(); m_time_since_driving = 0.0f; } m_on_node.insert(getCurrentNode()); m_time_since_driving += dt; if ((m_time_since_driving >= (m_cur_difficulty == RaceManager::DIFFICULTY_EASY ? 2.0f : 1.5f) && m_on_node.size() < 2 && !m_is_uturn && fabsf(m_kart->getSpeed()) < 3.0f) || isStuck() == true) { // Check whether a kart stay on the same node for a period of time // Or crashed 3 times m_on_node.clear(); m_time_since_driving = 0.0f; AIBaseController::reset(); m_is_stuck = true; } else if (m_time_since_driving >= (m_cur_difficulty == RaceManager::DIFFICULTY_EASY ? 2.0f : 1.5f)) { m_on_node.clear(); // Reset for any correct movement m_time_since_driving = 0.0f; } } // checkIfStuck
void PhysicObject::destuck() { if(isStuck()) { // If we are stuck in a non void block v_position.y = (preal)world()->altitude(v_position.x, v_position.z) + 0.01; v_velocity.null(); v_acceleration.null(); //ldebug(Channel_Physic, "destucked : set at " + QString::number(v_position.y)); } }
//------------------------------ process -------------------------------------- //----------------------------------------------------------------------------- int GoalSeekToPosition::process() { //if status is INACTIVE, call activate() activateIfInactive(); //test to see if the bot has become stuck if (isStuck()) { _status = FAILED; } //test to see if the bot has reached the waypoint. If so terminate the goal else { if (_owner->isAtPosition(_position)) { _status = COMPLETED; } } return _status; }
//------------------------------ Process -------------------------------------- //----------------------------------------------------------------------------- int Goal_TraverseEdge::Process() { //if status is inactive, call Activate() ActivateIfInactive(); //if the bot has become stuck return failure if (isStuck()) { m_iStatus = failed; } //if the bot has reached the end of the edge return completed else { if (m_pOwner->isAtPosition(m_Edge.Destination())) { m_iStatus = completed; } } return m_iStatus; }
/* Drive during race. */ void Driver::drive(tSituation *s) { memset(&car->ctrl, 0, sizeof(tCarCtrl)); update(s); if (isStuck()) { car->ctrl.steer = -angle / car->_steerLock; car->ctrl.gear = -1; // reverse gear car->ctrl.accelCmd = 0.5; // 50% accelerator pedal car->ctrl.brakeCmd = 0.0; // no brakes } else { car->ctrl.steer = filterSColl(getSteer()); car->ctrl.gear = getGear(); car->ctrl.brakeCmd = filterABS(filterBrakeSpeed(filterBColl(filterBPit(getBrake())))); if (car->ctrl.brakeCmd == 0.0) { car->ctrl.accelCmd = filterTCL(filterTrk(getAccel())); } else { car->ctrl.accelCmd = 0.0; } } }
//------------------------------ Process -------------------------------------- //----------------------------------------------------------------------------- int Goal_SeekToPosition::Process() { // std::cout << "Goal_SeekToPosition::Process" << std::endl; // std::cout << " ++ "; //if status is inactive, call Activate() ActivateIfInactive(); // Vector2D Estoy = m_pOwner->Pos(); // Vector2D Voy = m_vPosition; // std::cout << "Estoy (" << Estoy.x << "," << Estoy.y << ") Voy (" << Voy.x // << "," << Voy.y << ")" << std::endl; //test to see if the bot has become stuck if ( isStuck() ) { m_iStatus = failed; } //test to see if the bot has reached the waypoint. If so terminate the goal else { if ( m_pOwner->isAtPosition( m_vPosition ) ) { m_iStatus = completed; } } return m_iStatus; }
static void drive(int index, tCarElt* car, tSituation *s) { memset(&car->ctrl, 0, sizeof(tCarCtrl)); if (isStuck(car)) { float angle = -RtTrackSideTgAngleL(&(car->_trkPos)) + car->_yaw; NORM_PI_PI(angle); // put the angle back in the range from -PI to PI car->ctrl.steer = angle / car->_steerLock; car->ctrl.gear = -1; // reverse gear car->ctrl.accelCmd = 0.3; // 30% accelerator pedal car->ctrl.brakeCmd = 0.0; // no brakes } else { float angle; const float SC = 1.0; angle = RtTrackSideTgAngleL(&(car->_trkPos)) - car->_yaw; NORM_PI_PI(angle); // put the angle back in the range from -PI to PI angle -= SC*(car->_trkPos.toMiddle+keepLR)/car->_trkPos.seg->width; // set up the values to return car->ctrl.steer = angle / car->_steerLock; car->ctrl.gear = getGear(car); if (car->_speed_x>desired_speed) { car->ctrl.brakeCmd=0.5; car->ctrl.accelCmd=0.0; } else if (car->_speed_x<desired_speed) { car->ctrl.accelCmd=0.5; car->ctrl.brakeCmd=0.0; } } }
/* Drive during race. */ void Driver::drive(tCarElt* car, tSituation *s) { update(car, s); isStuck(car) ? unstuck(car) : followcenter(car); }