public override Action Control(ISensorModel sensorModel) { Action action = new Action(); if(sensorModel.GetSpeed() < TargetSpeed) { action.Accelerate = 1; } if(sensorModel.GetAngleToTrackAxis() < 0) { action.Steering = -0.1f; } else { action.Steering = 0.1f; } action.Gear = 1; return action; }
public override Action Control(ISensorModel sensorModel) { // check if car is currently stuck if (Math.Abs(sensorModel.GetAngleToTrackAxis()) > StuckAngle) { // update stuck counter stuck++; } else { // if not stuck reset stuck counter stuck = 0; } // after car is stuck for a while apply recovering policy if (stuck > StuckTime) { /* set gear and sterring command assuming car is * pointing in a direction out of track */ // to bring car parallel to track axis float steer = (float)(-sensorModel.GetAngleToTrackAxis() / SteerLock); int gear = -1; // Gear R // if car is pointing in the correct direction revert gear and steer if (sensorModel.GetAngleToTrackAxis() * sensorModel.GetTrackPosition() > 0) { gear = 1; steer = -steer; } clutch = Clutching(sensorModel, clutch); // build a CarControl variable and return it Action action = new Action(); action.Gear = gear; action.Steering = steer; action.Accelerate = 1.0f; action.Brake = 0; action.Clutch = clutch; return action; } else // car is not stuck { // compute accel/brake command float accelAndBrake = GetAccel(sensorModel); // compute gear int gear = GetGear(sensorModel); // compute steering float steer = GetSteer(sensorModel); // normalize steering if (steer < -1) { steer = -1; } if(steer > 1) { steer = 1; } // set accel and brake from the joint accel/brake command float accel, brake; if(accelAndBrake > 0) { accel = accelAndBrake; brake = 0; } else { accel = 0; // apply ABS to brake brake = FilterAbs(sensorModel, -accelAndBrake); } clutch = Clutching(sensorModel, clutch); // build a CarControl variable and return it Action action = new Action(); action.Gear = gear; action.Steering = steer; action.Accelerate = accel; action.Brake = brake; action.Clutch = clutch; return action; } }
private float GetSteer(ISensorModel model) { // steering angle is compute by correcting the actual car angle w.r.t. to track // axis [sensors.getAngle()] and to adjust car position w.r.t to middle of track [sensors.getTrackPos()*0.5] float targetAngle = (float)(model.GetAngleToTrackAxis() - model.GetTrackPosition() * 0.5f); // at high speed reduce the steering command to avoid loosing the control if (model.GetSpeed() > SteerSensitivityOffset) { return (float)(targetAngle / (SteerLock * (model.GetSpeed() - SteerSensitivityOffset) * WheelSensitivityCoeff)); } else { return (targetAngle) / SteerLock; } }