Skip to content
This repository has been archived by the owner on Nov 13, 2017. It is now read-only.

Enables setting optimization objectives from ompl_planning.yaml #75

Merged
merged 4 commits into from
Jul 12, 2016
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions ompl/ompl_interface/src/model_based_planning_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@
#include <ompl/base/spaces/SE3StateSpace.h>
#include <ompl/datastructures/PDF.h>


#include "ompl/base/objectives/PathLengthOptimizationObjective.h"
#include "ompl/base/objectives/MechanicalWorkOptimizationObjective.h"
#include "ompl/base/objectives/MinimaxObjective.h"
#include "ompl/base/objectives/StateCostIntegralObjective.h"
#include "ompl/base/objectives/MaximizeMinClearanceObjective.h"

ompl_interface::ModelBasedPlanningContext::ModelBasedPlanningContext(const std::string &name, const ModelBasedPlanningContextSpecification &spec) :
planning_interface::PlanningContext(name, spec.state_space_->getJointModelGroup()->getName()),
spec_(spec),
Expand Down Expand Up @@ -217,6 +224,38 @@ void ompl_interface::ModelBasedPlanningContext::useConfig()
if (cfg.empty())
return;


ompl::base::OptimizationObjectivePtr objective;
it = cfg.find("optimization_objective");
if (it == cfg.end())
{
logInform("%s: No optimization objective specified, defaulting to PathLengthOptimizationObjective");
objective.reset(new ompl::base::PathLengthOptimizationObjective(ompl_simple_setup_->getSpaceInformation()));
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you rewrite the default case to something like this:

std::string objective;
it = cfg.find("optimization_objective");
if (it == cfg.end())
{
   objective = "PathLengthOptimizationObjective";
   logInform(" ... defaulting to " + objective); // with appropriate string type conversions I suppose...
}
else
{
  objective = it->second;
}

This avoids redundancy and the big else-block afterwards.

else
{
std::string optimizer = it->second.c_str();
if (optimizer == "PathLengthOptimizationObjective"){
objective.reset(new ompl::base::PathLengthOptimizationObjective(ompl_simple_setup_->getSpaceInformation()));
}
else if (optimizer == "MinimaxObjective"){
objective.reset(new ompl::base::MinimaxObjective(ompl_simple_setup_->getSpaceInformation()));
}
else if (optimizer == "StateCostIntegralObjective"){
objective.reset(new ompl::base::StateCostIntegralObjective(ompl_simple_setup_->getSpaceInformation()));
}
else if (optimizer == "MechanicalWorkOptimizationObjective"){
objective.reset(new ompl::base::MechanicalWorkOptimizationObjective(ompl_simple_setup_->getSpaceInformation()));
}
else if (optimizer == "MaximizeMinClearanceObjective"){
objective.reset(new ompl::base::MaximizeMinClearanceObjective(ompl_simple_setup_->getSpaceInformation()));
}
else {
objective.reset(new ompl::base::PathLengthOptimizationObjective(ompl_simple_setup_->getSpaceInformation()));
}
}
ompl_simple_setup_->setOptimizationObjective(objective);

// remove the 'type' parameter; the rest are parameters for the planner itself
it = cfg.find("type");
if (it == cfg.end())
Expand Down