#include #include #include "keep_lane_traj_set.h" #include using namespace vlr; keep_lane_traj_set::keep_lane_traj_set(lanekeeping_params params) { par = params; } int keep_lane_traj_set::generate(double t_start, double s_start, movement_state start_state, GenerationMode mode, double sampling_horizon/*todo: get rid*/, const std::vector >& sample_ref) { double arg_max; double arg_res; double dder_min; double dder_max; double weight_arg; double weight_j; double weight_d; std::vector arg_alt; int number_of_alt_args; if ( mode == time_based ) { arg_max = par.holon.time_max; arg_res = par.holon.time_res; dder_min = par.holon.d_ddot_min; dder_max = par.holon.d_ddot_max; weight_arg = par.holon.k_t; weight_j = par.holon.k_j; weight_d = par.holon.k_d; number_of_alt_args = (int)floor( arg_max / arg_res +.5 ); arg_alt.resize(number_of_alt_args); double t0 = ceil(t_start/arg_res)*arg_res; arg_alt[0] = t0; // next discrete point in time for (int i=1; i d_alt(number_of_alt_d_offsets); d_alt[0] = (int) ceil( par.d_offset_min / par.d_res) * par.d_res; for (int i=1; i dder_min ) && ( traj.get_dder_max() < dder_max ) ) { // extrema a ok? // Sample for collision check traj.sampleArgumentSynchronized(sample_ref); // Calculate costs double arg = mode==time_based? ( arg_alt[j] -t_start ) : ( arg_alt[j] -s_start ); double J_integral = traj.get_jerk_integral(); double deviation = d_alt[i]; //movement_state end_state = traj.get_end_state(); double cost_arg = weight_arg * arg; double cost_jerk = weight_j * J_integral; double cost_deviation = weight_d * ( deviation*deviation ); cost = cost_arg + cost_jerk + cost_deviation; // if (d_alt[i]*d_alt[i] < 0.01 ) { // printf("--------------------------------------------------J_integral = %f\n", J_integral); // } traj.set_debug_info(arg, J_integral, deviation, cost_arg, cost_jerk, cost_deviation); traj.set_total_cost(cost); set_data.insert(traj); // insert new trajectory } } } } if ( set_data.size() == 0 ) { vlr::Exception except("Lane keeping set empty!"); throw except; } return 0; } void keep_lane_traj_set::clear() { set_data.clear(); }