2.6 Improving Getting UnstuckCurrent Version
Look Inside Criteria
|
Additional ConditionsAs you can see, MAX_UNSTUCK_ANGLE is 30 degrees. This is quite much, and can still cause problems if we try to drive forward along the wall. So we will reduce that angle. We will also add the condition, that the speed has to be below a certain threshold, before we try to get unstuck. An additional problem can occur if we try to get unstuck on the middle of the track. The following implementation will solve most of this problems. It will not solve the case, where the wall itself is not parallel to the track. The ImplementationSo finally here is the new isStuck(). Change it in driver.cpp. You can also further improve that.
/* Check if I'm stuck */ bool Driver::isStuck(tCarElt* car) { if (fabs(angle) > MAX_UNSTUCK_ANGLE && car->_speed_x < MAX_UNSTUCK_SPEED && fabs(car->_trkPos.toMiddle) > MIN_UNSTUCK_DIST) { if (stuck > MAX_UNSTUCK_COUNT && car->_trkPos.toMiddle*angle < 0.0) { return true; } else { stuck++; return false; } } else { stuck = 0; return false; } } Change also in driver.cpp this part of the drive function to apply more throttle to back up.
if (isStuck(car)) { 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 { Put the constants at the start of driver.cpp. Reduce also MAX_UNSTUCK_ANGLE.
const float Driver::MAX_UNSTUCK_SPEED = 5.0; /* [m/s] */ const float Driver::MIN_UNSTUCK_DIST = 3.0; /* [m] */ You need also to define the new constants in driver.h.
static const float MAX_UNSTUCK_SPEED; static const float MIN_UNSTUCK_DIST; DownloadsIn case you got lost, you can download my robot for TORCS 1.2.0 or later. FeedbackLet me know if you read this chapter and your thoughts about it. Please send me also spelling, grammar, math and code corrections. Thank you for the feedback. Summary
|
Back |
Up |