1
0

9 Коммиты 038379d589 ... 7487017f84

Автор SHA1 Сообщение Дата
  gf 7487017f84 1.添加打印 1 год назад
  gf 462ac47766 1.添加指令流程类型(存取车) 1 год назад
  gf b474d9cb74 1.马路点巡航时,同时进行提升机构动作 1 год назад
  gf 46c5b4fb75 1.优化mpc unknown时,下发反馈速度 1 год назад
  gf 645e4cd04b 1.雷达反馈位姿超时由1.0s延长至1.2s 1 год назад
  gf a594ebb980 1.前中后三段角速度权重1:3:6 1 год назад
  gf 35e5f2dba3 1.取消取车流程,送车到出口前旋转180动作,添加存车流程离开入口,掉头 1 год назад
  gf e565d37cfe 1.优化mpc计算unknown时,下发反馈的实时速度 1 год назад
  gf aa992c5816 1.屏蔽进出库(包括出入口),实时判断载车板或者门控信号 1 год назад

+ 12 - 1
MPC/custom_type.h

@@ -63,7 +63,8 @@ private:
 enum MpcError {
     success = 0,
     no_solution = 1,
-    failed
+    failed = 2,
+    unknown
 };
 //////////////////////////////////////////////////
 
@@ -126,6 +127,16 @@ enum eClamLiftActionType{
 };
 //////////////////////////////////////////////////
 
