RRTNode *RRTBase::sample()
{
if (this->useSamplingInfo_ && this->nodes().size() % 2 == 0) {
- float sar = static_cast<float>(rand());
- sar /= static_cast<float>(RAND_MAX / this->samplingInfo_.r);
- sar += this->samplingInfo_.mr;
- float sah = static_cast<float>(rand());
- sah /= static_cast<float>(RAND_MAX / this->samplingInfo_.h);
- sah *= this->samplingInfo_.dh;
- sah += this->samplingInfo_.sh;
+ float x = static_cast<float>(rand());
+ x /= static_cast<float>(RAND_MAX / this->samplingInfo_.x);
+ x -= this->samplingInfo_.x / 2;
+ x += this->samplingInfo_.x0;
+ float y = static_cast<float>(rand());
+ y /= static_cast<float>(RAND_MAX / this->samplingInfo_.y);
+ y -= this->samplingInfo_.y / 2;
+ y += this->samplingInfo_.y0;
float h = static_cast<float>(rand());
- h /= static_cast<float>(RAND_MAX / this->samplingInfo_.mh);
- h += this->samplingInfo_.mmh;
- h *= this->samplingInfo_.dh;
- h += this->samplingInfo_.sh;
- return new RRTNode(
- this->samplingInfo_.x + sar * cos(sah),
- this->samplingInfo_.y + sar * sin(sah),
- h
- );
+ h /= static_cast<float>(RAND_MAX / this->samplingInfo_.h);
+ h -= this->samplingInfo_.h / 2;
+ h += this->samplingInfo_.h0;
+ return new RRTNode(x, y, h);
} else {
return sa1();
}
std::vector<SegmentObstacle>& so
)
{
+ this->setAll();
if (this->slotType() == PERPENDICULAR) {
// TODO different slot headings
// this is jus for slot heading = pi / 2
struct SamplingInfo ParallelSlot::getSamplingInfo()
{
struct SamplingInfo si;
+ RRTNode *n = this->getMidd();
if (this->slotType() == PARALLEL) {
- si.x = this->slot().bnodes().front()->x();
- si.y = this->slot().bnodes().front()->y();
- si.mr = BCAR_WIDTH / 2;
- si.mmh = 0;
+ if (n != nullptr) {
+ si.x0 = n->x() + 1.5 * BCAR_LENGTH * cos(n->h());
+ si.y0 = n->y() + 1.5 * BCAR_LENGTH * sin(n->h());
+ si.h0 = n->h();
+ } else {
+ si.x0 = this->slot().bnodes().front()->x();
+ si.y0 = this->slot().bnodes().front()->y();
+ si.h0 = this->slotHeading();
+ }
+ si.x = BCAR_WIDTH;
+ si.y = BCAR_WIDTH;
+ si.h = M_PI / 8;
} else {
- si.x = this->slot().bnodes().back()->x();
- si.x -= this->slot().bnodes().front()->x();
- si.x /= 2;
- si.x += this->slot().bnodes().front()->x();
- si.y = this->slot().bnodes().back()->y();
- si.y -= this->slot().bnodes().front()->y();
- si.y /= 2;
- si.y += this->slot().bnodes().front()->y();
- si.mr = 0;
- si.mmh = (M_PI - M_PI / 6) / 2;
+ // TODO
}
- si.r = BCAR_LENGTH;
- si.h = M_PI;
- si.mh = M_PI / 2;
- si.sh = this->slotHeading();
- if (this->slotSide() == RIGHT)
- si.dh = 1;
- else
- si.dh = -1;
return si;
}
};
struct SamplingInfo {
+ float x0;
+ float y0;
+ float h0;
float x;
float y;
- float r; // max radi from [x, y] for random sample
- float mr; // minimum r added to random r
- float h; // max angle for random sample
- float mh; // max angle for heading of random sample
- float mmh; // minimum mh added to mh
- float sh; // slot heading
- float dh; // direction to compute random heading from slot heading
+ float h;
};
class ParallelSlot {