Skip to content

Commit 44b86cf

Browse files
Switch to using state solver in descartes edge evaluator and ompl motion validator
1 parent f5c011b commit 44b86cf

File tree

5 files changed

+66
-26
lines changed

5 files changed

+66
-26
lines changed

tesseract/tesseract_planning/tesseract_motion_planners/include/tesseract_motion_planners/descartes/descartes_collision_edge_evaluator.h

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,28 @@ class DescartesCollisionEdgeEvaluator : public descartes_light::EdgeEvaluator<Fl
5555
std::vector<typename descartes_light::LadderGraph<FloatType>::EdgeList>& edges) override;
5656

5757
protected:
58-
tesseract_environment::StateSolver::Ptr state_solver_; /**< @brief The tesseract state solver */
59-
tesseract_scene_graph::AllowedCollisionMatrix acm_; /**< @brief The allowed collision matrix */
60-
std::vector<std::string> active_link_names_; /**< @brief A vector of active link names */
61-
std::vector<std::string> joint_names_; /**< @brief A vector of joint names */
62-
tesseract_collision::DiscreteContactManager::Ptr discrete_contact_manager_; /**< @brief The discrete contact manager
63-
*/
64-
tesseract_collision::ContinuousContactManager::Ptr continuous_contact_manager_; /**< @brief The discrete contact
65-
manager */
66-
double collision_safety_margin_; /**< @brief The minimum allowed collision distance */
67-
double longest_valid_segment_length_; /**< @brief Used to check collisions between two state if norm(state0-state1) >
68-
longest_valid_segment_length. */
69-
bool allow_collision_; /**< @brief If true and no valid edges are found it will return the one with the lowest cost */
70-
bool debug_; /**< @brief Enable debug information to be printed to the terminal */
71-
std::size_t dof_; /**< @brief The number of joints */
58+
/** @brief The tesseract state solver */
59+
tesseract_environment::StateSolver::ConstPtr state_solver_;
60+
/** @brief The allowed collision matrix */
61+
tesseract_scene_graph::AllowedCollisionMatrix acm_;
62+
/** @brief A vector of active link names */
63+
std::vector<std::string> active_link_names_;
64+
/** @brief A vector of joint names */
65+
std::vector<std::string> joint_names_;
66+
/** @brief The discrete contact manager */
67+
tesseract_collision::DiscreteContactManager::Ptr discrete_contact_manager_;
68+
/** @brief The discrete contact manager */
69+
tesseract_collision::ContinuousContactManager::Ptr continuous_contact_manager_;
70+
/** @brief The minimum allowed collision distance */
71+
double collision_safety_margin_;
72+
/** @brief Used to check collisions between two state if norm(state0-state1) > longest_valid_segment_length. */
73+
double longest_valid_segment_length_;
74+
/** @brief If true and no valid edges are found it will return the one with the lowest cost */
75+
bool allow_collision_;
76+
/** @brief Enable debug information to be printed to the terminal */
77+
bool debug_;
78+
/** @brief The number of joints */
79+
std::size_t dof_;
7280

7381
/**
7482
* @brief Check continuous and discrete collision between two states
@@ -106,6 +114,9 @@ class DescartesCollisionEdgeEvaluator : public descartes_light::EdgeEvaluator<Fl
106114
/** @brief The discrete contact manager cache */
107115
mutable std::map<unsigned long int, tesseract_collision::DiscreteContactManager::Ptr> discrete_contact_managers_;
108116

