Skip to content

Commit 1c899e2

Browse files
committed
Improve logging of errors
1 parent 6c529ef commit 1c899e2

File tree

2 files changed

+66
-74
lines changed

2 files changed

+66
-74
lines changed

src/EnvironmentXYZTheta.cpp

+50-53
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace ugv_nav4d
2424
{\
2525
LOG_ERROR_S << #val; \
2626
LOG_ERROR_S << __FILE__ << ": " << __LINE__; \
27-
throw std::runtime_error("meeeeh"); \
27+
throw std::runtime_error("Error!"); \
2828
}
2929

3030
EnvironmentXYZTheta::EnvironmentXYZTheta(std::shared_ptr<MLGrid> mlsGrid,
@@ -103,9 +103,10 @@ void EnvironmentXYZTheta::setInitialPatch(const Eigen::Affine3d& ground2Mls, dou
103103

104104
void EnvironmentXYZTheta::updateMap(shared_ptr< ugv_nav4d::EnvironmentXYZTheta::MLGrid > mlsGrid)
105105
{
106-
if(this->mlsGrid && this->mlsGrid->getResolution() != mlsGrid->getResolution())
106+
if(this->mlsGrid && this->mlsGrid->getResolution() != mlsGrid->getResolution()){
107+
LOG_ERROR_S << "EnvironmentXYZTheta::updateMap : Error got MLSMap with different resolution";
107108
throw std::runtime_error("EnvironmentXYZTheta::updateMap : Error got MLSMap with different resolution");
108-
109+
}
109110
if(!this->mlsGrid)
110111
{
111112
availableMotions.computeMotions(mlsGrid->getResolution().x(), travConf.gridResolution);
@@ -131,7 +132,7 @@ EnvironmentXYZTheta::ThetaNode* EnvironmentXYZTheta::createNewStateFromPose(cons
131132
traversability_generator3d::TravGenNode *travNode = travGen.generateStartNode(pos);
132133
if(!travNode)
133134
{
134-
LOG_INFO_S << "Could not generate Node at pos";
135+
LOG_ERROR_S << "Could not generate new state at pos: " << pos.transpose();
135136
return nullptr;
136137
}
137138

@@ -140,7 +141,7 @@ EnvironmentXYZTheta::ThetaNode* EnvironmentXYZTheta::createNewStateFromPose(cons
140141
{
141142
if(!travGen.expandNode(travNode))
142143
{
143-
LOG_INFO_S << "createNewStateFromPose: Error: " << name << " Pose " << pos.transpose() << " is not traversable";
144+
LOG_ERROR_S << "createNewStateFromPose: Error: " << name << " Pose " << pos.transpose() << " is not traversable";
144145
return nullptr;
145146
}
146147
travNode->setNotExpanded();
@@ -165,13 +166,13 @@ bool EnvironmentXYZTheta::obstacleCheck(const maps::grid::Vector3d& pos, double
165166
maps::grid::Index idxObstNode;
166167
if(!obsGen.getTraversabilityMap().toGrid(pos, idxObstNode))
167168
{
168-
LOG_INFO_S << "Error " << nodeName << " is outside of obstacle map ";
169+
LOG_ERROR_S << "Error " << nodeName << " is outside of obstacle map ";
169170
return false;
170171
}
171172
traversability_generator3d::TravGenNode* obstacleNode = obsGen.findMatchingTraversabilityPatchAt(idxObstNode, pos.z());
172173
if(!obstacleNode)
173174
{
174-
LOG_INFO_S << "Error, could not find matching obstacle node for " << nodeName;
175+
LOG_ERROR_S << "Error, could not find matching obstacle node for " << nodeName;
175176
return false;
176177
}
177178

@@ -209,8 +210,8 @@ bool EnvironmentXYZTheta::obstacleCheck(const maps::grid::Vector3d& pos, double
209210
});
210211
#endif
211212

212-
LOG_INFO_S << "Num obstacles: " << stats.getRobotStats().getNumObstacles();
213-
LOG_INFO_S << "Error: " << nodeName << " inside obstacle";
213+
LOG_DEBUG_S << "Num obstacles: " << stats.getRobotStats().getNumObstacles();
214+
LOG_DEBUG_S << "Error: " << nodeName << " inside obstacle";
214215
return false;
215216
}
216217
}
@@ -246,7 +247,7 @@ void EnvironmentXYZTheta::setGoal(const Eigen::Vector3d& goalPos, double theta)
246247
base::Vector3d(1,1,1), V3DD::Color::red);
247248
#endif
248249

249-
LOG_INFO_S << "GOAL IS: " << goalPos.transpose();
250+
LOG_DEBUG_S << "GOAL IS: " << goalPos.transpose();
250251

251252
if(!startXYZNode)
252253
throw std::runtime_error("Error, start needs to be set before goal");
@@ -266,7 +267,7 @@ void EnvironmentXYZTheta::setGoal(const Eigen::Vector3d& goalPos, double theta)
266267
{
267268
if(!checkOrientationAllowed(goalXYZNode->getUserData().travNode, theta))
268269
{
269-
LOG_INFO_S << "Goal orientation not allowed due to slope";
270+
LOG_ERROR_S << "Goal orientation not allowed due to slope";
270271
throw OrientationNotAllowed("Goal orientation not allowed due to slope");
271272
}
272273
}
@@ -278,13 +279,12 @@ void EnvironmentXYZTheta::setGoal(const Eigen::Vector3d& goalPos, double theta)
278279
//check goal position
279280
if(!checkStartGoalNode("goal", goalXYZNode->getUserData().travNode, goalThetaNode->theta.getRadian()))
280281
{
281-
LOG_INFO_S << "goal position is invalid";
282+
LOG_ERROR_S << "Goal position is invalid";
282283
throw ObstacleCheckFailed("goal position is invalid");
283284
}
284285

285286
try {
286287
precomputeCost();
287-
LOG_INFO_S << "Heuristic computed";
288288
}
289289
catch(const std::runtime_error& ex){
290290
throw ex;
@@ -316,7 +316,7 @@ void EnvironmentXYZTheta::setGoal(const Eigen::Vector3d& goalPos, double theta)
316316
}
317317
}
318318
if (!foundNextNode) {
319-
LOG_INFO_S << "nextNode has no connection";
319+
LOG_DEBUG_S << "nextNode has no connection";
320320
break;
321321
}
322322
}
@@ -351,23 +351,24 @@ void EnvironmentXYZTheta::setStart(const Eigen::Vector3d& startPos, double theta
351351
base::Vector3d(1,1,1), V3DD::Color::blue);
352352
#endif
353353

354-
LOG_INFO_S << "START IS: " << startPos.transpose();
354+
LOG_DEBUG_S << "START IS: " << startPos.transpose();
355355

356356
startThetaNode = createNewStateFromPose("start", startPos, theta, &startXYZNode);
357-
if(!startThetaNode)
357+
if(!startThetaNode){
358+
LOG_ERROR_S << "Failed to create start state";
358359
throw StateCreationFailed("Failed to create start state");
359-
360+
}
360361
obstacleStartNode = obsGen.generateStartNode(startPos);
361362
if(!obstacleStartNode)
362363
{
363-
LOG_INFO_S << "Could not generate obstacle node at start pos";
364+
LOG_ERROR_S << "Could not generate obstacle node at start pos";
364365
throw ObstacleCheckFailed("Could not generate obstacle node at start pos");
365366
}
366367

367368
//check start position
368369
if(!checkStartGoalNode("start", startXYZNode->getUserData().travNode, startThetaNode->theta.getRadian()))
369370
{
370-
LOG_INFO_S<< "Start position is invalid";
371+
LOG_ERROR_S<< "Start position is invalid";
371372
throw ObstacleCheckFailed("Start position inside obstacle");
372373
}
373374
}
@@ -425,9 +426,10 @@ const Motion& EnvironmentXYZTheta::getMotion(const int fromStateID, const int to
425426
}
426427
}
427428