+//////////////////////////////////////////////////
+/// 指令流程类型
+enum eSequenceType{
+    eSequenceDefault = 0,
+    eSequencePark = 1,
+    eSequencePick = 2
+};
+//////////////////////////////////////////////////
+
+
 //////////////////////////////////////////////////
 /// plc区域+编号载车板 对应 车位表
 enum eRegionId{

+ 11 - 7
MPC/loaded_mpc.cpp

@@ -81,14 +81,14 @@ public:
         for (int t = 0; t < N - 1; t++) {
             //角速度,加速度,角加速度 weight loss
             fg[0] += vth_cost_weight * CppAD::pow(vars[ndlt + t], 2);
-            if(t > N / 3){//前中后三段角速度权重1:2:3
-                fg[0] += vth_cost_weight * CppAD::pow(vars[ndlt + t], 2);
+            if(t > N / 3){//前中后三段角速度权重1:3:6
+                fg[0] += 2*vth_cost_weight * CppAD::pow(vars[ndlt + t], 2);
             }
-            if(t > N / 3 * 2){//前中后三段角速度权重1:2:3
-                fg[0] += vth_cost_weight * CppAD::pow(vars[ndlt + t], 2);
+            if(t > N / 3 * 2){//前中后三段角速度权重1:3:6
+                fg[0] += 5*vth_cost_weight * CppAD::pow(vars[ndlt + t], 2);
             }
             fg[0] += a_cost_weight * CppAD::pow(vars[nv + t + 1] - vars[nv + t], 2);
-            fg[0] += ath_cost_weight * CppAD::pow(vars[ndlt + t + 1] - vars[ndlt + t], 2);
+//            fg[0] += ath_cost_weight * CppAD::pow(vars[ndlt + t + 1] - vars[ndlt + t], 2);
         }
 
         /////////////////////
@@ -172,7 +172,7 @@ MpcError LoadedMPC::solve(Trajectory trajectory, Pose2d target, Eigen::VectorXd
     double wmg = statu[4];
 
 
-    size_t N=15;//int(10./(1+exp(-16.*(fabs(line_velocity)-0.5)))+10);
+    size_t N=19;//int(10./(1+exp(-16.*(fabs(line_velocity)-0.5)))+10);
     size_t nx = 0;
     size_t ny = nx + N;
     size_t nth = ny + N;
@@ -225,7 +225,9 @@ MpcError LoadedMPC::solve(Trajectory trajectory, Pose2d target, Eigen::VectorXd
     double max_acc_line_velocity = mpc_param.acc_velocity*acc_sigmoid;
     double max_acc_dlt = mpc_param.acc_angular;
 
-    double ref_velocity = 0.5*dis*dis+min_velocity_;//max_velocity_/(1+exp(-4.*(dis-0.8)))+min_velocity_;
+    double ref1=sqrt(0.5*dis/mpc_param.acc_velocity)+min_velocity_;
+    double ref2=2.5/(1.+exp(-2.5*(dis-1.1)))-0.15+min_velocity_;
+    double ref_velocity = std::min(ref1,ref2);//max_velocity_/(1+exp(-4.*(dis-0.8)))+min_velocity_;
 
     Pose2d targetPoseInAGV = Pose2d::relativePose(target, pose_agv);
     //std::cout<<"target:"<<target<<", agv:"<<pose_agv<<", relative:"<<targetPoseInAGV<<std::endl;
@@ -370,6 +372,8 @@ MpcError LoadedMPC::solve(Trajectory trajectory, Pose2d target, Eigen::VectorXd
                wmg, angular, max_velocity_);
         if (solution.status == CppAD::ipopt::solve_result<Dvector>::local_infeasibility)
             return no_solution;
+        if (solution.status == CppAD::ipopt::solve_result<Dvector>::unknown)
+            return unknown;
         return failed;
     }
 

+ 95 - 35
MPC/monitor/emqx/message.pb.cc

@@ -212,14 +212,17 @@ PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT
 template <typename>
 PROTOBUF_CONSTEXPR NavCmd::NavCmd(
     ::_pbi::ConstantInitialized): _impl_{
-    /*decltype(_impl_.newactions_)*/{}
+    /*decltype(_impl_._has_bits_)*/{}
+  , /*decltype(_impl_._cached_size_)*/{}
+  , /*decltype(_impl_.newactions_)*/{}
   , /*decltype(_impl_.key_)*/ {
     &::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized {}
   }
 
   , /*decltype(_impl_.action_)*/ 0
 
-  , /*decltype(_impl_._cached_size_)*/{}} {}
+  , /*decltype(_impl_.sequence_)*/ 0
+} {}
 struct NavCmdDefaultTypeInternal {
   PROTOBUF_CONSTEXPR NavCmdDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {}
   ~NavCmdDefaultTypeInternal() {}
@@ -451,7 +454,7 @@ const ::uint32_t TableStruct_message_2eproto::offsets[] PROTOBUF_SECTION_VARIABL
     ~0u,
     ~0u,
     ~0u,
-    ~0u,  // no _has_bits_
+    PROTOBUF_FIELD_OFFSET(::NavMessage::NavCmd, _impl_._has_bits_),
     PROTOBUF_FIELD_OFFSET(::NavMessage::NavCmd, _internal_metadata_),
     ~0u,  // no _extensions_
     ~0u,  // no _oneof_case_
@@ -462,6 +465,11 @@ const ::uint32_t TableStruct_message_2eproto::offsets[] PROTOBUF_SECTION_VARIABL
     PROTOBUF_FIELD_OFFSET(::NavMessage::NavCmd, _impl_.action_),
     PROTOBUF_FIELD_OFFSET(::NavMessage::NavCmd, _impl_.key_),
     PROTOBUF_FIELD_OFFSET(::NavMessage::NavCmd, _impl_.newactions_),
+    PROTOBUF_FIELD_OFFSET(::NavMessage::NavCmd, _impl_.sequence_),
+    ~0u,
+    ~0u,
+    ~0u,
+    0,
     ~0u,  // no _has_bits_
     PROTOBUF_FIELD_OFFSET(::NavMessage::NavResponse, _internal_metadata_),
     ~0u,  // no _extensions_
@@ -536,11 +544,11 @@ static const ::_pbi::MigrationSchema
         { 64, 78, -1, sizeof(::NavMessage::PathNode)},
         { 84, -1, -1, sizeof(::NavMessage::Trajectory)},
         { 93, 108, -1, sizeof(::NavMessage::NewAction)},
-        { 115, -1, -1, sizeof(::NavMessage::NavCmd)},
-        { 126, -1, -1, sizeof(::NavMessage::NavResponse)},
-        { 136, -1, -1, sizeof(::NavMessage::ManualCmd)},
-        { 147, 164, -1, sizeof(::NavMessage::NavStatu)},
-        { 173, 185, -1, sizeof(::NavMessage::RobotStatu)},
+        { 115, 127, -1, sizeof(::NavMessage::NavCmd)},
+        { 131, -1, -1, sizeof(::NavMessage::NavResponse)},
+        { 141, -1, -1, sizeof(::NavMessage::ManualCmd)},
+        { 152, 169, -1, sizeof(::NavMessage::NavStatu)},
+        { 178, 190, -1, sizeof(::NavMessage::RobotStatu)},
 };
 
 static const ::_pb::Message* const file_default_instances[] = {
@@ -579,32 +587,33 @@ const char descriptor_table_protodef_message_2eproto[] PROTOBUF_SECTION_VARIABLE
     "\030\003 \001(\0132\024.NavMessage.PathNode\022(\n\nstreetNo"
     "de\030\004 \001(\0132\024.NavMessage.PathNode\022\'\n\tpathNo"
     "des\030\005 \003(\0132\024.NavMessage.PathNode\022\021\n\twheel"
-    "base\030\006 \001(\002\022\023\n\013changedMode\030\007 \001(\005\"P\n\006NavCm"
+    "base\030\006 \001(\002\022\023\n\013changedMode\030\007 \001(\005\"t\n\006NavCm"
     "d\022\016\n\006action\030\001 \001(\005\022\013\n\003key\030\002 \001(\t\022)\n\nnewAct"
-    "ions\030\005 \003(\0132\025.NavMessage.NewAction\"(\n\013Nav"
-    "Response\022\013\n\003ret\030\001 \001(\005\022\014\n\004info\030\002 \001(\t\"B\n\tM"
-    "anualCmd\022\013\n\003key\030\001 \001(\t\022\026\n\016operation_type\030"
-    "\002 \001(\005\022\020\n\010velocity\030\003 \001(\002\"\366\001\n\010NavStatu\022\r\n\005"
-    "statu\030\001 \001(\005\022\020\n\010main_agv\030\002 \001(\010\022\021\n\tmove_mo"
-    "de\030\003 \001(\005\022(\n\004odom\030\004 \001(\0132\032.NavMessage.Lida"
-    "rOdomStatu\022\013\n\003key\030\005 \001(\t\022-\n\rselected_traj"
-    "\030\006 \001(\0132\026.NavMessage.Trajectory\022,\n\014predic"
-    "t_traj\030\007 \001(\0132\026.NavMessage.Trajectory\022\020\n\010"
-    "in_space\030\010 \001(\010\022\020\n\010space_id\030\t \001(\t\"Y\n\nRobo"
-    "tStatu\022\t\n\001x\030\001 \001(\002\022\t\n\001y\030\002 \001(\002\022\r\n\005theta\030\003 "
-    "\001(\002\022&\n\010agvStatu\030\004 \001(\0132\024.NavMessage.AgvSt"
-    "atu2\302\001\n\nNavExcutor\0226\n\005Start\022\022.NavMessage"
-    ".NavCmd\032\027.NavMessage.NavResponse\"\000\0227\n\006Ca"
-    "ncel\022\022.NavMessage.NavCmd\032\027.NavMessage.Na"
-    "vResponse\"\000\022C\n\017ManualOperation\022\025.NavMess"
-    "age.ManualCmd\032\027.NavMessage.NavResponse\"\000"
-    "b\006proto3"
+    "ions\030\005 \003(\0132\025.NavMessage.NewAction\022\025\n\010seq"
+    "uence\030\006 \001(\005H\000\210\001\001B\013\n\t_sequence\"(\n\013NavResp"
+    "onse\022\013\n\003ret\030\001 \001(\005\022\014\n\004info\030\002 \001(\t\"B\n\tManua"
+    "lCmd\022\013\n\003key\030\001 \001(\t\022\026\n\016operation_type\030\002 \001("
+    "\005\022\020\n\010velocity\030\003 \001(\002\"\366\001\n\010NavStatu\022\r\n\005stat"
+    "u\030\001 \001(\005\022\020\n\010main_agv\030\002 \001(\010\022\021\n\tmove_mode\030\003"
+    " \001(\005\022(\n\004odom\030\004 \001(\0132\032.NavMessage.LidarOdo"
+    "mStatu\022\013\n\003key\030\005 \001(\t\022-\n\rselected_traj\030\006 \001"
+    "(\0132\026.NavMessage.Trajectory\022,\n\014predict_tr"
+    "aj\030\007 \001(\0132\026.NavMessage.Trajectory\022\020\n\010in_s"
+    "pace\030\010 \001(\010\022\020\n\010space_id\030\t \001(\t\"Y\n\nRobotSta"
+    "tu\022\t\n\001x\030\001 \001(\002\022\t\n\001y\030\002 \001(\002\022\r\n\005theta\030\003 \001(\002\022"
+    "&\n\010agvStatu\030\004 \001(\0132\024.NavMessage.AgvStatu2"
+    "\302\001\n\nNavExcutor\0226\n\005Start\022\022.NavMessage.Nav"
+    "Cmd\032\027.NavMessage.NavResponse\"\000\0227\n\006Cancel"
+    "\022\022.NavMessage.NavCmd\032\027.NavMessage.NavRes"
+    "ponse\"\000\022C\n\017ManualOperation\022\025.NavMessage."
+    "ManualCmd\032\027.NavMessage.NavResponse\"\000b\006pr"
+    "oto3"
 };
 static ::absl::once_flag descriptor_table_message_2eproto_once;
 const ::_pbi::DescriptorTable descriptor_table_message_2eproto = {
     false,
     false,
-    1608,
+    1644,
     descriptor_table_protodef_message_2eproto,
     "message.proto",
     &descriptor_table_message_2eproto_once,
@@ -3428,6 +3437,12 @@ void NewAction::InternalSwap(NewAction* other) {
 
 class NavCmd::_Internal {
  public:
+  using HasBits = decltype(std::declval<NavCmd>()._impl_._has_bits_);
+  static constexpr ::int32_t kHasBitsOffset =
+    8 * PROTOBUF_FIELD_OFFSET(NavCmd, _impl_._has_bits_);
+  static void set_has_sequence(HasBits* has_bits) {
+    (*has_bits)[0] |= 1u;
+  }
 };
 
 NavCmd::NavCmd(::PROTOBUF_NAMESPACE_ID::Arena* arena)
@@ -3439,12 +3454,15 @@ NavCmd::NavCmd(const NavCmd& from)
   : ::PROTOBUF_NAMESPACE_ID::Message() {
   NavCmd* const _this = this; (void)_this;
   new (&_impl_) Impl_{
-      decltype(_impl_.newactions_){from._impl_.newactions_}
+      decltype(_impl_._has_bits_){from._impl_._has_bits_}
+    , /*decltype(_impl_._cached_size_)*/{}
+    , decltype(_impl_.newactions_){from._impl_.newactions_}
     , decltype(_impl_.key_) {}
 
     , decltype(_impl_.action_) {}
 
-    , /*decltype(_impl_._cached_size_)*/{}};
+    , decltype(_impl_.sequence_) {}
+  };
 
   _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
   _impl_.key_.InitDefault();
@@ -3454,19 +3472,24 @@ NavCmd::NavCmd(const NavCmd& from)
   if (!from._internal_key().empty()) {
     _this->_impl_.key_.Set(from._internal_key(), _this->GetArenaForAllocation());
   }
-  _this->_impl_.action_ = from._impl_.action_;
+  ::memcpy(&_impl_.action_, &from._impl_.action_,
+    static_cast<::size_t>(reinterpret_cast<char*>(&_impl_.sequence_) -
+    reinterpret_cast<char*>(&_impl_.action_)) + sizeof(_impl_.sequence_));
   // @@protoc_insertion_point(copy_constructor:NavMessage.NavCmd)
 }
 
 inline void NavCmd::SharedCtor(::_pb::Arena* arena) {
   (void)arena;
   new (&_impl_) Impl_{
-      decltype(_impl_.newactions_){arena}
+      decltype(_impl_._has_bits_){}
+    , /*decltype(_impl_._cached_size_)*/{}
+    , decltype(_impl_.newactions_){arena}
     , decltype(_impl_.key_) {}
 
     , decltype(_impl_.action_) { 0 }
 
-    , /*decltype(_impl_._cached_size_)*/{}
+    , decltype(_impl_.sequence_) { 0 }
+
   };
   _impl_.key_.InitDefault();
   #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
@@ -3502,11 +3525,14 @@ void NavCmd::Clear() {
   _internal_mutable_newactions()->Clear();
   _impl_.key_.ClearToEmpty();
   _impl_.action_ = 0;
+  _impl_.sequence_ = 0;
+  _impl_._has_bits_.Clear();
   _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
 }
 
 const char* NavCmd::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
 #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
+  _Internal::HasBits has_bits{};
   while (!ctx->Done(&ptr)) {
     ::uint32_t tag;
     ptr = ::_pbi::ReadTag(ptr, &tag);
@@ -3545,6 +3571,16 @@ const char* NavCmd::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
           goto handle_unusual;
         }
         continue;
+      // optional int32 sequence = 6;
+      case 6:
+        if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 48)) {
+          _Internal::set_has_sequence(&has_bits);
+          _impl_.sequence_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr);
+          CHK_(ptr);
+        } else {
+          goto handle_unusual;
+        }
+        continue;
       default:
         goto handle_unusual;
     }  // switch
@@ -3561,6 +3597,7 @@ const char* NavCmd::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
     CHK_(ptr != nullptr);
   }  // while
 message_done:
