Skip to content

Commit 4ae3374

Browse files
Fix constraint from error function in trajopt plan profile
1 parent 2a313cb commit 4ae3374

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

tesseract/tesseract_planning/tesseract_motion_planners/include/tesseract_motion_planners/trajopt/profile/trajopt_default_plan_profile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class TrajOptDefaultPlanProfile : public TrajOptPlanProfile
8888
tinyxml2::XMLElement* toXML(tinyxml2::XMLDocument& doc) const override;
8989

9090
protected:
91-
void addConstraintErrorFunctions(trajopt::ProblemConstructionInfo& pci, const std::vector<int>& fixed_steps) const;
91+
void addConstraintErrorFunctions(trajopt::ProblemConstructionInfo& pci, int index) const;
9292

9393
void addAvoidSingularity(trajopt::ProblemConstructionInfo& pci, const std::vector<int>& fixed_steps) const;
9494
};

tesseract/tesseract_planning/tesseract_motion_planners/src/trajopt/profile/trajopt_default_plan_profile.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ void TrajOptDefaultPlanProfile::apply(trajopt::ProblemConstructionInfo& pci,
132132
pci.cnt_infos.push_back(ti);
133133
else
134134
pci.cost_infos.push_back(ti);
135+
136+
// Add constraints from error functions if available.
137+
addConstraintErrorFunctions(pci, index);
135138
}
136139

137140
void TrajOptDefaultPlanProfile::apply(trajopt::ProblemConstructionInfo& pci,
@@ -149,6 +152,23 @@ void TrajOptDefaultPlanProfile::apply(trajopt::ProblemConstructionInfo& pci,
149152
pci.cost_infos.push_back(ti);
150153
}
151154

155+
void TrajOptDefaultPlanProfile::addConstraintErrorFunctions(trajopt::ProblemConstructionInfo& pci, int index) const
156+
{
157+
for (std::size_t i = 0; i < constraint_error_functions.size(); ++i)
158+
{
159+
auto& c = constraint_error_functions[i];
160+
trajopt::TermInfo::Ptr ti =
161+
createUserDefinedTermInfo(index, index, std::get<0>(c), std::get<1>(c), trajopt::TT_CNT);
162+
163+
// Update the term info with the (possibly) new start and end state indices for which to apply this cost
164+
std::shared_ptr<trajopt::UserDefinedTermInfo> ef = std::static_pointer_cast<trajopt::UserDefinedTermInfo>(ti);
165+
ef->constraint_type = std::get<2>(c);
166+
ef->coeff = std::get<3>(c);
167+
168+
pci.cnt_infos.push_back(ef);
169+
}
170+
}
171+
152172
tinyxml2::XMLElement* TrajOptDefaultPlanProfile::toXML(tinyxml2::XMLDocument& doc) const
153173
{
154174
Eigen::IOFormat eigen_format(Eigen::StreamPrecision, Eigen::DontAlignCols, " ", " ");

0 commit comments

Comments
 (0)