|
@@ -393,121 +393,6 @@ void Navigation::NavCmdCallback(const MqttMsg& msg,void* context)
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-bool Navigation::execute_adjust_action(const Pose2d& target,const Pose2d& target_diff,stLimit limit_v,
|
|
|
- stLimit limit_h,stLimit limit_rotate,bool anyDitect)
|
|
|
-{
|
|
|
- std::cout<<" adjust target:"<<target<<" target diff:"<<target_diff<<std::endl;
|
|
|
- if(inited_==false) {
|
|
|
- printf(" navigation has not inited\n");
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- Pose2d accuracy=Pose2d::abs(target_diff.rotate(timedPose_.Get().theta()));
|
|
|
- Pose2d thresh=Pose2d::abs(accuracy);
|
|
|
-
|
|
|
- int action=0; //1 原地旋转,2横移,3前进
|
|
|
- while(cancel_==false) {
|
|
|
- std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
|
|
- if (pause_ == true) {
|
|
|
- //发送暂停消息
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (PoseTimeout() || timedV_.timeout() || timedA_.timeout()) {
|
|
|
- printf(" navigation Error:Pose/v/a is timeout \n");
|
|
|
- break;
|
|
|
- }
|
|
|
- //判断是否到达目标点
|
|
|
- int direct=0;
|
|
|
- if(anyDitect) direct=2;
|
|
|
- if (IsArrived(timedPose_.Get(), timedV_.Get(), timedA_.Get(), target, accuracy,direct)) {
|
|
|
- if(Stop()) {
|
|
|
- printf("adjust completed anyDitect :%d\n",anyDitect);
|
|
|
- return true;
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- //计算目标点在当前pose下的pose
|
|
|
- Pose2d diff = Pose2d::relativePose(target,timedPose_.Get());
|
|
|
- //停止状态
|
|
|
- if (action == 0) {
|
|
|
- //
|
|
|
- if (Pose2d::abs(diff).x() > thresh.x()) {
|
|
|
- //前进
|
|
|
- action = 3;
|
|
|
- }else if (Pose2d::abs(diff).y() > thresh.y()) {
|
|
|
- //横移
|
|
|
- action = 2;
|
|
|
- }
|
|
|
- else if (Pose2d::abs(diff).theta() > thresh.theta()) {
|
|
|
- action = 1; //原地旋转
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- double acc_v=0.6;
|
|
|
- double acc_angular=10.0*M_PI/180.0;
|
|
|
- double dt=0.1;
|
|
|
- if (action == 1) {
|
|
|
- float minYawDiff=diff.theta();
|
|
|
- if(anyDitect){
|
|
|
- Pose2d p0=timedPose_.Get();
|
|
|
- float yawdiff[4]={0};
|
|
|
- yawdiff[0]=diff.theta();
|
|
|
- yawdiff[1]=Pose2d::relativePose(target,p0-Pose2d(0,0,M_PI/2)).theta(); ////使用减法,保证角度在【-pi pi】
|
|
|
- yawdiff[2]=Pose2d::relativePose(target,p0-Pose2d(0,0,M_PI)).theta();
|
|
|
- yawdiff[3]=Pose2d::relativePose(target,p0-Pose2d(0,0,3*M_PI/2)).theta();
|
|
|
- for(int i=1;i<4;++i){
|
|
|
- if(fabs(yawdiff[i])<fabs(minYawDiff)){
|
|
|
- minYawDiff=yawdiff[i];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- if (fabs(minYawDiff) > thresh.theta()) {
|
|
|
-
|
|
|
- double theta = limit_gause(minYawDiff,limit_rotate.min,limit_rotate.max);
|
|
|
- double angular=next_speed(timedA_.Get(),theta,acc_angular,dt);
|
|
|
- double limit_angular=limit(angular,limit_rotate.min,limit_rotate.max);
|
|
|
-
|
|
|
- SendMoveCmd(move_mode_,Monitor_emqx::eRotate, 0, limit_angular);
|
|
|
- actionType_=eRotation;
|
|
|
- printf(" Ratate | input anguar:%f,next angular:%f,down:%f diff:%f anyDitect:%d\n",
|
|
|
- timedA_.Get(),angular,limit_angular,minYawDiff,anyDitect);
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
- if (action == 2) {
|
|
|
- if (Pose2d::abs(diff).y() > thresh.y()) {
|
|
|
- double hv=limit_gause(diff.y(),limit_h.min,limit_h.max);
|
|
|
- double velocity=limit(next_speed(timedV_.Get(),hv,acc_v,dt),limit_h.min,limit_h.max);
|
|
|
- SendMoveCmd(move_mode_,Monitor_emqx::eHorizontal,velocity , 0);
|
|
|
- actionType_=eHorizon;
|
|
|
- printf(" Horizontal input:%f out:%f\n",timedV_.Get(),velocity);
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
- if (action == 3) {
|
|
|
- if (Pose2d::abs(diff).x() > thresh.x()) {
|
|
|
- double v=limit_gause(diff.x(),limit_v.min,limit_v.max);
|
|
|
- double velocity=limit(next_speed(timedV_.Get(),v,acc_v,dt),limit_v.min,limit_v.max);
|
|
|
- SendMoveCmd(move_mode_,Monitor_emqx::eMPC, velocity, 0);
|
|
|
- actionType_=eVertical;
|
|
|
- printf(" Vrtical input:%f,out:%f diff.x:%f\n",timedV_.Get(),velocity,diff.x());
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
- if(Stop()) {
|
|
|
- printf(" monitor type :%d completed!!! reset action type!!!\n", action);
|
|
|
- action = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return false;
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
bool Navigation::RotateReferToTarget(const Pose2d& target,stLimit limit_rotate,bool anyDirect) {
|
|
|
|
|
|
while(cancel_==false) {
|
|
@@ -586,24 +471,9 @@ bool Navigation::execute_nodes(NavMessage::NewAction action)
|
|
|
bool anyDirect=(action.type()==3);
|
|
|
|
|
|
//速度限制
|
|
|
- stLimit adjust_x={ action.adjustvelocitylimit().min(),action.adjustvelocitylimit().max() };
|
|
|
- stLimit adjust_h={ action.adjusthorizonlimit().min(),action.adjusthorizonlimit().max() };
|
|
|
stLimit adjust_angular={ action.nodeangularlimit().min(),action.nodeangularlimit().max() };
|
|
|
stLimit mpc_velocity={ action.nodevelocitylimit().min(),action.nodevelocitylimit().max() };
|
|
|
|
|
|
- /*原地调整起点
|
|
|
- NavMessage::PathNode first=action.pathnodes(0);
|
|
|
-
|
|
|
- //目标,精度
|
|
|
- double first_yaw=timedPose_.Get().theta();
|
|
|
- if(1<action.pathnodes_size()){
|
|
|
- NavMessage::PathNode next=action.pathnodes(1);
|
|
|
- first_yaw=Pose2d::vector2yaw(next.pose().x()-first.pose().x(),next.pose().y()-first.pose().y());
|
|
|
- }
|
|
|
- Pose2d first_target(first.pose().x(),first.pose().y(),first_yaw);
|
|
|
- Pose2d first_accuracy(first.accuracy().x(),first.accuracy().y(),first.accuracy().theta());
|
|
|
- execute_adjust_action(first_target,first_accuracy,adjust_x,adjust_h,adjust_angular,anyDirect);
|
|
|
- Pose2d last_node=first_target;*/
|
|
|
for(int i=0;i< action.pathnodes_size();++i) {
|
|
|
NavMessage::PathNode node = action.pathnodes(i);
|
|
|
/// 巡线到目标点,判断巡线方向
|
|
@@ -641,40 +511,8 @@ bool Navigation::execute_nodes(NavMessage::NewAction action)
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-bool Navigation::execute_vehicle_mode(NavMessage::NewAction action){
|
|
|
- if(action.type()==5 ) //最优动作导航 or 导航中保证朝向严格一致
|
|
|
- {
|
|
|
- if (!action.has_nodevelocitylimit() || !action.has_nodeangularlimit() ||
|
|
|
- !action.has_adjustvelocitylimit() || !action.has_adjusthorizonlimit()
|
|
|
- || action.pathnodes_size() == 0) {
|
|
|
- std::cout << "execute pathNodes failed ,Action invalid:" << action.DebugString() << std::endl;
|
|
|
- return false;
|
|
|
-
|
|
|
- //原地调整起点
|
|
|
- NavMessage::PathNode first=action.pathnodes(0);
|
|
|
- //速度限制
|
|
|
- stLimit adjust_x={ action.adjustvelocitylimit().min(),action.adjustvelocitylimit().max() };
|
|
|
- stLimit adjust_h={ action.adjusthorizonlimit().min(),action.adjusthorizonlimit().max() };
|
|
|
- stLimit adjust_angular={ action.nodeangularlimit().min(),action.nodeangularlimit().max() };
|
|
|
- stLimit mpc_velocity={ action.nodevelocitylimit().min(),action.nodevelocitylimit().max() };
|
|
|
- //目标,精度
|
|
|
- double first_yaw=timedPose_.Get().theta();
|
|
|
- if(1<action.pathnodes_size()){
|
|
|
- NavMessage::PathNode next=action.pathnodes(1);
|
|
|
- first_yaw=Pose2d::vector2yaw(next.pose().x()-first.pose().x(),next.pose().y()-first.pose().y());
|
|
|
- }
|
|
|
- Pose2d first_target(first.pose().x(),first.pose().y(),first_yaw);
|
|
|
- Pose2d first_accuracy(first.accuracy().x(),first.accuracy().y(),first.accuracy().theta());
|
|
|
- //execute_adjust_action(first_target,first_accuracy,adjust_x,adjust_h,adjust_angular,anyDirect);
|
|
|
- return false;
|
|
|
- }
|
|
|
- }else{
|
|
|
- return false;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
bool Navigation::execute_InOut_space(NavMessage::NewAction action) {
|
|
|
- if (action.type() != 1 && action.type() != 2) {
|
|
|
+ /*if (action.type() != 1 && action.type() != 2) {
|
|
|
printf(" Inout_space failed : msg action type must ==1\n ");
|
|
|
return false;
|
|
|
}
|
|
@@ -739,7 +577,7 @@ bool Navigation::execute_InOut_space(NavMessage::NewAction action) {
|
|
|
return false;
|
|
|
|
|
|
if (execute_along_action(begin, target, target_accuracy, mpc_velocity, true) == false)
|
|
|
- return false;
|
|
|
+ return false;*/
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -819,7 +657,7 @@ bool Navigation::IsArrived(const Pose2d& cur,double velocity,double angular,
|
|
|
const Pose2d& target,const Pose2d& diff,int direct)
|
|
|
{
|
|
|
//std::cout<<cur<<","<<target<<","<<nearest_yaw<<",v"<<velocity<<"a:"<<angular<<"diff:"<<diff<<std::endl;
|
|
|
- Pose2d distance=Pose2d::relativePose(target,cur);
|
|
|
+ Pose2d distance=target-cur;
|
|
|
Pose2d absDiff=Pose2d::abs(distance);
|
|
|
|
|
|
//std::cout<<" arrive distanc:"<<distance<<",direct:"<<direct<<std::endl;
|
|
@@ -858,11 +696,10 @@ bool Navigation::IsArrived(const Pose2d& cur,double velocity,double angular,
|
|
|
const Pose2d& target,const Pose2d& diff)
|
|
|
{
|
|
|
//std::cout<<cur<<","<<target<<","<<nearest_yaw<<",v"<<velocity<<"a:"<<angular<<"diff:"<<diff<<std::endl;
|
|
|
- Pose2d distance=Pose2d::relativePose(target,cur);
|
|
|
+ Pose2d distance=target-cur;
|
|
|
Pose2d absDiff=Pose2d::abs(distance);
|
|
|
|
|
|
//std::cout<<" arrive distanc:"<<distance<<",direct:"<<direct<<std::endl;
|
|
|
-
|
|
|
if(absDiff.x()<diff.x() && absDiff.y()<diff.y())
|
|
|
{
|
|
|
if(fabs(velocity) < 0.06 && fabs(angular) < 5 * M_PI / 180.0)
|
|
@@ -964,10 +801,8 @@ Navigation::MpcResult Navigation::execute_along_action(const Pose2d& begin,const
|
|
|
return eMpcFailed;
|
|
|
}
|
|
|
//判断是否到达终点
|
|
|
- Pose2d target_accuracy=target_diff;
|
|
|
- if(directY)
|
|
|
- target_accuracy=Pose2d::abs(target_diff.rotate(timedPose_.Get().theta()));
|
|
|
- if (IsArrived(timedPose_.Get(), timedV_.Get(), timedA_.Get(), target, Pose2d::abs(target_accuracy),2)) {
|
|
|
+ Pose2d target_accuracy=Pose2d::abs(target_diff);
|
|
|
+ if (IsArrived(timedPose_.Get(), timedV_.Get(), timedA_.Get(), target, Pose2d::abs(target_accuracy))) {
|
|
|
if (Stop()) {
|
|
|
printf(" exec along completed !!!\n");
|
|
|
return eMpcSuccess;
|
|
@@ -1007,21 +842,11 @@ Navigation::MpcResult Navigation::execute_along_action(const Pose2d& begin,const
|
|
|
* 判断车辆是否在终点附近徘徊,无法到达终点
|
|
|
*/
|
|
|
if (mpc_possible_to_end(target, target_accuracy,directY) == false) {
|
|
|
- printf(" --------------MPC imposible to target -----------------------\n");
|
|
|
+ printf(" --------------MPC imposible to target -------------------------------------------\n");
|
|
|
if(fabs(timedV_.Get())>0.1 || fabs(timedA_.Get())>5*M_PI/180.0)
|
|
|
Stop();
|
|
|
return eImpossibleToTarget;
|
|
|
- //调整到目标点
|
|
|
- /*stLimit limitv, limitR;
|
|
|
- limitv.min = 0.05;
|
|
|
- limitv.max = 0.1;
|
|
|
- limitR.min = 2 * M_PI / 180.0;
|
|
|
- limitR.max = 10 * M_PI / 180.0;
|
|
|
- Pose2d accuracy(target_diff.x(),target_diff.y(),M_PI*2);
|
|
|
- if (execute_adjust_action(target, accuracy, limitv, limitv, limitR,false))
|
|
|
- return true;
|
|
|
- else
|
|
|
- return false;*/
|
|
|
+
|
|
|
}
|
|
|
|
|
|
//std::this_thread::sleep_for(std::chrono::milliseconds (400));
|
|
@@ -1030,32 +855,26 @@ Navigation::MpcResult Navigation::execute_along_action(const Pose2d& begin,const
|
|
|
return eMpcFailed;
|
|
|
}
|
|
|
|
|
|
-bool Navigation::mpc_possible_to_end(const Pose2d& target,const Pose2d& target_diff,bool directY)
|
|
|
-{
|
|
|
-
|
|
|
- if(timedPose_.timeout()==false) {
|
|
|
+bool Navigation::mpc_possible_to_end(const Pose2d& target,const Pose2d& target_diff,bool directY) {
|
|
|
+ if (timedPose_.timeout() == false) {
|
|
|
|
|
|
Pose2d current = timedPose_.Get();
|
|
|
- Pose2d targetInPose = Pose2d::relativePose(target, current);
|
|
|
- //std::cout<<" target in pose:"<<targetInPose<<", target diff:"<<target_diff<<std::endl;
|
|
|
if (directY) {
|
|
|
- targetInPose=targetInPose.rotate(M_PI / 2.0);
|
|
|
+ current = current.rotate(current.x(), current.y(), M_PI / 2.0);
|
|
|
}
|
|
|
- if (fabs(targetInPose.x()) < target_diff.x()) {
|
|
|
- if (fabs(targetInPose.y()) > target_diff.y())
|
|
|
- return false;
|
|
|
- else
|
|
|
- return true;
|
|
|
- } else {
|
|
|
- float y=fabs(targetInPose.y())-fabs(target_diff.y());
|
|
|
- if(y<0) y=0;
|
|
|
- Pose2d minTarget(targetInPose.x(),y,0);
|
|
|
- float cuv=compute_cuv(minTarget);
|
|
|
- if(cuv>15*M_PI/180.0)
|
|
|
- return false;
|
|
|
- return true;
|
|
|
+ Pose2d targetInPose = Pose2d::relativePose(target, current);
|
|
|
+ Pose2d accuracy = Pose2d::abs(target_diff.rotate(current.theta()));
|
|
|
+
|
|
|
+ float y = fabs(targetInPose.y()) - fabs(accuracy.y());
|
|
|
+ if (y < 0) y = 0;
|
|
|
+ Pose2d minTarget(fabs(targetInPose.x()), y, 0);
|
|
|
+ float cuv = compute_cuv(minTarget);
|
|
|
+ if (cuv > 15 * M_PI / 180.0) {
|
|
|
+ std::cout<<"targetInPose:"<<targetInPose<<", target diff:"<<target_diff<<", accuracy:"<<accuracy<<std::endl;
|
|
|
+ return false;
|
|
|
}
|
|
|
- }else{
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
return false;
|
|
|
}
|
|
|
|