428-
if(cost == -1)
429+
if(cost == -1){
430+
LOG_ERROR_S << "Internal Error: No matching motion for output path found";
429431
throw std::runtime_error("Internal Error: No matching motion for output path found");
430-
432+
}
431433
return availableMotions.getMotion(motionId);
432434
}
433435

@@ -452,7 +454,6 @@ int EnvironmentXYZTheta::GetGoalHeuristic(int stateID)
452454
numToTravType[maps::grid::TraversabilityNodeBase::HOLE] = "HOLE";
453455
numToTravType[maps::grid::TraversabilityNodeBase::UNSET] = "UNSET";
454456
numToTravType[maps::grid::TraversabilityNodeBase::FRONTIER] = "FRONTIER";
455-
//throw std::runtime_error("tried to get heuristic for " + numToTravType[travNode->getType()] + " patch. StateID: " + std::to_string(stateID));
456457
return std::numeric_limits<int>::max();
457458
}
458459

@@ -469,18 +470,18 @@ int EnvironmentXYZTheta::GetGoalHeuristic(int stateID)
469470
int result = maxTime >= 10000000 ? maxTime : maxTime * Motion::costScaleFactor;
470471
if(result < 0)
471472
{
472-
LOG_INFO_S << sourceToGoalDist;
473-
LOG_INFO_S << stateID;
474-
LOG_INFO_S << mobilityConfig.translationSpeed;
475-
LOG_INFO_S << timeTranslation;
476-
LOG_INFO_S << sourceThetaNode->theta.shortestDist(goalThetaNode->theta).getRadian();
477-
LOG_INFO_S << mobilityConfig.rotationSpeed;
478-
LOG_INFO_S << timeRotation;
479-
LOG_INFO_S << result;
480-
LOG_INFO_S << travNode->getUserData().id;
481-
LOG_INFO_S << travNode->getType();
473+
LOG_ERROR_S << sourceToGoalDist;
474+
LOG_ERROR_S << stateID;
475+
LOG_ERROR_S << mobilityConfig.translationSpeed;
476+
LOG_ERROR_S << timeTranslation;
477+
LOG_ERROR_S << sourceThetaNode->theta.shortestDist(goalThetaNode->theta).getRadian();
478+
LOG_ERROR_S << mobilityConfig.rotationSpeed;
479+
LOG_ERROR_S << timeRotation;
480+
LOG_ERROR_S << result;
481+
LOG_ERROR_S << travNode->getUserData().id;
482+
LOG_ERROR_S << travNode->getType();
482483
//throw std::runtime_error("Goal heuristic < 0");
483-
LOG_INFO_S<< "Overflow while computing goal heuristic!";
484+
LOG_ERROR_S<< "Overflow while computing goal heuristic!";
484485
result = std::numeric_limits<int>::max();
485486
}
486487
oassert(result >= 0);
@@ -556,7 +557,7 @@ traversability_generator3d::TravGenNode *EnvironmentXYZTheta::movementPossible(t
556557
{
557558
//FIXME this should never happen but it did happen in the past and I have no idea why
558559
// needs investigation!
559-
LOG_INFO_S<< "movement not possible. nodes not conncted";
560+
LOG_DEBUG_S<< "Movement not possible. Nodes are not connected";
560561
return nullptr;
561562
}
562563

@@ -569,7 +570,7 @@ traversability_generator3d::TravGenNode *EnvironmentXYZTheta::movementPossible(t
569570
// during the expansion. Beforehand the type is undefined
570571
if(targetNode->getType() != maps::grid::TraversabilityNodeBase::TRAVERSABLE)
571572
{
572-
// LOG_INFO_S<< "movement not possible. targetnode not traversable";
573+
LOG_DEBUG_S<< "movement not possible. targetnode not traversable";
573574
return nullptr;
574575
}
575576
return targetNode;
@@ -652,7 +653,7 @@ void EnvironmentXYZTheta::GetSuccs(int SourceStateID, vector< int >* SuccIDV, ve
652653
if(!travGen.expandNode(sourceTravNode))
653654
{
654655
//expansion failed, current node is not driveable -> there are not successors to this state
655-
LOG_INFO_S<< "GetSuccs: current node not expanded and not expandable";
656+
LOG_DEBUG_S<< "GetSuccs: current node not expanded and not expandable";
656657
return;
657658
}
658659
}
@@ -740,9 +741,10 @@ void EnvironmentXYZTheta::GetSuccs(int SourceStateID, vector< int >* SuccIDV, ve
740741
{
741742
const auto &candidateMap = searchGrid.at(finalPos);
742743

743-
if(goalTravNode->getIndex() != finalPos)
744-
throw std::runtime_error("Internal error, indexes do not match");
745-
744+
if(goalTravNode->getIndex() != finalPos){
745+
LOG_ERROR_S << "Internal error, indexes of goalTravNode and finalPos do not match";
746+
throw std::runtime_error("Internal error, indexes of goalTravNode and finalPos do not match");
747+
}
746748
XYZNode searchTmp(goalTravNode->getHeight(), goalTravNode->getIndex());
747749

748750
//this works, as the equals check is on the height, not the node itself
@@ -791,7 +793,6 @@ void EnvironmentXYZTheta::GetSuccs(int SourceStateID, vector< int >* SuccIDV, ve
791793
}
792794
const double slopeFactor = avgSlope * travConf.slopeMetricScale;
793795
cost = motion.baseCost + motion.baseCost * slopeFactor;
794-
LOG_INFO_S<< "cost: " << cost << ", baseCost: " << motion.baseCost << ", slopeFactor: " << slopeFactor;
795796
break;
796797
}
797798
case traversability_generator3d::SlopeMetric::MAX_SLOPE:
@@ -827,7 +828,8 @@ void EnvironmentXYZTheta::GetSuccs(int SourceStateID, vector< int >* SuccIDV, ve
827828
cost = motion.baseCost;
828829
break;
829830
default:
830-
throw std::runtime_error("unknown slope metric selected");
831+
LOG_ERROR_S << "Unknown slope metric selected";
832+
throw std::runtime_error("Unknown slope metric selected");
831833
}
832834

833835
if (usePathStatistics){
@@ -874,6 +876,7 @@ void EnvironmentXYZTheta::GetSuccs(int SourceStateID, vector< int >* SuccIDV, ve
874876

875877
if(travNodeh->getType() != maps::grid::TraversabilityNodeBase::TRAVERSABLE)
876878
{
879+
LOG_ERROR_S << "In GetSuccs() returned id for non-traversable patch";
877880
throw std::runtime_error("In GetSuccs() returned id for non-traversable patch");
878881
}
879882
}
@@ -987,9 +990,8 @@ void EnvironmentXYZTheta::getTrajectory(const vector<int>& stateIDPath,
987990
traversability_generator3d::TravGenNode *nextNode = curNode->getConnectedNode(curIndex);
988991
if(!nextNode)
989992
{
990-
for(auto *n : curNode->getConnections())
991-
LOG_INFO_S<< "Con Node " << n->getIndex().transpose();;
992-
throw std::runtime_error("Internal error, trajectory is not continuous on tr grid");
993+
LOG_ERROR_S << "Internal error, trajectory is not continuous on traversability grid";
994+
throw std::runtime_error("Internal error, trajectory is not continuous on traversability grid");
993995
}
994996
curNode = nextNode;
995997
lastIndex = curIndex;
@@ -1016,15 +1018,13 @@ void EnvironmentXYZTheta::getTrajectory(const vector<int>& stateIDPath,
10161018
if (mobilityConfig.remove_goal_offset == true &&
10171019
i == indexOfMotionToUpdate)
10181020
{
1019-
LOG_INFO_S << "Original spline end position: " << positions[positions.size()-1];
10201021
double goal_offset_x = (goalPos.x() - positions[positions.size()-1].x()) / (positions.size()-1);
10211022
double goal_offset_y = (goalPos.y() - positions[positions.size()-1].y()) / (positions.size()-1);
10221023

10231024
for (int j{0}; j < positions.size(); j++){
10241025
positions[j].x() += j*goal_offset_x;
10251026
positions[j].y() += j*goal_offset_y;
10261027
}
1027-
LOG_INFO_S << "Updated spline end position: " << positions[positions.size()-1];
10281028
goal_position_updated = true;
10291029
}
10301030

@@ -1172,8 +1172,8 @@ double EnvironmentXYZTheta::getAvgSlope(std::vector<const traversability_generat
11721172
{
11731173
if(path.size() <= 0)
11741174
{
1175+
LOG_ERROR_S << "Requested slope of path with length zero.";
11751176
throw std::runtime_error("Requested slope of path with length zero.");
1176-
return 0;
11771177
}
11781178
double slopeSum = 0;
11791179
for(const traversability_generator3d::TravGenNode* node : path)
@@ -1415,16 +1415,13 @@ std::shared_ptr<SubTrajectory> EnvironmentXYZTheta::findTrajectoryOutOfObstacle(
14151415
}
14161416
else
14171417
{
1418-
LOG_INFO_S<< "EnvironmentXYZTheta::findTrajectoryOutOfObstacle(): NO WAY OUT, ROBOT IS STUCK!";
1419-
LOG_INFO_S<< "EnvironmentXYZTheta::findTrajectoryOutOfObstacle(): NO WAY OUT, ROBOT IS STUCK!";
1420-
LOG_INFO_S<< "EnvironmentXYZTheta::findTrajectoryOutOfObstacle(): NO WAY OUT, ROBOT IS STUCK!";
1418+
LOG_ERROR_S<< "EnvironmentXYZTheta::findTrajectoryOutOfObstacle(): NO WAY OUT, ROBOT IS STUCK!";
1419+
LOG_ERROR_S<< "EnvironmentXYZTheta::findTrajectoryOutOfObstacle(): NO WAY OUT, ROBOT IS STUCK!";
1420+
LOG_ERROR_S<< "EnvironmentXYZTheta::findTrajectoryOutOfObstacle(): NO WAY OUT, ROBOT IS STUCK!";
14211421
return nullptr;
14221422
}
14231423

14241424
std::shared_ptr<SubTrajectory> subTraj(new SubTrajectory(trajectory));
14251425
return subTraj;
14261426
}
1427-
1428-
1429-
14301427
}

0 commit comments

Comments
 (0)