47 double acc_dt,
double acc_lim_x,
double acc_lim_y,
48 double acc_lim_th,
double max_vel_x,
double min_vel_x,
49 double max_vel_y,
double min_vel_y,
double max_rot_vel,
50 double min_rot_vel,
unsigned int vx_samples,
51 unsigned int vy_samples,
unsigned int vth_samples)
52 : collision_(collision)
56 , acc_lim_x_(acc_lim_x)
57 , acc_lim_y_(acc_lim_y)
58 , acc_lim_th_(acc_lim_th)
59 , max_vel_x_(max_vel_x)
60 , min_vel_x_(min_vel_x)
61 , max_vel_y_(max_vel_y)
62 , min_vel_y_(min_vel_y)
63 , max_rot_vel_(max_rot_vel)
64 , min_rot_vel_(min_rot_vel)
65 , vx_samples_(vx_samples)
66 , vy_samples_(vy_samples)
67 , vth_samples_(vth_samples)
68 , steps_(static_cast<unsigned int>(
std::abs(horizon / dt)))
72 std::cout <<
"vx samples set to 0 but need at least 1... setting this to 1"
79 std::cout <<
"vy samples set to 0 but need at least 1... setting this to 1"
86 std::cout <<
"vth samples set to 0 but need at least 1... setting this to 1"
93 const vec& vref)
const
96 const std::tuple<vec, vec> window_config =
window(vb);
99 auto min_cost = std::numeric_limits<double>::max();
101 vec u_opt(3, arma::fill::zeros);
102 vec u(3, arma::fill::zeros);
104 auto vx = std::get<0>(window_config)(0);
107 auto vy = std::get<0>(window_config)(1);
110 auto w = std::get<0>(window_config)(2);
117 const auto cost =
objective(grid, x0, vref, u);
125 w += std::get<1>(window_config)(2);
127 vy += std::get<1>(window_config)(1);
129 vx += std::get<1>(window_config)(0);
132 if (
almost_equal(min_cost, std::numeric_limits<double>::max()))
134 std::cout <<
"DWA Failed! Not even 1 solution found" << std::endl;
135 return std::make_tuple(
false, u_opt);
138 return std::make_tuple(
true, u_opt);
142 const mat& xt_ref,
double dt_ref)
const
145 const tuple<vec, vec> window_config =
window(vb);
148 const double tf =
static_cast<double>(xt_ref.n_cols) * dt_ref;
151 auto min_cost = std::numeric_limits<double>::max();
153 vec u_opt(3, arma::fill::zeros);
154 vec u(3, arma::fill::zeros);
156 auto vx = std::get<0>(window_config)(0);
159 auto vy = std::get<0>(window_config)(1);
162 auto w = std::get<0>(window_config)(2);
169 const auto cost =
objective(grid, x0, u, xt_ref,
tf);
177 w += std::get<1>(window_config)(2);
179 vy += std::get<1>(window_config)(1);
181 vx += std::get<1>(window_config)(0);
184 if (
almost_equal(min_cost, std::numeric_limits<double>::max()))
186 std::cout <<
"DWA Failed! Not even 1 solution found" << std::endl;
187 return std::make_tuple(
false, u_opt);
190 return std::make_tuple(
true, u_opt);
196 vec vel_upper(3, arma::fill::zeros);
197 vec vel_lower(3, arma::fill::zeros);
198 vec delta_vb(3, arma::fill::zeros);
216 delta_vb(0) = (vel_upper(0) - vel_lower(0)) /
static_cast<double>(
vx_samples_ - 1);
221 delta_vb(1) = (vel_upper(1) - vel_lower(1)) /
static_cast<double>(
vy_samples_ - 1);
226 delta_vb(2) = (vel_upper(2) - vel_lower(2)) /
static_cast<double>(
vth_samples_ - 1);
234 return std::make_tuple(vel_lower, delta_vb);
242 for (
unsigned int i = 0; i <
steps_; i++)
249 return std::numeric_limits<double>::max();
254 const vec cntrl_error = vref - u;
255 return dot(cntrl_error, cntrl_error);
259 const mat& xt_ref,
double tf)
const
266 for (
unsigned int i = 0; i <
steps_; i++)
273 return std::numeric_limits<double>::max();
277 const auto j =
static_cast<unsigned int>(std::round((xt_ref.n_cols - 1) *
t /
tf));
279 cost += arma::norm(xt_ref(span(0, 1), span(j, j)) - pose.rows(0, 1));