+  _impl_._has_bits_.Or(has_bits);
   return ptr;
 failure:
   ptr = nullptr;
@@ -3597,6 +3634,14 @@ failure:
         InternalWriteMessage(5, repfield, repfield.GetCachedSize(), target, stream);
   }
 
+  cached_has_bits = _impl_._has_bits_[0];
+  // optional int32 sequence = 6;
+  if (cached_has_bits & 0x00000001u) {
+    target = stream->EnsureSpace(target);
+    target = ::_pbi::WireFormatLite::WriteInt32ToArray(
+        6, this->_internal_sequence(), target);
+  }
+
   if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
     target = ::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray(
         _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);
@@ -3632,6 +3677,13 @@ failure:
         this->_internal_action());
   }
 
+  // optional int32 sequence = 6;
+  cached_has_bits = _impl_._has_bits_[0];
+  if (cached_has_bits & 0x00000001u) {
+    total_size += ::_pbi::WireFormatLite::Int32SizePlusOne(
+        this->_internal_sequence());
+  }
+
   return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_);
 }
 
@@ -3657,6 +3709,9 @@ void NavCmd::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBU
   if (from._internal_action() != 0) {
     _this->_internal_set_action(from._internal_action());
   }
+  if ((from._impl_._has_bits_[0] & 0x00000001u) != 0) {
+    _this->_internal_set_sequence(from._internal_sequence());
+  }
   _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
 }
 
