Skip to content

Commit

Permalink
Added check to ensure seed state parameter is set correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
marip8 committed Sep 29, 2023
1 parent 0173bc0 commit ad31474
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/reach/reach_study.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ class ReachStudy
std::tuple<double, double> getAverageNeighborsCount() const;

protected:
/**
* @brief Checks the seed state parameter for validity and sets it to a default value if it does not exist
* @throws Throws an exception if all of the IK solver joint names cannot be found in the seed state parameter
*/
void checkSeedState();

Parameters params_;
ReachDatabase db_;

Expand Down
18 changes: 18 additions & 0 deletions src/reach_study.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ ReachStudy::ReachStudy(IKSolver::ConstPtr ik_solver, Evaluator::ConstPtr evaluat
, target_poses_(target_generator->generate())
, search_tree_(createSearchTree(target_poses_))
{
checkSeedState();
}

ReachStudy::ReachStudy(const ReachStudy& rhs)
Expand All @@ -49,6 +50,23 @@ ReachStudy::ReachStudy(const ReachStudy& rhs)
, target_poses_(rhs.target_poses_)
, search_tree_(rhs.search_tree_)
{
checkSeedState();
}

void ReachStudy::checkSeedState()
{
// Check the optional seed state parameter
const std::vector<std::string> joint_names = ik_solver_->getJointNames();
if(params_.seed_state.empty())
{
logger_->print("Seed state is empty; setting to all-zeros state");
params_.seed_state = zip(joint_names, std::vector<double>(joint_names.size(), 0.0));
}
else
{
// Attempt to extract a subset of the seed state for the provided joint names. This function throws an exception if this is not possible
transcribeInputMap(params_.seed_state, joint_names);
}
}

void ReachStudy::load(const std::string& filename)
Expand Down

0 comments on commit ad31474

Please sign in to comment.