|
@@ -150,10 +150,9 @@ void Navigation::HandleAgvStatu(const MqttMsg &msg) {
|
|
|
ResetStatu(speed.v(), speed.w());
|
|
|
ResetClamp((ClampStatu) speed.clamp());
|
|
|
ResetLifter((LifterStatus) speed.lifter());
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
- ResetInsideDoor(speed.door());
|
|
|
+ ResetDoor(speed.door());
|
|
|
std::vector<int32_t> vecStatus;
|
|
|
for(int i=0;i<speed.zcb_size();++i){
|
|
|
vecStatus.push_back(speed.zcb(i));
|
|
@@ -361,6 +360,8 @@ Navigation::Navigation() {
|
|
|
obs_h_ = 4.0;
|
|
|
obs_w_ = 2.0;
|
|
|
timedBrotherPose_.reset(Pose2d(-100, 0, 0), 0.5);
|
|
|
+
|
|
|
+ LoadSpaceNo2CarrierNo();
|
|
|
}
|
|
|
|
|
|
void Navigation::BrotherAgvStatuCallback(const MqttMsg &msg, void *context) {
|
|
@@ -722,6 +723,10 @@ bool Navigation::execute_nodes(NavMessage::NewAction action, int space_id) {
|
|
|
Navigation::MpcResult Navigation::DoubleOutSpaceCorrectTheta() {
|
|
|
if (move_mode_ != eDouble)
|
|
|
return eMpcSuccess;
|
|
|
+ int clampLifterAction=0;
|
|
|
+ if(move_mode_==eDouble){
|
|
|
+ clampLifterAction |= eLifterDown;
|
|
|
+ }
|
|
|
Pose2d init = timedPose_.Get();
|
|
|
double diff1 = fabs(M_PI / 2.0 - init.theta());
|
|
|
double diff2 = fabs(-M_PI / 2.0 - init.theta());
|
|
@@ -747,12 +752,15 @@ Navigation::MpcResult Navigation::DoubleOutSpaceCorrectTheta() {
|
|
|
if (fabs(yawDiff) < 0.2 * M_PI / 180.0 && fabs(timedA_.Get()) < 5 * M_PI / 180.0) {
|
|
|
printf(" DoubleOutSpaceCorrectTheta refer target completed\\n,cuv:%f\n", yawDiff);
|
|
|
Stop();
|
|
|
+ if(WaitClampLifterStatu(clampLifterAction)==false){
|
|
|
+ return eMpcFailed;
|
|
|
+ }
|
|
|
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);
|
|
|
+ SendMoveCmd(clampLifterAction, move_mode_, eRotation, v, w);
|
|
|
actionType_ = eRotation;
|
|
|
printf(" DoubleOutSpaceCorrectTheta | input anguar:%f, down:%f(%f), diff:%f anyDirect:false\n",
|
|
|
timedA_.Get(), out[0], out[0] / M_PI * 180, yawDiff);
|
|
@@ -931,6 +939,8 @@ bool Navigation::TargetIsExport(NavMessage::PathNode node) {
|
|
|
return node.id().find("S1101") != -1;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
bool Navigation::execute_InOut_space(NavMessage::NewAction action) {
|
|
|
if (action.type() != 1 && action.type() != 2) {
|
|
|
printf(" Inout_space failed : msg action type must ==1\n ");
|
|
@@ -997,7 +1007,8 @@ bool Navigation::execute_InOut_space(NavMessage::NewAction action) {
|
|
|
//去出入口,等内门打开
|
|
|
if (TargetIsExport(action.spacenode()) || TargetIsEntrance(action.spacenode())) {
|
|
|
printf(" Wait Inside door opened.......\n");
|
|
|
- if (WaitInsideDoorOpen(action.spacenode().id()) == false) {
|
|
|
+ int port_id = GetPortIDBySpace(action.spacenode());
|
|
|
+ if (WaitInsideDoorCompleted(port_id, eDoorOpened) == false ) {
|
|
|
return false;
|
|
|
}
|
|
|
printf(" Wait Inside door opened completed!!!\n");
|
|
@@ -1005,16 +1016,23 @@ bool Navigation::execute_InOut_space(NavMessage::NewAction action) {
|
|
|
//去车位点
|
|
|
if (IsUperSpace(action.spacenode())) {
|
|
|
printf(" Wait Carrier down.......\n");
|
|
|
- if (WaitCarrierCompleted(0/*待修改*/, eCarrierDown) == false) {
|
|
|
+ if (WaitCarrierCompleted(GetSpaceId(action.spacenode()), eCarrierDown) == false) {
|
|
|
return false;
|
|
|
}
|
|
|
printf(" Wait Carrier down completed!!!\n");
|
|
|
} else {
|
|
|
- printf(" Wait Carrier up.......\n");
|
|
|
- if (WaitCarrierCompleted(0/*待修改*/, eCarrierUp) == false) {
|
|
|
- return false;
|
|
|
+ if(!TargetIsExport(action.spacenode()) && !TargetIsEntrance(action.spacenode())) {
|
|
|
+ printf(" Wait Carrier up.......\n");
|
|
|
+ if (WaitCarrierCompleted(GetSpaceId(action.spacenode()), eCarrierUp) == false) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ printf(" Wait Carrier up completed!!!\n");
|
|
|
+ }else{
|
|
|
+ printf(" Wait inside door open.......\n");
|
|
|
+ if(WaitInsideDoorCompleted(GetSpaceId(action.spacenode()),eDoorOpened)==false)
|
|
|
+ return false;
|
|
|
+ printf("inside door opened\n");
|
|
|
}
|
|
|
- printf(" Wait Carrier up completed!!!\n");
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1024,6 +1042,13 @@ bool Navigation::execute_InOut_space(NavMessage::NewAction action) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 单车进库必须全打开
|
|
|
+ if (move_mode_ == eSingle){
|
|
|
+ if (clamp_fully_open() == false) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//入库
|
|
|
Pose2d rotated = timedPose_.Get();
|
|
|
double x = new_target.x();
|
|
@@ -1039,7 +1064,9 @@ bool Navigation::execute_InOut_space(NavMessage::NewAction action) {
|
|
|
while (true) {
|
|
|
if (cancel_) {
|
|
|
return false;
|
|
|
- }
|
|
|
+ }if(move_mode_==eDouble){
|
|
|
+ clampLifterAction |= eLifterDown;
|
|
|
+ }
|
|
|
Pose2d current = timedPose_.Get();
|
|
|
Pose2d brother_pose = timedBrotherPose_.Get();
|
|
|
Pose2d vecCurent2T = current - target;
|
|
@@ -1101,12 +1128,9 @@ bool Navigation::execute_InOut_space(NavMessage::NewAction action) {
|
|
|
return false;
|
|
|
}
|
|
|
isInSpace_ = false;
|
|
|
- if (!lifter_down())
|
|
|
- return false;
|
|
|
//摆正
|
|
|
if (DoubleOutSpaceCorrectTheta() != eMpcSuccess)
|
|
|
return false;
|
|
|
-
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
@@ -1509,39 +1533,42 @@ bool Navigation::lifter_down() {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-bool Navigation::WaitInsideDoorOpen(std::string doorID) {
|
|
|
- return true;
|
|
|
+bool Navigation::WaitInsideDoorCompleted(int doorID, DoorStatu status) {
|
|
|
while (cancel_ == false) {
|
|
|
- if (timed_insideDoor_.timeout()) {
|
|
|
+ if (timed_Door_.timeout()) {
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
- InsideDoorStatu current = timed_insideDoor_.Get();
|
|
|
- /*
|
|
|
- *
|
|
|
- */
|
|
|
-
|
|
|
+ if (timed_Door_.Get()[doorID].second == status) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
usleep(1000 * 100);
|
|
|
+ printf("waiting door_id(ins):%d, to:%d...\n",doorID, status);
|
|
|
}
|
|
|
if (cancel_ == true) {
|
|
|
return false;
|
|
|
}
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
-bool Navigation::WaitCarrierCompleted(int carrierID, CarrierStatu statu) {
|
|
|
- return true;
|
|
|
+bool Navigation::WaitCarrierCompleted(int spaceID, CarrierStatu statu) {
|
|
|
while (cancel_ == false) {
|
|
|
- if (timed_Carrier_.timeout()) {
|
|
|
+ int region_id=-1, carrier_no=-1;
|
|
|
+ SpaceNo2CarrierNo(spaceID, region_id, carrier_no);
|
|
|
+ if (timed_Carrier_[region_id].timeout()) {
|
|
|
return false;
|
|
|
}
|
|
|
-// CarrierStatu current = timed_Carrier_.Get();
|
|
|
- /* */
|
|
|
|
|
|
+ CarrierStatu cur_ = GetCarrierStatusBySpaceID(spaceID);
|
|
|
+ if ( cur_ == statu){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
usleep(1000 * 100);
|
|
|
+ printf("waiting space_id:%d, carrier_id[%d,%d] to:%d, cur:%d...\n",spaceID, region_id, carrier_no, statu, cur_);
|
|
|
}
|
|
|
if (cancel_ == true) {
|
|
|
return false;
|
|
|
}
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
bool Navigation::WaitClampLifterStatu(int clampLifterAction) {
|
|
@@ -1928,7 +1955,7 @@ void Navigation::Start(const NavMessage::NavCmd &cmd, NavMessage::NavResponse &r
|
|
|
break;
|
|
|
}
|
|
|
} else if (act.type() == 7) {
|
|
|
- if (this->clamp_half_open() == false) {
|
|
|
+ if (this->clamp_fully_open() == false) {
|
|
|
printf("打开夹持 failed...\n");
|
|
|
break;
|
|
|
}
|
|
@@ -2035,57 +2062,169 @@ bool Navigation::IsMasterAGV() {
|
|
|
return is_master_AGV;
|
|
|
}
|
|
|
|
|
|
-void Navigation::ResetInsideDoor(int32_t status) {
|
|
|
- if ((status & eInsideDoorOpened) == eInsideDoorOpened){
|
|
|
- timed_insideDoor_.reset(eInsideDoorOpened);
|
|
|
- } else if ((status & eInsideDoorClosed) == eInsideDoorClosed){
|
|
|
- timed_insideDoor_.reset(eInsideDoorClosed);
|
|
|
- } else{
|
|
|
- timed_insideDoor_.reset(eInsideDoorInvalid);
|
|
|
+void Navigation::ResetDoor(int32_t status) {
|
|
|
+// printf("---------------receive status:%d\n",status);
|
|
|
+ DoorStatusMap doorStatusMap;
|
|
|
+ anasisDoorStatu(status, doorStatusMap);
|
|
|
+
|
|
|
+// for (auto it = doorStatusMap.begin() ; it != doorStatusMap.end() ; ++it) {
|
|
|
+// printf("doorID:%d, out:%d, ins:%d\n",it->first, it->second.first, it->second.second);
|
|
|
+// }
|
|
|
+
|
|
|
+ timed_Door_.reset(doorStatusMap, 3);
|
|
|
+}
|
|
|
+
|
|
|
+void Navigation::anasisDoorStatu(int32_t i_door_status, DoorStatusMap& m_door_status) {
|
|
|
+// int bytesize = sizeof(int32_t)*8;
|
|
|
+ m_door_status.clear();
|
|
|
+ for (int i = 1; i >= 0; --i) {
|
|
|
+ int statu = i_door_status>>(i*16);
|
|
|
+ int door_id = (statu&0xFF00)>>8;
|
|
|
+ int outside_door_status = statu&0x00FF;
|
|
|
+ int inside_door_status = outside_door_status>>2;
|
|
|
+
|
|
|
+ if ((outside_door_status & eDoorOpened) == eDoorOpened){
|
|
|
+ outside_door_status = eDoorOpened;
|
|
|
+ } else if ((outside_door_status & eDoorClosed) == eDoorClosed){
|
|
|
+ outside_door_status = eDoorClosed;
|
|
|
+ } else{
|
|
|
+ outside_door_status = eDoorInvalid;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ((inside_door_status & eDoorOpened) == eDoorOpened){
|
|
|
+ inside_door_status = eDoorOpened;
|
|
|
+ } else if ((inside_door_status & eDoorClosed) == eDoorClosed){
|
|
|
+ inside_door_status = eDoorClosed;
|
|
|
+ } else{
|
|
|
+ inside_door_status = eDoorInvalid;
|
|
|
+ }
|
|
|
+
|
|
|
+ m_door_status[door_id] = DoorStatusInOnePort((DoorStatu)outside_door_status, (DoorStatu)inside_door_status);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+#define SWAP_BYTES 0
|
|
|
void Navigation::anasisCarierStatu(int& regionID, CarrierStatuRegionMap& status, int32_t bytes){
|
|
|
+ int32_t reverseBytes=bytes;
|
|
|
+ if(SWAP_BYTES){
|
|
|
+ reverseBytes = (bytes>>24)| ((bytes&0xFF0000)>>8)|((bytes&0xFF00)<<8)|((bytes&0xFF)<<24);
|
|
|
+ }
|
|
|
int bytesize=sizeof(int32_t)*8;
|
|
|
regionID = (bytes>>((bytesize-1)*8));
|
|
|
for (int i = 0; i < (bytesize-8)/2; ++i) {
|
|
|
- int statu =(bytes>>(i*2) & 0x03);
|
|
|
+ int statu =(reverseBytes>>(i*2) & 0x03);
|
|
|
|
|
|
if ((statu & eCarrierUp) == eCarrierUp) {
|
|
|
- status[i]=eCarrierUp;
|
|
|
+ status[i+1]=eCarrierUp;
|
|
|
}
|
|
|
else if ((statu & eCarrierDown) == eCarrierDown){
|
|
|
- status[i]=eCarrierDown;
|
|
|
+ status[i+1]=eCarrierDown;
|
|
|
}
|
|
|
else {
|
|
|
- status[i]=eCarrierInvalid;
|
|
|
+ status[i+1]=eCarrierInvalid;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void Navigation::ResetCarrier(std::vector<int32_t> status) {
|
|
|
- std::map<int,CarrierStatuRegionMap> regionStatus;
|
|
|
for(int32_t statu : status){
|
|
|
int regionID;
|
|
|
CarrierStatuRegionMap region;
|
|
|
anasisCarierStatu(regionID,region,statu);
|
|
|
- regionStatus[regionID]=region;
|
|
|
+
|
|
|
+ timed_Carrier_[regionID].reset(region,5);
|
|
|
}
|
|
|
- timed_Carrier_.reset(regionStatus);
|
|
|
|
|
|
- printf("---------------------------------------\n");
|
|
|
- for(std::map<int,CarrierStatuRegionMap>::iterator it=regionStatus.begin();
|
|
|
- it!=regionStatus.end();it++){
|
|
|
+ /*printf("---------------------------------------\n");
|
|
|
+ for(std::map<int,TimedLockData<CarrierStatuRegionMap>>::iterator it=timed_Carrier_.begin();
|
|
|
+ it!=timed_Carrier_.end();it++){
|
|
|
int regionID=it->first;
|
|
|
+ if(it->second.timeout())
|
|
|
+ continue;
|
|
|
printf(">>>>>>> Region ID :%d\n",regionID);
|
|
|
- for(std::map<int,CarrierStatu>::iterator it1=it->second.begin();
|
|
|
- it1!=it->second.end();++it1){
|
|
|
+ std::map<int,CarrierStatu> region=it->second.Get();
|
|
|
+ for(std::map<int,CarrierStatu>::iterator it1=region.begin();
|
|
|
+ it1!=region.end();++it1){
|
|
|
int id=it1->first;
|
|
|
CarrierStatu sta=it1->second;
|
|
|
printf("\t \tcarrier id :%d statu:%d\n",id,sta);
|
|
|
}
|
|
|
+ }*/
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void Navigation::Stringsplit(const std::string& str, const std::string splits, std::vector<std::string>& res){
|
|
|
+ res.clear();
|
|
|
+ if(str.empty())
|
|
|
+ return;
|
|
|
+ std::string strs = str+splits;
|
|
|
+ size_t pos = strs.find(splits);
|
|
|
+ int step = splits.size();
|
|
|
+
|
|
|
+ while (pos!= std::string::npos){
|
|
|
+ std::string temp = strs.substr(0, pos);
|
|
|
+ res.push_back(temp);
|
|
|
+ strs = strs.substr(pos+step,strs.size());
|
|
|
+ pos = strs.find(splits);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+bool Navigation::LoadSpaceNo2CarrierNo(){
|
|
|
+ std::string file_name = "../config/SpaceNO2CarrarierNO.txt";
|
|
|
+ std::ifstream in(file_name);
|
|
|
+ std::string line;
|
|
|
+ std::vector<std::string> data_in_one_line;
|
|
|
+ if (in){
|
|
|
+ short space_id, region_id, carrier_no;
|
|
|
+ while(std::getline(in,line)){
|
|
|
+ Stringsplit(line, " ",data_in_one_line);
|
|
|
+ space_id = std::stoi(data_in_one_line[0]);
|
|
|
+ region_id = std::stoi(data_in_one_line[1]);
|
|
|
+ carrier_no = std::stoi(data_in_one_line[2]);
|
|
|
+ spaceNo_2_region_carrier_excel_[space_id] = Region_Carry(region_id,carrier_no);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ } else{
|
|
|
+ printf("no SpaceNO2CarrarierNO.txt in config!\n");
|
|
|
}
|
|
|
+ return false;
|
|
|
+}
|
|
|
|
|
|
+bool Navigation::SpaceNo2CarrierNo(int space_no, int& region_id, int& carrier_no) {
|
|
|
+ Region_Carry region_carry = spaceNo_2_region_carrier_excel_[space_no];
|
|
|
+ region_id = region_carry.first;
|
|
|
+ carrier_no = region_carry.second;
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
+Navigation::CarrierStatu Navigation::GetCarrierStatusBySpaceID(int space_id) {
|
|
|
+ int region_id;
|
|
|
+ int carrier_no;
|
|
|
+ if (SpaceNo2CarrierNo(space_id,region_id,carrier_no) == false){
|
|
|
+ printf("no matched carrier!\n");
|
|
|
+ return eCarrierInvalid;
|
|
|
+ }
|
|
|
+ printf("space_id:%d, region_id:%d, carrier_no:%d\n",space_id,region_id,carrier_no);
|
|
|
+ if (timed_Carrier_[region_id].timeout()){
|
|
|
+ printf("carrier status is timeout!\n");
|
|
|
+ return eCarrierInvalid;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ return timed_Carrier_[region_id].Get()[carrier_no];
|
|
|
+ }
|
|
|
+ return eCarrierInvalid;
|
|
|
+}
|
|
|
+
|
|
|
+int Navigation::GetPortIDBySpace(NavMessage::PathNode node) {
|
|
|
+ int port_id = GetSpaceId(node);
|
|
|
+ if (port_id == 1101){
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ else if (port_id == 1102){
|
|
|
+ return 2;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|