|
@@ -43,8 +43,8 @@ public:
|
|
|
// 代价函数计算
|
|
|
for (int t = 0; t < N - 1; ++t) {
|
|
|
/// 角速度,角加速度weight loss
|
|
|
- //fg[0] += angular_velocity_cost_weight * CppAD::pow(vars[N + t], 2);
|
|
|
- //fg[0] += angular_acceleration_cost_weight * CppAD::pow(vars[N + t + 1] - vars[N + t], 2);
|
|
|
+ fg[0] += angular_velocity_cost_weight * CppAD::pow(vars[N + t], 2);
|
|
|
+ fg[0] += angular_acceleration_cost_weight * CppAD::pow(vars[N + t + 1] - vars[N + t], 2);
|
|
|
/// 目标角度 loss
|
|
|
fg[0] += angular_cost_weight * CppAD::pow(target_theta - vars[t], 2);
|
|
|
}
|
|
@@ -120,9 +120,9 @@ RotateMPC::solve(Pose2d current_to_target, Eigen::VectorXd statu, MPC_parameter
|
|
|
|
|
|
/// 定义最大最小角度,角速度,角加速度(不区分方向)
|
|
|
double max_angular = M_PI;
|
|
|
- double max_angular_velocity = 6.0 / 180 * M_PI;
|
|
|
- double min_angular_velocity = 0.1 / 180 * M_PI;
|
|
|
- double max_angular_acceleration_velocity = 3.0 / 180 * M_PI;//mpc_param.acc_angular; //
|
|
|
+ double max_angular_velocity = 15.0 / 180 * M_PI;
|
|
|
+ double min_angular_velocity = 0.01 / 180 * M_PI;
|
|
|
+ double max_angular_acceleration_velocity = 30.0 / 180 * M_PI;//mpc_param.acc_angular; //
|
|
|
/// 调整输入
|
|
|
if (angular_velocity > max_angular_velocity) angular_velocity = max_angular_velocity;
|
|
|
if (angular_velocity < -max_angular_velocity) angular_velocity = -max_angular_velocity;
|
|
@@ -155,7 +155,8 @@ RotateMPC::solve(Pose2d current_to_target, Eigen::VectorXd statu, MPC_parameter
|
|
|
|
|
|
// Lower and upper limits for the constraints
|
|
|
/// 障碍物是否进入 碰撞检测范围内
|
|
|
- float distance = Pose2d::distance(obs_relative_pose_, Pose2d(0, 0, 0));
|
|
|
+// float distance = Pose2d::distance(obs_relative_pose_, Pose2d(0, 0, 0));
|
|
|
+ float distance = 1000;//屏蔽障碍物
|
|
|
bool find_obs = distance < 5;
|
|
|
if (find_obs) printf(" find obs ..............................\n");
|
|
|
size_t n_constraints = 2 * N + find_obs * N;// 0~N角度,N~2N角加速度, 2N~3N障碍物约束
|
|
@@ -191,23 +192,25 @@ RotateMPC::solve(Pose2d current_to_target, Eigen::VectorXd statu, MPC_parameter
|
|
|
|
|
|
Pose2d targetAngularInAGV = current_to_target;
|
|
|
/// 调整到适合的目标角度
|
|
|
- if (targetAngularInAGV.theta() > 0) {
|
|
|
- double acc_time = (max_angular_velocity - angular_velocity) / max_angular_acceleration_velocity;
|
|
|
- double max_angular_once = max_angular_velocity * N * dt - acc_time * (max_angular_velocity - angular_velocity);
|
|
|
- if (targetAngularInAGV.theta() > max_angular_once ) {
|
|
|
- targetAngularInAGV.set_theta(max_angular_once);
|
|
|
- }
|
|
|
- }
|
|
|
- else if (targetAngularInAGV.theta() < 0) {
|
|
|
- double acc_time = fabs((-max_angular_velocity - angular_velocity) / -max_angular_acceleration_velocity);
|
|
|
- double max_angular_once = -max_angular_velocity * N * dt + acc_time * (-max_angular_velocity - angular_velocity);
|
|
|
- if (targetAngularInAGV.theta() < max_angular_once ) {
|
|
|
- targetAngularInAGV.set_theta(max_angular_once);
|
|
|
- }
|
|
|
- } else{
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
+// if (targetAngularInAGV.theta() > 0) {
|
|
|
+//// double acc_time = (max_angular_velocity - angular_velocity) / max_angular_acceleration_velocity;
|
|
|
+//// double max_angular_once = max_angular_velocity * N * dt - acc_time * (max_angular_velocity - angular_velocity);
|
|
|
+// double max_angular_once = 9.0 / 180 * M_PI;
|
|
|
+// if (targetAngularInAGV.theta() > max_angular_once ) {
|
|
|
+// targetAngularInAGV.set_theta(max_angular_once);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// else if (targetAngularInAGV.theta() < 0) {
|
|
|
+//// double acc_time = fabs((-max_angular_velocity - angular_velocity) / -max_angular_acceleration_velocity);
|
|
|
+//// double max_angular_once = -max_angular_velocity * N * dt + acc_time * (-max_angular_velocity - angular_velocity);
|
|
|
+// double max_angular_once = -9.0 / 180 * M_PI;
|
|
|
+// if (targetAngularInAGV.theta() < max_angular_once ) {
|
|
|
+// targetAngularInAGV.set_theta(max_angular_once);
|
|
|
+// }
|
|
|
+// } else{
|
|
|
+//
|
|
|
+// }
|
|
|
+ printf("target: %f\n",targetAngularInAGV.theta()/M_PI*180);
|
|
|
|
|
|
Eigen::VectorXd condition(4);
|
|
|
condition << dt, targetAngularInAGV.theta(), obs_w_, obs_h_;
|