117+
/** @brief The state solver manager cache */
118+
mutable std::map<unsigned long int, tesseract_environment::StateSolver::Ptr> state_solver_managers_;
119+
109120
/**
110121
* @brief Perform a continuous collision check between two states
111122
* @param segment Trajectory containing two states

tesseract/tesseract_planning/tesseract_motion_planners/include/tesseract_motion_planners/descartes/impl/descartes_collision_edge_evaluator.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,22 +159,27 @@ bool DescartesCollisionEdgeEvaluator<FloatType>::continuousCollisionCheck(
159159
// It was time using chronos time elapsed and it was faster to cache the contact manager
160160
unsigned long int hash = std::hash<std::thread::id>{}(std::this_thread::get_id());
161161
tesseract_collision::ContinuousContactManager::Ptr cm;
162+
tesseract_environment::StateSolver::Ptr ss;
162163
mutex_.lock();
163164
auto it = continuous_contact_managers_.find(hash);
164165
if (it == continuous_contact_managers_.end())
165166
{
166167
cm = continuous_contact_manager_->clone();
167168
continuous_contact_managers_[hash] = cm;
169+
170+
ss = state_solver_->clone();
171+
state_solver_managers_[hash] = ss;
168172
}
169173
else
170174
{
171175
cm = it->second;
176+
ss = state_solver_managers_[hash];
172177
}
173178
mutex_.unlock();
174179

175180
return tesseract_environment::checkTrajectory(results,
176181
*cm,
177-
*state_solver_,
182+
*ss,
178183
joint_names_,
179184
segment,
180185
longest_valid_segment_length_,
@@ -192,22 +197,27 @@ bool DescartesCollisionEdgeEvaluator<FloatType>::discreteCollisionCheck(
192197
// It was time using chronos time elapsed and it was faster to cache the contact manager
193198
unsigned long int hash = std::hash<std::thread::id>{}(std::this_thread::get_id());
194199
tesseract_collision::DiscreteContactManager::Ptr cm;
200+
tesseract_environment::StateSolver::Ptr ss;
195201
mutex_.lock();
196202
auto it = discrete_contact_managers_.find(hash);
197203
if (it == discrete_contact_managers_.end())
198204
{
199205
cm = discrete_contact_manager_->clone();
200206
discrete_contact_managers_[hash] = cm;
207+
208+
ss = state_solver_->clone();
209+
state_solver_managers_[hash] = ss;
201210
}
202211
else
203212
{
204213
cm = it->second;
214+
ss = state_solver_managers_[hash];
205215
}
206216
mutex_.unlock();
207217

208218
return tesseract_environment::checkTrajectory(results,
209219
*cm,
210-
*state_solver_,
220+
*ss,
211221
joint_names_,
212222
segment,
213223
longest_valid_segment_length_,

tesseract/tesseract_planning/tesseract_motion_planners/include/tesseract_motion_planners/ompl/continuous_motion_validator.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ContinuousMotionValidator : public ompl::base::MotionValidator
4242
{
4343
public:
4444
ContinuousMotionValidator(const ompl::base::SpaceInformationPtr& space_info,
45-
tesseract_environment::Environment::ConstPtr env,
45+
const tesseract_environment::Environment::ConstPtr& env,
4646
tesseract_kinematics::ForwardKinematics::ConstPtr kin,
4747
double collision_safety_margin);
4848

@@ -71,6 +71,9 @@ class ContinuousMotionValidator : public ompl::base::MotionValidator
7171
/** @brief The Tesseract Environment */
7272
tesseract_environment::Environment::ConstPtr env_;
7373

74+
/**< @brief The tesseract state solver */
75+
tesseract_environment::StateSolver::ConstPtr state_solver_;
76+
7477
/** @brief The Tesseract Forward Kinematics */
7578
tesseract_kinematics::ForwardKinematics::ConstPtr kin_;
7679

@@ -99,6 +102,9 @@ class ContinuousMotionValidator : public ompl::base::MotionValidator
99102

100103
/** @brief The discrete contact manager cache */
101104
mutable std::map<unsigned long int, tesseract_collision::DiscreteContactManager::Ptr> discrete_contact_managers_;
105+
106+
/** @brief The state solver manager cache */
107+
mutable std::map<unsigned long int, tesseract_environment::StateSolver::Ptr> state_solver_managers_;
102108
};
103109
} // namespace tesseract_motion_planners
104110

