Skip to content

Commit 5b77653

Browse files
Implemented a parsing of robot id that should be a little bit more robust.
1 parent 541bd2b commit 5b77653

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

loop-functions/vanilla/ForagingTwoSpotsLoopFunc.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,13 @@ void ForagingTwoSpotsLoopFunction::PostStep() {
101101
UInt32 unId;
102102
for (CSpace::TMapPerType::iterator it = tEpuckMap.begin(); it != tEpuckMap.end(); ++it) {
103103
CEPuckEntity* pcEpuck = any_cast<CEPuckEntity*>(it->second);
104-
unId = atoi(pcEpuck->GetId().substr(5, 2).c_str());
104+
// unId = atoi(pcEpuck->GetId().substr(5, 2).c_str());
105+
// expects the id to be in the following form: epuck_{unId}_{robotId}
106+
std::string robot_id = pcEpuck->GetId();
107+
UInt8 first_underscore = robot_id.find("_");
108+
UInt8 second_underscore = robot_id.find("_", first_underscore+1);
109+
robot_id = robot_id.substr(first_underscore, second_underscore-first_underscore);
110+
unId = atoi(robot_id.c_str());
105111
cEpuckPosition.Set(pcEpuck->GetEmbodiedEntity().GetOriginAnchor().Position.GetX(),
106112
pcEpuck->GetEmbodiedEntity().GetOriginAnchor().Position.GetY());
107113

@@ -114,9 +120,9 @@ void ForagingTwoSpotsLoopFunction::PostStep() {
114120
} else if (cEpuckPosition.GetY() <= m_fNestLimit) {
115121
m_fObjectiveFunction = m_fObjectiveFunction + m_punFoodData[unId];
116122
m_punFoodData[unId] = 0;
123+
// LOG << "Obj " << m_fObjectiveFunction << std::endl;
117124
}
118125
}
119-
//LOG << "Obj " << m_fObjectiveFunction << std::endl;
120126
}
121127

122128
/****************************************/

0 commit comments

Comments
 (0)