|
@@ -25,10 +25,12 @@ public:
|
|
Eigen::VectorXd m_coeffs; //曲线方程
|
|
Eigen::VectorXd m_coeffs; //曲线方程
|
|
Eigen::VectorXd m_statu; //当前状态
|
|
Eigen::VectorXd m_statu; //当前状态
|
|
Eigen::VectorXd m_condition; //搜索条件参数
|
|
Eigen::VectorXd m_condition; //搜索条件参数
|
|
- FG_eval_half_agv(Eigen::VectorXd coeffs, Eigen::VectorXd statu, Eigen::VectorXd condition) {
|
|
|
|
|
|
+ bool directY_;
|
|
|
|
+ FG_eval_half_agv(Eigen::VectorXd coeffs, Eigen::VectorXd statu, Eigen::VectorXd condition,bool directY) {
|
|
m_coeffs = coeffs;
|
|
m_coeffs = coeffs;
|
|
m_statu = statu;
|
|
m_statu = statu;
|
|
m_condition = condition;
|
|
m_condition = condition;
|
|
|
|
+ directY_=directY;
|
|
}
|
|
}
|
|
|
|
|
|
typedef CPPAD_TESTVECTOR(CppAD::AD<double>) ADvector;
|
|
typedef CPPAD_TESTVECTOR(CppAD::AD<double>) ADvector;
|
|
@@ -113,45 +115,29 @@ public:
|
|
fg[1 + ndlt + t] = (vars[ndlt + t] - vars[ndlt + t - 1]) / dt;
|
|
fg[1 + ndlt + t] = (vars[ndlt + t] - vars[ndlt + t - 1]) / dt;
|
|
}
|
|
}
|
|
|
|
|
|
- if (m_statu.size() == 2 + 3) {
|
|
|
|
- float obs_x = m_statu[2];
|
|
|
|
- float obs_y = m_statu[3];
|
|
|
|
- float obs_theta = m_statu[4];
|
|
|
|
- Pose2d obs_relative_pose(obs_x, obs_y, obs_theta);
|
|
|
|
- std::vector<Pose2d> obs_vertexes = Pose2d::generate_rectangle_vertexs(obs_relative_pose, obs_w * 2,
|
|
|
|
- obs_h * 2);
|
|
|
|
- for (auto t = 0; t < N/2; ++t) {
|
|
|
|
- CppAD::AD<double> min_distance = 1e19-1;
|
|
|
|
- for (auto i = 0; i < 8; ++i) {
|
|
|
|
- CppAD::AD<double> ra = (obs_vertexes[i].x() - vars[nx + t]) * CppAD::cos(vars[nth + t]) -
|
|
|
|
- (obs_vertexes[i].y() - vars[ny + t]) * CppAD::sin(vars[nth + t]);
|
|
|
|
- CppAD::AD<double> rb = (obs_vertexes[i].x() - vars[nx + t]) * CppAD::sin(vars[nth + t]) +
|
|
|
|
- (obs_vertexes[i].y() - vars[ny + t]) * CppAD::cos(vars[nth + t]);
|
|
|
|
- CppAD::AD<double> distance = CppAD::pow(ra / obs_w, 8) + CppAD::pow(rb / obs_h, 8);
|
|
|
|
- if (distance < min_distance) min_distance = distance;
|
|
|
|
|
|
+
|
|
|
|
+ if (m_statu.size() == 2 + 16) {
|
|
|
|
+ //与障碍物的距离
|
|
|
|
+ for (int i = 0; i < 8; ++i) {
|
|
|
|
+ double ox = m_statu[2 + i * 2];
|
|
|
|
+ double oy = m_statu[2 + i * 2 + 1];
|
|
|
|
+ for (int t = 0; t < N; ++t) {
|
|
|
|
+ /*第i点的矩形方程为: {[(x-xi)cos(Θi)-(y-yi)sin(Θi)]/1.35}**8 +
|
|
|
|
+ * {[(x-xi)sin(Θi)+(y-yi)cos(Θi)]/0.75}**8 = 1.0
|
|
|
|
+ *
|
|
|
|
+ * */
|
|
|
|
+ CppAD::AD<double> ra = (ox - vars[nx + t]) * CppAD::cos(vars[nth + t]) -
|
|
|
|
+ (oy - vars[ny + t]) * CppAD::sin(vars[nth + t]);
|
|
|
|
+ CppAD::AD<double> rb = (ox - vars[nx + t]) * CppAD::sin(vars[nth + t]) +
|
|
|
|
+ (oy - vars[ny + t]) * CppAD::cos(vars[nth + t]);
|
|
|
|
+ if(!directY_)
|
|
|
|
+ fg[1 + nobs + N * i + t] = CppAD::pow(ra / obs_w, 8) + CppAD::pow(rb / (obs_h*0.6), 8);
|
|
|
|
+ else
|
|
|
|
+ fg[1 + nobs + N * i + t] = CppAD::pow(ra / (obs_w*0.6), 8) + CppAD::pow(rb / obs_h, 8);
|
|
}
|
|
}
|
|
- fg[1 + nobs + t] = min_distance;
|
|
|
|
}
|
|
}
|
|
-// std::cout << " fg[n_obs]: " << fg[n_obs] << " | __LINE__:" << __LINE__ << std::endl;
|
|
|
|
}
|
|
}
|
|
-// if (m_statu.size() == 2 + 3) {
|
|
|
|
-// //与障碍物的距离
|
|
|
|
-// for (int i = 0; i < 8; ++i) {
|
|
|
|
-// double ox = m_statu[2 + i * 2];
|
|
|
|
-// double oy = m_statu[2 + i * 2 + 1];
|
|
|
|
-// for (int t = 0; t < N; ++t) {
|
|
|
|
-// /*第i点的矩形方程为: {[(x-xi)cos(Θi)-(y-yi)sin(Θi)]/1.35}**8 +
|
|
|
|
-// * {[(x-xi)sin(Θi)+(y-yi)cos(Θi)]/0.75}**8 = 1.0
|
|
|
|
-// *
|
|
|
|
-// * */
|
|
|
|
-// CppAD::AD<double> ra = (ox - vars[nx + t]) * CppAD::cos(vars[nth + t]) -
|
|
|
|
-// (oy - vars[ny + t]) * CppAD::sin(vars[nth + t]);
|
|
|
|
-// CppAD::AD<double> rb = (ox - vars[nx + t]) * CppAD::sin(vars[nth + t]) +
|
|
|
|
-// (oy - vars[ny + t]) * CppAD::cos(vars[nth + t]);
|
|
|
|
-// fg[1 + nobs + N * i + t] = CppAD::pow(ra / obs_w, 8) + CppAD::pow(rb / obs_h, 8);
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
@@ -166,7 +152,8 @@ LoadedMPC::LoadedMPC(const Pose2d &obs, double obs_w, double obs_h, double min_v
|
|
LoadedMPC::~LoadedMPC() {}
|
|
LoadedMPC::~LoadedMPC() {}
|
|
|
|
|
|
MpcError LoadedMPC::solve(Trajectory trajectory, Pose2d target, Eigen::VectorXd statu, MPC_parameter mpc_param,
|
|
MpcError LoadedMPC::solve(Trajectory trajectory, Pose2d target, Eigen::VectorXd statu, MPC_parameter mpc_param,
|
|
- std::vector<double> &out, Trajectory &select_traj, Trajectory &optimize_trajectory) {
|
|
|
|
|
|
+ std::vector<double> &out, Trajectory &select_traj,
|
|
|
|
+ Trajectory &optimize_trajectory,bool directY) {
|
|
auto start = std::chrono::steady_clock::now();
|
|
auto start = std::chrono::steady_clock::now();
|
|
// State vector holds all current values neede for vars below
|
|
// State vector holds all current values neede for vars below
|
|
Pose2d pose_agv = Pose2d(statu[0], statu[1], statu[2]);
|
|
Pose2d pose_agv = Pose2d(statu[0], statu[1], statu[2]);
|
|
@@ -247,14 +234,17 @@ MpcError LoadedMPC::solve(Trajectory trajectory, Pose2d target, Eigen::VectorXd
|
|
}
|
|
}
|
|
|
|
|
|
// Lower and upper limits for the constraints
|
|
// Lower and upper limits for the constraints
|
|
|
|
+ size_t n_constraints = N * 5;
|
|
/*
|
|
/*
|
|
* 障碍物是否进入 碰撞检测范围内
|
|
* 障碍物是否进入 碰撞检测范围内
|
|
*/
|
|
*/
|
|
float distance = Pose2d::distance(obs_relative_pose_, Pose2d(0, 0, 0));
|
|
float distance = Pose2d::distance(obs_relative_pose_, Pose2d(0, 0, 0));
|
|
- distance = 1000;
|
|
|
|
- bool find_obs = distance < 10;
|
|
|
|
- if (find_obs) printf(" find obs ..............................\n");
|
|
|
|
- size_t n_constraints = 5 * N + find_obs * N/2;
|
|
|
|
|
|
+ bool find_obs = false;
|
|
|
|
+ if (distance < 20) {
|
|
|
|
+ printf(" mpc find obs ,w=%f,h=%f\n",obs_w_,obs_h_);
|
|
|
|
+ find_obs = true;
|
|
|
|
+ }
|
|
|
|
+ if (find_obs) n_constraints = N * (5 + 8);
|
|
|
|
|
|
Dvector constraints_lowerbound(n_constraints);
|
|
Dvector constraints_lowerbound(n_constraints);
|
|
Dvector constraints_upperbound(n_constraints);
|
|
Dvector constraints_upperbound(n_constraints);
|
|
@@ -277,7 +267,7 @@ MpcError LoadedMPC::solve(Trajectory trajectory, Pose2d target, Eigen::VectorXd
|
|
constraints_lowerbound[i] = -max_acc_dlt;
|
|
constraints_lowerbound[i] = -max_acc_dlt;
|
|
constraints_upperbound[i] = max_acc_dlt;
|
|
constraints_upperbound[i] = max_acc_dlt;
|
|
//延迟处理,前delay个周期内认定为匀速运动(加速度为0)
|
|
//延迟处理,前delay个周期内认定为匀速运动(加速度为0)
|
|
- if (i < nv+delay){
|
|
|
|
|
|
+ if (i < ndlt+delay){
|
|
constraints_lowerbound[i] = 0;
|
|
constraints_lowerbound[i] = 0;
|
|
constraints_upperbound[i] = 0;
|
|
constraints_upperbound[i] = 0;
|
|
}
|
|
}
|
|
@@ -285,7 +275,7 @@ MpcError LoadedMPC::solve(Trajectory trajectory, Pose2d target, Eigen::VectorXd
|
|
|
|
|
|
// 与障碍物保持距离的约束
|
|
// 与障碍物保持距离的约束
|
|
if (find_obs) {
|
|
if (find_obs) {
|
|
- for (int i = nobs; i < nobs + N/2; ++i) {
|
|
|
|
|
|
+ for (int i = nobs; i < nobs + 8 * N; ++i) {
|
|
constraints_lowerbound[i] = 1.0;
|
|
constraints_lowerbound[i] = 1.0;
|
|
constraints_upperbound[i] = 1e19;
|
|
constraints_upperbound[i] = 1e19;
|
|
}
|
|
}
|
|
@@ -311,18 +301,23 @@ MpcError LoadedMPC::solve(Trajectory trajectory, Pose2d target, Eigen::VectorXd
|
|
angular = -max_dlt;
|
|
angular = -max_dlt;
|
|
}
|
|
}
|
|
|
|
|
|
- Eigen::VectorXd status(2 + 3 * find_obs);
|
|
|
|
- status[0] = line_velocity;
|
|
|
|
- status[1] = angular;
|
|
|
|
|
|
+ Eigen::VectorXd statu_velocity(2);
|
|
if (find_obs) {
|
|
if (find_obs) {
|
|
- status[2]= obs_relative_pose_.x();
|
|
|
|
- status[3] = obs_relative_pose_.y();
|
|
|
|
- status[4] = obs_relative_pose_.theta();
|
|
|
|
|
|
+ statu_velocity = Eigen::VectorXd(2 + 16);
|
|
|
|
+
|
|
|
|
+ std::vector<Pose2d> vertexs = Pose2d::generate_rectangle_vertexs(obs_relative_pose_, obs_w_ * 2, obs_h_ * 2);
|
|
|
|
+ for (int i = 0; i < vertexs.size(); ++i) {
|
|
|
|
+ //std::cout<<"vetex:"<<vertexs[i]<<std::endl;
|
|
|
|
+ statu_velocity[2 + i * 2] = vertexs[i].x();
|
|
|
|
+ statu_velocity[2 + i * 2 + 1] = vertexs[i].y();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+ statu_velocity[0] = line_velocity;
|
|
|
|
+ statu_velocity[1] = angular;
|
|
|
|
|
|
Eigen::VectorXd condition(6);
|
|
Eigen::VectorXd condition(6);
|
|
condition << dt, ref_velocity, obs_w_, obs_h_, targetPoseInAGV.x(), targetPoseInAGV.y();
|
|
condition << dt, ref_velocity, obs_w_, obs_h_, targetPoseInAGV.x(), targetPoseInAGV.y();
|
|
- FG_eval_half_agv fg_eval(coef, status, condition);
|
|
|
|
|
|
+ FG_eval_half_agv fg_eval(coef, statu_velocity, condition,directY);
|
|
|
|
|
|
// options for IPOPT solver
|
|
// options for IPOPT solver
|
|
std::string options;
|
|
std::string options;
|