tesseract/tesseract_planning/tesseract_motion_planners/src/ompl/continuous_motion_validator.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,26 @@ TESSERACT_COMMON_IGNORE_WARNINGS_POP
3535
namespace tesseract_motion_planners
3636
{
3737
ContinuousMotionValidator::ContinuousMotionValidator(const ompl::base::SpaceInformationPtr& space_info,
38-
tesseract_environment::Environment::ConstPtr env,
38+
const tesseract_environment::Environment::ConstPtr& env,
3939
tesseract_kinematics::ForwardKinematics::ConstPtr kin,
4040
double collision_safety_margin)
41-
: MotionValidator(space_info), env_(std::move(env)), kin_(std::move(kin))
41+
: MotionValidator(space_info)
42+
, state_solver_(env->getStateSolver())
43+
, kin_(std::move(kin))
44+
, continuous_contact_manager_(env->getContinuousContactManager())
45+
, discrete_contact_manager_(env->getDiscreteContactManager())
4246
{
4347
joints_ = kin_->getJointNames();
4448

4549
// kinematics objects does not know of every link affected by its motion so must compute adjacency map
4650
// to determine all active links.
4751
tesseract_environment::AdjacencyMap adj_map(
48-
env_->getSceneGraph(), kin_->getActiveLinkNames(), env_->getCurrentState()->transforms);
52+
env->getSceneGraph(), kin_->getActiveLinkNames(), env->getCurrentState()->transforms);
4953
links_ = adj_map.getActiveLinkNames();
5054

51-
continuous_contact_manager_ = env_->getContinuousContactManager();
5255
continuous_contact_manager_->setActiveCollisionObjects(links_);
5356
continuous_contact_manager_->setContactDistanceThreshold(collision_safety_margin);
5457

55-
discrete_contact_manager_ = env_->getDiscreteContactManager();
5658
discrete_contact_manager_->setActiveCollisionObjects(links_);
5759
discrete_contact_manager_->setContactDistanceThreshold(collision_safety_margin);
5860
}
@@ -125,25 +127,30 @@ bool ContinuousMotionValidator::continuousCollisionCheck(const ompl::base::State
125127
// It was time using chronos time elapsed and it was faster to cache the contact manager
126128
unsigned long int hash = std::hash<std::thread::id>{}(std::this_thread::get_id());
127129
tesseract_collision::ContinuousContactManager::Ptr cm;
130+
tesseract_environment::StateSolver::Ptr ss;
128131
mutex_.lock();
129132
auto it = continuous_contact_managers_.find(hash);
130133
if (it == continuous_contact_managers_.end())
131134
{
132135
cm = continuous_contact_manager_->clone();
133136
continuous_contact_managers_[hash] = cm;
137+
138+
ss = state_solver_->clone();
139+
state_solver_managers_[hash] = ss;
134140
}
135141
else
136142
{
137143
cm = it->second;
144+
ss = state_solver_managers_[hash];
138145
}
139146
mutex_.unlock();
140147

141148
const auto dof = si_->getStateDimension();
142149
Eigen::Map<Eigen::VectorXd> start_joints(start->values, dof);
143150
Eigen::Map<Eigen::VectorXd> finish_joints(finish->values, dof);
144151

145-
tesseract_environment::EnvState::Ptr state0 = env_->getState(joints_, start_joints);
146-
tesseract_environment::EnvState::Ptr state1 = env_->getState(joints_, finish_joints);
152+
tesseract_environment::EnvState::Ptr state0 = ss->getState(joints_, start_joints);
153+
tesseract_environment::EnvState::Ptr state1 = ss->getState(joints_, finish_joints);
147154

148155
for (const auto& link_name : links_)
149156
cm->setCollisionObjectsTransform(link_name, state0->transforms[link_name], state1->transforms[link_name]);
@@ -161,23 +168,28 @@ bool ContinuousMotionValidator::discreteCollisionCheck(const ompl::base::State*
161168
// It was time using chronos time elapsed and it was faster to cache the contact manager
162169
unsigned long int hash = std::hash<std::thread::id>{}(std::this_thread::get_id());
163170
tesseract_collision::DiscreteContactManager::Ptr cm;
171+
tesseract_environment::StateSolver::Ptr ss;
164172
mutex_.lock();
165173
auto it = discrete_contact_managers_.find(hash);
166174
if (it == discrete_contact_managers_.end())
167175
{
168176
cm = discrete_contact_manager_->clone();
169177
discrete_contact_managers_[hash] = cm;
178+
179+
ss = state_solver_->clone();
180+
state_solver_managers_[hash] = ss;
170181
}
171182
else
172183
{
173184
cm = it->second;
185+
ss = state_solver_managers_[hash];
174186
}
175187
mutex_.unlock();
176188

177189
const auto dof = si_->getStateDimension();
178190
Eigen::Map<Eigen::VectorXd> finish_joints(finish->values, dof);
179191

180-
tesseract_environment::EnvState::Ptr state1 = env_->getState(joints_, finish_joints);
192+
tesseract_environment::EnvState::Ptr state1 = ss->getState(joints_, finish_joints);
181193

182194
for (const auto& link_name : links_)
183195
cm->setCollisionObjectsTransform(link_name, state1->transforms[link_name]);

tesseract/tesseract_planning/tesseract_motion_planners/test/ompl_trajopt_planner_test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ using namespace tesseract_motion_planners;
6666
const static int SEED = 1;
6767
const static std::vector<double> start_state = { -0.5, 0.5, 0.0, -1.3348, 0.0, 1.4959, 0.0 };
6868
const static std::vector<double> end_state = { 0.5, 0.5, 0.0, -1.3348, 0.0, 1.4959, 0.0 };
69+
const static bool PLANNER_VERBOSE = false;
6970

7071
std::string locateResource(const std::string& url)
7172
{
@@ -208,7 +209,7 @@ TYPED_TEST(OMPLTrajOptTestFixture, OMPLTrajOptFreespacePlannerUnit) // NOLINT
208209
ompl_config, std::make_shared<tesseract_motion_planners::TrajOptPlannerFreespaceConfig>(trajopt_config));
209210

210211
tesseract_motion_planners::PlannerResponse planning_response;
211-
tesseract_common::StatusCode status = this->planner.solve(planning_response);
212+
tesseract_common::StatusCode status = this->planner.solve(planning_response, PLANNER_VERBOSE);
212213

213214
// Expect the planning to succeed
214215
if (!status)

0 commit comments

Comments
 (0)