class ParkingSlot {
private:
double offset_ = 0.001; // to avoid collision during init
+ double parking_speed_ = -0.1;
+ unsigned int max_cusp_ = 10;
+ double delta_angle_to_slot_ = 0.001;
Point border_[4];
Line entry_;
Line rear_;
/*! Return parking slot's orientation. */
double h() const;
+ /*! Car's next iteration distance. (Negative for backward.) */
+ void set_parking_speed(double s);
+
+ /*! Maximum allowed number of cusp inside the parking slot. */
+ void set_max_cusp(unsigned int m);
+
+ /*! Angle's increment when creating start positions. */
+ void set_delta_angle_to_slot(double d);
+
/*! Return `true` for the parallel parking slot. */
bool parallel() const;
/*! \brief Drive car `c` into the parking slot `this`.
*
* \param c Starting bicycle car.
- * \param max Maximum number of backward-forward direction changes.
*/
- std::vector<BicycleCar> drive_in_slot(BicycleCar c, unsigned int& max);
+ std::vector<BicycleCar> drive_in_slot(BicycleCar c);
/*! \brief Steer car `c` into the parking slot `this`.
*
/*! \brief Find entry.
*
* \param c For which `BicycleCar` should entry be found?
- * \param max Maximum number of backward-forward direction changes.
*/
- PoseRange fe(BicycleCar c, unsigned int& max);
+ PoseRange fe(BicycleCar c);
/*! \brief Recompute zero slot's `PoseRange` entry for `this`.
*
return atan2(this->lfy() - this->lry(), this->lfx() - this->lrx());
}
+void
+ParkingSlot::set_parking_speed(double s)
+{
+ this->parking_speed_ = s;
+}
+
+void
+ParkingSlot::set_max_cusp(unsigned int m)
+{
+ this->max_cusp_ = m;
+}
+
+void
+ParkingSlot::set_delta_angle_to_slot(double d)
+{
+ this->delta_angle_to_slot_ = d;
+}
+
bool
ParkingSlot::parallel() const
{
}
std::vector<BicycleCar>
-ParkingSlot::drive_in_slot(BicycleCar c, unsigned int& max)
+ParkingSlot::drive_in_slot(BicycleCar c)
{
assert(this->parallel());
assert(this->right());
assert(c.len() < this->len());
assert(c.w() < this->w());
std::vector<BicycleCar> path;
- path.reserve(max + 2);
+ path.reserve(this->max_cusp_ + 2);
path.push_back(c);
unsigned int cusp = 0;
- while (cusp < max + 1) {
+ while (cusp < this->max_cusp_ + 1) {
if (this->parked(c)) {
- if (cusp < max) {
- max = cusp;
+ if (cusp < this->max_cusp_) {
+ this->max_cusp_ = cusp;
}
path.push_back(c);
return path;
}
PoseRange
-ParkingSlot::fe(BicycleCar c, unsigned int& max)
+ParkingSlot::fe(BicycleCar c)
{
assert(this->parallel());
assert(this->right());
c.x(this->lrx() + clen * cos(c.h()) + cw * cos(c.h() + M_PI / 2.0));
c.y(this->lry() + clen * sin(c.h()) + cw * sin(c.h() + M_PI / 2.0));
c.set_max_steer();
- c.sp(-0.001);
+ c.sp(this->parking_speed_);
auto const rc = c.rf();
this->curb_.intersects_with(rc, c.len());
double max_to_slot;
std::vector<BicycleCar> starts;
double a_to_slot = 0.0;
while (a_to_slot < max_to_slot) {
- a_to_slot += 0.0001;
- c.rotate(rc, 0.0001);
+ a_to_slot += this->delta_angle_to_slot_;
+ c.rotate(rc, this->delta_angle_to_slot_);
starts.push_back(c);
}
std::vector<std::vector<BicycleCar>> entries;
for (auto s: starts) {
- auto r = this->drive_in_slot(s, max);
+ auto r = this->drive_in_slot(s);
if (r.size() > 0) {
entries.push_back(r);
}