@@ -3676,11 +3731,16 @@ void NavCmd::InternalSwap(NavCmd* other) {
   auto* lhs_arena = GetArenaForAllocation();
   auto* rhs_arena = other->GetArenaForAllocation();
   _internal_metadata_.InternalSwap(&other->_internal_metadata_);
+  swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]);
   _internal_mutable_newactions()->InternalSwap(other->_internal_mutable_newactions());
   ::_pbi::ArenaStringPtr::InternalSwap(&_impl_.key_, lhs_arena,
                                        &other->_impl_.key_, rhs_arena);
-
-  swap(_impl_.action_, other->_impl_.action_);
+  ::PROTOBUF_NAMESPACE_ID::internal::memswap<
+      PROTOBUF_FIELD_OFFSET(NavCmd, _impl_.sequence_)
+      + sizeof(NavCmd::_impl_.sequence_)
+      - PROTOBUF_FIELD_OFFSET(NavCmd, _impl_.action_)>(
+          reinterpret_cast<char*>(&_impl_.action_),
+          reinterpret_cast<char*>(&other->_impl_.action_));
 }
 
 ::PROTOBUF_NAMESPACE_ID::Metadata NavCmd::GetMetadata() const {

+ 40 - 1
MPC/monitor/emqx/message.pb.h

@@ -1862,6 +1862,7 @@ class NavCmd final :
     kNewActionsFieldNumber = 5,
     kKeyFieldNumber = 2,
     kActionFieldNumber = 1,
+    kSequenceFieldNumber = 6,
   };
   // repeated .NavMessage.NewAction newActions = 5;
   int newactions_size() const;
@@ -1912,6 +1913,17 @@ class NavCmd final :
   ::int32_t _internal_action() const;
   void _internal_set_action(::int32_t value);
 
+  public:
+  // optional int32 sequence = 6;
+  bool has_sequence() const;
+  void clear_sequence() ;
+  ::int32_t sequence() const;
+  void set_sequence(::int32_t value);
+
+  private:
+  ::int32_t _internal_sequence() const;
+  void _internal_set_sequence(::int32_t value);
+
   public:
   // @@protoc_insertion_point(class_scope:NavMessage.NavCmd)
  private:
@@ -1921,10 +1933,12 @@ class NavCmd final :
   typedef void InternalArenaConstructable_;
   typedef void DestructorSkippable_;
   struct Impl_ {
+    ::PROTOBUF_NAMESPACE_ID::internal::HasBits<1> _has_bits_;
+    mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
     ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::NavMessage::NewAction > newactions_;
     ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr key_;
     ::int32_t action_;
-    mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
+    ::int32_t sequence_;
   };
   union { Impl_ _impl_; };
   friend struct ::TableStruct_message_2eproto;
@@ -4181,6 +4195,31 @@ NavCmd::_internal_mutable_newactions() {
   return &_impl_.newactions_;
 }
 
