本文整理汇总了C++中CarState类的典型用法代码示例。如果您正苦于以下问题:C++ CarState类的具体用法?C++ CarState怎么用?C++ CarState使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CarState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: seemsStuck
bool Stuck::seemsStuck(CarState &cs) {
cs.getSpeedX()<STUCK_SPEED?slowSpeedTicks++:slowSpeedTicks = 0;
if(notStuckAnymore(cs.getTrackPos(), cs.getAngle())){
slowSpeedTicks=0;
}
return (slowSpeedTicks>MAX_SLOW_SPEED_TICKS?1:0);
}
示例2:
float
SimpleDriver::filterABS(CarState &cs,float brake)
{
// convert speed to m/s
float speed = cs.getSpeedX() / 3.6;
// when spedd lower than min speed for abs do nothing
if (speed < absMinSpeed)
return brake;
// compute the speed of wheels in m/s
float slip = 0.0f;
for (int i = 0; i < 4; i++)
{
slip += cs.getWheelSpinVel(i) * wheelRadius[i];
}
// slip is the difference between actual speed of car and average speed of wheels
slip = speed - slip/4.0f;
// when slip too high applu ABS
if (slip > absSlip)
{
brake = brake - (slip - absSlip)/absRange;
}
// check brake is not negative, otherwise set it to zero
if (brake<0)
return 0;
else
return brake;
}
示例3: if
/** The transition choose the most fitted state at the moment of the race. */
void
FSMDriver3::transition(CarState &cs) {
DrivingState *state = current_state;
if(gameTicks <= 10000){
distRaced = cs.getDistRaced();
ticks_on_inside_track = inside_track->get_ticks_in_state();
ticks_on_stuck = stuck->get_ticks_in_state();
ticks_on_out_of_track = out_of_track->get_ticks_in_state();
damage = cs.getDamage();
gameTicks += 1;
}/*
else if(gameTicks == 10000){
distRaced = cs.getDistRaced();
gameTicks+=1;
ticks_on_inside_track = inside_track->get_ticks_in_state();
ticks_on_stuck = stuck->get_ticks_in_state();
ticks_on_out_of_track = out_of_track->get_ticks_in_state();
damage = cs.getDamage();
}*/
setTrackType();
if(stuck->isStuck(cs)) {
state = stuck;
} else {
if (cs.getTrack(1) > 0)
state = inside_track;
else {
state = out_of_track;
}
}
if (current_state != state) changeTo(state);
}
示例4: setTargetSpeed
float
InsideTrackA::get_accel(CarState &cs) {
setTargetSpeed(cs);
float Front, max10, max20;
Front = cs.getTrack(10);
max10 = max(cs.getTrack(9), cs.getTrack(11));
max20 = max(cs.getTrack(8), cs.getTrack(12));
float accel = (cs.getSpeedX() > target_speed ? 0 : (Front+max10+max20)/(3*200));
if(Front >= 70) accel = 1;
if(Front <= 20 && cs.getSpeedX() <= 30) accel = 1; /*Resolve o caso em que o carro está preso com a frente voltada para a borda da pista*/
//printf("%.0f, %.0f, %.0f --> accel: %.2f\n", Front, max10, max20, accel);
return accel ;
}
示例5: getGear
int
getGear(CarState & cs) {
int current_gear = cs.getGear();
if(!current_gear) return 1;
if(cs.getRpm() > 8000) ++current_gear;
else if(current_gear > 1 && cs.getRpm() < 5000) --current_gear;
return current_gear;
}
示例6: getBrake
float ApproachingCurve::getBrake(CarState &cs) {
float brake = 0;
float brakeFactor = 0.02;
float diff = cs.getSpeedX() - targetSpeed;
//if (fabs(cs.getSpeedX()) < 2) return 1;
if (cs.getSpeedX() < 0) return 1;
if (diff > 0) brake = brakeFactor * diff;
return brake;
}
示例7: if
int
InsideTrackA::get_gear(CarState &cs) {
int gear = cs.getGear();
if(gear <= 0) return start_gear;
int rpm = cs.getRpm();
if(shouldIncreaseGear(gear, rpm)) ++gear;
else if(shouldDecreaseGear(gear, rpm)) --gear;
return gear;
}
示例8: return
float
SimpleDriver::getSteer(CarState &cs)
{
// steering angle is compute by correcting the actual car angle w.r.t. to track
// axis [cs.getAngle()] and to adjust car position w.r.t to middle of track [cs.getTrackPos()*0.5]
float targetAngle=(cs.getAngle()-cs.getTrackPos()*0.5);
// at high speed reduce the steering command to avoid loosing the control
if (cs.getSpeedX() > steerSensitivityOffset)
return targetAngle/(steerLock*(cs.getSpeedX()-steerSensitivityOffset)*wheelSensitivityCoeff);
else
return (targetAngle)/steerLock;
}
示例9: drive
CarControl Stuck::drive(FSMDriver5 *fsmdriver5, CarState &cs) {
++elapsedTicks;
trackInitialPos = getInitialPos(cs);
if(notStuckAnymore(cs.getTrackPos(), cs.getAngle()) || hasBeenStuckLongEnough()){
elapsedTicks = 0;
slowSpeedTicks = 0;
trackInitialPos = 0;
}
const float accel = 1, brake = 0, clutch = 0;
const int gear = -1, focus = 0, meta = 0;
float steer = getSteer(trackInitialPos, cs);
return CarControl(accel, brake, gear, steer, clutch, focus, meta);
}
示例10: return
/**************************************************************************
* Modularization*/
float
Stuck::get_steer(CarState &cs) {
if(abs(cs.getAngle()) > M_PI) // around 180 graus
return (getInitialPos(cs) > 0 ? -1 : 1);
return (getInitialPos(cs) > 0 ? 1 : -1);
}
示例11: getSteer
float Stuck::getSteer(float trackInitialPos, CarState &cs){
//return (trackInitialPos > 0 ? 1 : -1);
if(abs(cs.getAngle()) > 1.557){// around 180 graus
return (trackInitialPos > 0 ? -1 : 1);
}else{
return (trackInitialPos > 0 ? 1 : -1);
}
}
示例12: getSteering
float
getSteering(CarState & cs) {
// based on Loiacono's SimpleDriver
const float
steerLock = 0.366519;
float
targetAngle = (cs.getAngle() - cs.getTrackPos() * 0.5) / steerLock;
// normalize steering
if(targetAngle < -1)
targetAngle = -1;
else if(targetAngle > 1)
targetAngle = 1;
return targetAngle;
}
示例13:
float
ApproachingCurve::getSteering(CarState &cs) {
if(r_sensor == l_sensor) return 0;
float angle = cs.getAngle();
// If the controller is not in a pre-defined region amongst the inside limits of the track (between 0.7 and 0.9 with the current
// set of values, normalized), than it will be adjusted to do so
bool adjustedToCurve = ((fabs(cs.getTrackPos()) - target_pos >= 0) && (fabs(cs.getTrackPos()) - target_pos < 0.2));
if(!adjustedToCurve) {
if(approachingRightTurn())
angle = max_steering - angle;
else
angle -= max_steering;
}
return angle;
}
示例14: fabs
void
ApproachingCurve::updateSensors(CarState &cs) {
float speedFactor = 5000; // The target speed is obtained through a constant factor
if (cs.getFocus(2) == -1) { // Focus sensors are available only once per second
r_sensor = cs.getTrack(10); // Use track sensors
c_sensor = cs.getTrack(9);
l_sensor = cs.getTrack(8);
}
else {
r_sensor = cs.getFocus(3); // Use focus sensors
c_sensor = cs.getFocus(2);
l_sensor = cs.getFocus(1);
}
target_speed = base_speed + speedFactor / fabs(l_sensor - r_sensor);
sensors_are_updated = true;
}
示例15: updateSensors
void ApproachingCurve::updateSensors(CarState &cs) {
float speedFactor = 5000; //The target speed is obtained through a constant factor
if (cs.getFocus(2) == -1) { //Focus sensors are available only once per second
// cout << "FOCUS MISS!" << endl;
rSensor = cs.getTrack(10); //Use track sensors
cSensor = cs.getTrack(9);
lSensor = cs.getTrack(8);
}
else {
// cout << "FOCUS HIT!" << endl;
rSensor = cs.getFocus(3); //Use focus sensors
cSensor = cs.getFocus(2);
lSensor = cs.getFocus(1);
}
targetSpeed = BASE_SPEED + speedFactor / fabs(lSensor - rSensor);
sensorsAreUpdated = true;
}