+// optional int32 sequence = 6;
+inline bool NavCmd::has_sequence() const {
+  bool value = (_impl_._has_bits_[0] & 0x00000001u) != 0;
+  return value;
+}
+inline void NavCmd::clear_sequence() {
+  _impl_.sequence_ = 0;
+  _impl_._has_bits_[0] &= ~0x00000001u;
+}
+inline ::int32_t NavCmd::sequence() const {
+  // @@protoc_insertion_point(field_get:NavMessage.NavCmd.sequence)
+  return _internal_sequence();
+}
+inline void NavCmd::set_sequence(::int32_t value) {
+  _internal_set_sequence(value);
+  // @@protoc_insertion_point(field_set:NavMessage.NavCmd.sequence)
+}
+inline ::int32_t NavCmd::_internal_sequence() const {
+  return _impl_.sequence_;
+}
+inline void NavCmd::_internal_set_sequence(::int32_t value) {
+  _impl_._has_bits_[0] |= 0x00000001u;
+  _impl_.sequence_ = value;
+}
+
 // -------------------------------------------------------------------
 
 // NavResponse

+ 171 - 57
MPC/navigation.cpp

@@ -275,7 +275,7 @@ void Navigation::ResetLifter(LifterStatus status) {
 
 
 void Navigation::ResetPose(const Pose2d &pose) {
-    timedPose_.reset(pose, 1.0);
+    timedPose_.reset(pose, 1.2);
     if (pose.theta() > 0) {
         if (parameter_.main_agv()) {
             isFront_.reset(true, 1.0);
@@ -592,8 +592,6 @@ bool Navigation::MoveToTarget(NavMessage::PathNode node, Navigation::stLimit lim
         return true;
     }
     bool already_in_mpc = false;
-    int retry_count = 0;
-    int retry_count_limit = 3;
     while (cancel_ == false) {
         std::this_thread::sleep_for(std::chrono::milliseconds(100));
         if (PoseTimeout()) {
@@ -638,9 +636,7 @@ bool Navigation::MoveToTarget(NavMessage::PathNode node, Navigation::stLimit lim
             printf(" MPC to target:%f %f l:%f,w:%f theta:%f  impossible ,retry ...\n",
                    node.x(), node.y(), node.l(), node.w(), node.theta());
         } else {
-            retry_count++;
-            if (retry_count > retry_count_limit)
-                return false;
+
         }
     }
     if (cancel_) {
@@ -666,8 +662,6 @@ bool Navigation::execute_nodes(NavMessage::NewAction action) {
         int clampLifterAction = 0;
         if (move_mode_ == eSingle) {
             clampLifterAction |= eByteClampHalfOpen;
-        } else {
-            clampLifterAction |= eByteLifterDown;
         }
         ////////////////////////////////////////////////////////////
         for (int i = 0; i < action.pathnodes_size(); ++i) {
@@ -677,13 +671,13 @@ bool Navigation::execute_nodes(NavMessage::NewAction action) {
                 Pose2d vec(next.x() - node.x(), next.y() - node.y(), 0);
                 node.set_theta(Pose2d::vector2yaw(vec.x(), vec.y()) + M_PI / 2.0);
                 node.set_l(0.03);
-                node.set_w(0.20);
+                node.set_w(0.25);
             } else {
                 NavMessage::PathNode befor = action.pathnodes(i - 1);
                 Pose2d vec(node.x() - befor.x(), node.y() - befor.y(), 0);
                 node.set_theta(Pose2d::vector2yaw(vec.x(), vec.y()));
                 node.set_l(0.02);
-                node.set_w(0.2);
+                node.set_w(0.25);
             }
             int directions = Direction::eForward;
             if (anyDirect)
@@ -716,6 +710,18 @@ bool Navigation::execute_nodes(NavMessage::NewAction action) {
                 }
             }*/
 
+            //提升机构提前动作
+            if (GetRemainActionsCount() > 1){
+                NavMessage::NewAction last_action = GetLastAction();
+                if (IsUperSpace(last_action.spacenode())){
+                    if ((i+1) == action.pathnodes_size()){
+                        clampLifterAction |= eByteLifterUp;
+                    }
+                } else{
+                    clampLifterAction |= eByteLifterDown;
+                }
+            }
+
             if (MoveToTarget(node, mpc_velocity, wmg_limit, anyDirect, true, clampLifterAction) == false)
                 return false;
             else
@@ -782,6 +788,50 @@ Navigation::MpcResult Navigation::DoubleOutSpaceCorrectTheta() {
     return eMpcFailed;
 }
 
+Navigation::MpcResult Navigation::RotateAfterOutExport() {
+    printf("RotateAfterOutExport...\n");
+    if (move_mode_ != eDouble)
+        return eMpcSuccess;
+    Pose2d init = timedPose_.Get();
+    double diff1 = fabs(M_PI / 2.0 - init.theta());
+    double diff2 = fabs(-M_PI / 2.0 - init.theta());
+    double target = diff1 > diff2 ? M_PI / 2.0 : -M_PI / 2.0;
+    stLimit limit_rotate = {3 * M_PI / 180.0, 15 * M_PI / 180.0};
+    while (cancel_ == false) {
+        std::this_thread::sleep_for(std::chrono::milliseconds(80));
+        Pose2d current = timedPose_.Get();
+        double yawDiff = (target - current.theta());
+
+        //一次变速
+        std::vector<double> out;
+        bool ret;
+        TimerRecord::Execute([&, this]() {
+            ret = Rotation_mpc_once(Pose2d(0, 0, yawDiff), limit_rotate, out);
+        }, "Rotation_mpc_once");
+        if (ret == false) {
+            Stop();
+            return eMpcFailed;
+        }
+
+        //下发速度
+        if (fabs(yawDiff) < 0.5 * M_PI / 180.0 && fabs(timedA_.Get()) < 5 * M_PI / 180.0) {
+            printf(" RotateBeforeEnterSpace refer target completed\\n,cuv:%f\n", yawDiff);
+            Stop();
+            return eMpcSuccess;
+        } else {
+            const int down_count = 3;
+            double v[down_count] = {0, 0, 0};
+            double w[down_count] = {out[0], out[1], out[2]};
+            SendMoveCmd(0, move_mode_, eRotation, v, w);
+            actionType_ = eRotation;
+//            printf(" RotateBeforeEnterSpace | input anguar:%f, down:%f(%f), diff:%f anyDirect:false\n",
+//                   timedA_.Get(), out[0], out[0] / M_PI * 180, yawDiff);
+        }
+        continue;
+    }
+    return eMpcFailed;
+}
+
 
 Navigation::MpcResult Navigation::RotateBeforeIntoExport() {
     if (move_mode_ != eDouble)
@@ -808,7 +858,7 @@ Navigation::MpcResult Navigation::RotateBeforeIntoExport() {
         }
 
         //下发速度
-        if (fabs(yawDiff) < 0.2 * M_PI / 180.0 && fabs(timedA_.Get()) < 5 * M_PI / 180.0) {
+        if (fabs(yawDiff) < 0.5 * M_PI / 180.0 && fabs(timedA_.Get()) < 5 * M_PI / 180.0) {
             printf(" RotateBeforeEnterSpace refer target completed\\n,cuv:%f\n", yawDiff);
             Stop();
             return eMpcSuccess;
@@ -902,7 +952,7 @@ Navigation::RotateBeforeEnterSpace(NavMessage::PathNode space, double wheelbase,
         }
 
         //下发速度
-        if (fabs(yawDiff) < 0.3 * M_PI / 180.0 && fabs(timedA_.Get()) < 5 * M_PI / 180.0) {
+        if (fabs(yawDiff) < 0.5 * M_PI / 180.0 && fabs(timedA_.Get()) < 5 * M_PI / 180.0) {
             printf(" RotateBeforeEnterSpace refer target completed\\n,cuv:%f\n", yawDiff);
             Stop();
             return eMpcSuccess;
@@ -1003,14 +1053,14 @@ bool Navigation::execute_InOut_space(NavMessage::NewAction action) {
         printf("inout ----------------------------------------\n");
 
         //取车流程,送车到出口前旋转180
-        if (move_mode_ == eDouble && TargetIsExport(action.spacenode()) && GetSpaceId(action.spacenode()) != 1102) {
-            Pose2d current_pose = timedPose_.Get();
-            double current_theta = current_pose.theta();
-            if (RotateBeforeIntoExport() != eMpcSuccess) {
-                printf("Rotate before in entrance failed\n");
-                return false;
-            }
-        }
+//        if (move_mode_ == eDouble && TargetIsExport(action.spacenode()) && GetSpaceId(action.spacenode()) != 1102) {
+//            Pose2d current_pose = timedPose_.Get();
+//            double current_theta = current_pose.theta();
+//            if (RotateBeforeIntoExport() != eMpcSuccess) {
+//                printf("Rotate before in entrance failed\n");
+//                return false;
+//            }
+//        }
 
         //计算车位朝向
         action.mutable_spacenode()->set_theta(Pose2d::vector2yaw(vec.x(), vec.y()));
@@ -1162,6 +1212,20 @@ bool Navigation::execute_InOut_space(NavMessage::NewAction action) {
             return false;
         }
         isInSpace_ = false;
+
+        // 存车流程离开入口,掉头
+        printf("SequenceType: %d\n",GetSequenceType());
+        if (GetSequenceType() == eSequencePark) {
+            if (move_mode_ == eDouble && TargetIsExport(action.spacenode()) && GetSpaceId(action.spacenode()) != 1102) {
+                Pose2d current_pose = timedPose_.Get();
+                double current_theta = current_pose.theta();
+                if (RotateAfterOutExport() != eMpcSuccess) {
+                    printf("Rotate after out entrance failed\n");
+                    return false;
+                }
+            }
+        }
+
         //摆正
         if (GetRemainActionsCount() > 1) {
             if (DoubleOutSpaceCorrectTheta() != eMpcSuccess)
@@ -1233,7 +1297,7 @@ bool Navigation::Rotation_mpc_once(Pose2d current_to_target, Navigation::stLimit
     return ret == success || ret == no_solution;
 }
 
-bool Navigation::mpc_once(Trajectory traj, stLimit limit_v, std::vector<double> &out, bool directY) {
+bool Navigation::mpc_once(Trajectory traj, stLimit limit_v, std::vector<double> &out, int& mpc_result, bool directY) {
     if (PoseTimeout() == true) {
         printf(" MPC once Error:Pose is timeout \n");
         return false;
@@ -1289,13 +1353,14 @@ bool Navigation::mpc_once(Trajectory traj, stLimit limit_v, std::vector<double>
 
     MpcError ret = failed;
     LoadedMPC MPC(relative, obs_w, obs_h, limit_v.min, limit_v.max);
-    // 巡线最大角速度固定0.1745
+    // 巡线最大角速度固定0.1745
     LoadedMPC::MPC_parameter parameter = {mpc_parameter.shortest_radius(), mpc_parameter.dt(),
                                           mpc_parameter.acc_velocity(), 0.1745};
     //printf(" r:%f  dt:%f acc:%f  acc_a:%f\n",mpc_parameter.shortest_radius(),
     //       mpc_parameter.dt(),mpc_parameter.acc_velocity(),mpc_parameter.acc_angular());
     ret = MPC.solve(traj, traj[traj.size() - 1], statu, parameter,
                     out, selected_trajectory, optimize_trajectory, directY);
+    mpc_result = ret;
 
     //std::cout<<" traj size %d  %d -------- "<<selected_trajectory.size()<<","<<optimize_trajectory.size()<<std::endl;
     if (ret == no_solution) {
@@ -1308,6 +1373,18 @@ bool Navigation::mpc_once(Trajectory traj, stLimit limit_v, std::vector<double>
         out.push_back(0);
         out.push_back(0);
     }
+
+    if (ret == unknown) {
+        printf(" mpc solve unknown set v/w = current\n");
+        double current_v = timedV_.Get(), current_w = timedA_.Get();
+        out.clear();
+        out.push_back(current_v);
+        out.push_back(current_w);
+        out.push_back(current_v);
+        out.push_back(current_w);
+        out.push_back(current_v);
+        out.push_back(current_w);
+    }
     //
 //    diff_yaw.push_back(0);
 //    diff_yaw.push_back(0);
@@ -1732,6 +1809,9 @@ Navigation::MpcResult Navigation::MpcToTarget(NavMessage::PathNode node, stLimit
     ofs.open(log_file_dir + log_file_name, std::ios::app);  //打开的地址和方式
     auto beg_time = std::chrono::steady_clock::now();
 
+    int retry_count = 0;
+    int retry_count_limit = 3;
+
     while (cancel_ == false) {
         std::this_thread::sleep_for(std::chrono::milliseconds(20));
         if (pause_ == true) {
@@ -1749,37 +1829,38 @@ Navigation::MpcResult Navigation::MpcToTarget(NavMessage::PathNode node, stLimit
             return eMpcFailed;
         }
 
-        //出入库实时判断门控或者载车板
-        NavMessage::NewAction current_action = GetCurrentAction();
-        if (current_action.type() == 1 || current_action.type() == 2) {
-            //去出入口,判断内门是否打开
-            if (TargetIsExport(current_action.spacenode()) || TargetIsEntrance(current_action.spacenode())) {
-                int port_id = GetPortIDBySpace(current_action.spacenode());
-                if (timed_Door_.timeout() || timed_Door_.Get()[port_id].second != eDoorOpened) {
-                    printf(" Inside door is not opened.......| line: %d\n", __LINE__);
-                    return eMpcFailed;
-                }
-            } else {
-                //去车位点
-                if (IsUperSpace(current_action.spacenode())) {
-                    if (GetCarrierStatusBySpaceID(GetSpaceId(current_action.spacenode())) != eCarrierDown) {
-                        printf(" Carrier is not downed.......| line: %d\n", __LINE__);
-                        return eMpcFailed;
-                    }
-                } else {
-                    int region_id = 0, carrier_no = 0;
-                    SpaceNo2CarrierNo(GetSpaceId(current_action.spacenode()), region_id, carrier_no);
-                    if (region_id < 0) {// 子母车位,且不在载车板下方的车位
-
-                    } else {
-                        if (GetCarrierStatusBySpaceID(GetSpaceId(current_action.spacenode())) != eCarrierUp) {
-                            printf(" Carrier is not up.......| line: %d\n", __LINE__);
-                            return eMpcFailed;
-                        }
-                    }
-                }
-            }
-        }
+//        //出入库实时判断门控或者载车板
+//        float door_no_1_y = -5;
+//        NavMessage::NewAction current_action = GetCurrentAction();
+//        if (current_action.type() == 1 || current_action.type() == 2) {
+//            //去出入口,判断内门是否打开
+//            if (TargetIsExport(current_action.spacenode()) || TargetIsEntrance(current_action.spacenode())) {
+//                int port_id = GetPortIDBySpace(current_action.spacenode());
+//                if (timed_Door_.timeout() || timed_Door_.Get()[port_id].second != eDoorOpened) {
+//                    printf(" Inside door is not opened.......| line: %d\n", __LINE__);
+//                    return eMpcFailed;
+//                }
+//            } else {
+//                //去车位点
+//                if (IsUperSpace(current_action.spacenode())) {
+//                    if (GetCarrierStatusBySpaceID(GetSpaceId(current_action.spacenode())) != eCarrierDown) {
+//                        printf(" Carrier is not downed.......| line: %d\n", __LINE__);
+//                        return eMpcFailed;
+//                    }
+//                } else {
+//                    int region_id = 0, carrier_no = 0;
+//                    SpaceNo2CarrierNo(GetSpaceId(current_action.spacenode()), region_id, carrier_no);
+//                    if (region_id < 0) {// 子母车位,且不在载车板下方的车位
+//
+//                    } else {
+//                        if (GetCarrierStatusBySpaceID(GetSpaceId(current_action.spacenode())) != eCarrierUp) {
+//                            printf(" Carrier is not up.......| line: %d\n", __LINE__);
+//                            return eMpcFailed;
+//                        }
+//                    }
+//                }
+//            }
+//        }
 
         //判断是否到达终点
         if (IsArrived(node)) {
@@ -1792,17 +1873,33 @@ Navigation::MpcResult Navigation::MpcToTarget(NavMessage::PathNode node, stLimit
             }
         }
 
+        float v_before_compute = timedV_.Get();
+        float a_before_compute = timedA_.Get();
         //一次变速
         std::vector<double> out;
 //        std::vector<double> diff_yaw; //两车分别与整车的相对角度
         bool ret;
+        int mpc_result = 0;
         TimerRecord::Execute([&, this]() {
-            ret = mpc_once(traj, limit_v, out, directY);
+            ret = mpc_once(traj, limit_v, out, mpc_result, directY);
         }, "mpc_once");
+
         if (ret == false) {
-            SlowlyStop();
-            ofs.close();//关闭文件
-            return eMpcFailed;
+            if (mpc_result == unknown){
+                retry_count++;
+                if (retry_count > retry_count_limit) {
+                    printf("MpcToTarget failed,ret:%d\n", ret);
+                    SlowlyStop();
+                    ofs.close();//关闭文件
+                    return eMpcFailed;
+                }
+                printf("MpcToTarget failed,mpc_result:%d, retry...\n", mpc_result);
+            } else {
+                printf("MpcToTarget failed,ret:%d\n", ret);
+                SlowlyStop();
+                ofs.close();//关闭文件
+                return eMpcFailed;
+            }
         }
         const int down_count = 3;//下发前多少步
         double down_v[down_count] = {out[0], out[2], out[4]};//下发线速度
@@ -1891,6 +1988,10 @@ Navigation::MpcResult Navigation::MpcToTarget(NavMessage::PathNode node, stLimit
                         std::to_string(cur_Bro_pose.theta());
         log_inf_line += " ";
 
+        log_inf_line += std::to_string(v_before_compute) + " " + std::to_string(a_before_compute);//计算时反馈速度
+        log_inf_line += " ";
+        log_inf_line += std::to_string(timedV_.Get()) + " " + std::to_string(timedA_.Get());//下发时反馈速度
+        log_inf_line += " ";
         log_inf_line += std::to_string(out[0]) + " " + std::to_string(out[1]);//下发速度
         log_inf_line += " ";
         log_inf_line += std::to_string(out[2]) + " " + std::to_string(out[3]);//下发速度
@@ -2360,6 +2461,7 @@ int Navigation::GetPortIDBySpace(NavMessage::PathNode node) {
     return -1;
 }
 
+
 int Navigation::GetRemainActionsCount() {
     return newUnfinished_cations_.size();
 }
@@ -2368,5 +2470,17 @@ NavMessage::NewAction Navigation::GetCurrentAction() {
     return newUnfinished_cations_.front();
 }
 
+NavMessage::NewAction Navigation::GetLastAction() {
+    return newUnfinished_cations_.back();
+}
+
+int Navigation::GetSequenceType() {
+    if (global_navCmd_.has_sequence()){
+        return eSequenceDefault;
+    }
+    else{
+        return global_navCmd_.sequence();
+    }
+}
 
 

+ 7 - 1
MPC/navigation.h

@@ -126,9 +126,13 @@ public:
 
     int GetPortIDBySpace(NavMessage::PathNode node);
 
+    //获取当前流程是出/入库
+    int GetSequenceType();
+
     // 获取当前未完成动作数量
     virtual int GetRemainActionsCount();
     virtual NavMessage::NewAction GetCurrentAction();
+    virtual NavMessage::NewAction GetLastAction();
 
 protected:
     static void anasisCarierStatu(int& regionID, CarrierStatuRegionMap& status, int32_t bytes);
@@ -199,6 +203,8 @@ protected:
 
     virtual Navigation::MpcResult RotateBeforeIntoExport();
 
+    virtual Navigation::MpcResult RotateAfterOutExport();
+
     /// 双车出库摆正
     virtual Navigation::MpcResult DoubleOutSpaceCorrectTheta();
 
@@ -218,7 +224,7 @@ protected:
 
     virtual int GetSpaceId(NavMessage::PathNode spaceNode);
 
-    bool mpc_once(Trajectory traj, stLimit limit_v, std::vector<double> &out, bool directY = false);
+    bool mpc_once(Trajectory traj, stLimit limit_v, std::vector<double> &out, int& mpc_result, bool directY = false);
 
     /* 原地旋转mpc
      *

+ 1 - 1
MPC/navigation_main.cpp

@@ -27,7 +27,7 @@ void NavigationMain::ResetPose(const Pose2d &pose) {
         Pose2d brother = timedBrotherPose_.Get();
         Pose2d diff = Pose2d::abs(Pose2d::relativePose(brother, pose));
 
-        if (diff.x() > 3.6 || diff.x() < 2.2 || diff.y() > 0.3 || diff.theta() > 5 * M_PI / 180.0) {
+        if (diff.x() > 3.6 || diff.x() < 2.2 || diff.y() > 0.5 || diff.theta() > 10 * M_PI / 180.0) {
             std::cout << " distance with two agv is too far diff: " << diff << std::endl;
             return;
         }

+ 4 - 2
MPC/navigation_main.h

@@ -29,8 +29,10 @@ public:
     virtual bool SwitchMode(int mode, float wheelBase) {
         printf("change mode to:%d\n", mode);
         wheelBase_ = wheelBase;
-        if (move_mode_ == mode)
+        if (move_mode_ == mode){
             return true;
+        }
+
         if (mode == eDouble) {
             if (timedBrotherPose_.timeout() == true || timedPose_.timeout() == true) {
                 std::cout << "Brother/self pose is timeout can not set MainAGV pose" << std::endl;
@@ -42,7 +44,7 @@ public:
             Pose2d pose = timedPose_.Get();
             Pose2d diff = Pose2d::abs(Pose2d::relativePose(brother, pose));
 
-            if (diff.x() > 3.4 || diff.x() < 2.3 || diff.y() > 0.5 || diff.theta() > 5 * M_PI / 180.0) {
+            if (diff.x() > 3.6 || diff.x() < 2.2 || diff.y() > 0.5 || diff.theta() > 5 * M_PI / 180.0) {
                 std::cout << " distance with two agv is too far diff: " << diff << std::endl;
                 return false;
             }

+ 1 - 0
message.proto

@@ -81,6 +81,7 @@ message NavCmd
     int32 action = 1;  //  0 开始任务,1 pause, 2 continue ,3 cancel,4:切换到双车模式,5:切换到单车模式,
     string key = 2;
     repeated NewAction newActions = 5;
+    optional int32 sequence = 6; // 0:无, 1:存车, 2:取车
 }
 
 message NavResponse {