Skip to content

Commit 693537d

Browse files
jslee02brianhou
authored andcommitted
Refactor planner API (#314)
* Add Planner class and associated APIs * Fix code format * Pass function argument as const reference * Rename planning problems * Revise snap planner * Apply snap planner to util * Add PlannerFor[Single/Multi]Problem * Remove getPlannableProblems() * Fix const-correctness of CompositePlanner * Set state space when a planner is created Move interpolator from problem to planner * Rename Problem's getName() to getType() * Fix grammar errors * Use unordered_set for goal states * Remove interpolator from problem * Code format * Address comments that are straightforward * Add missing explicit specifier * Use more descriptive parameter name * Add utility functions for goal states * Minor updates * Remove PlannerForMultiProblem rename PlannerForSingleProblem to SingleProblemPlanner * Remove setters from problem All the problem classes intentionally don't have setters. This is because we assume creating a new problem for different problem settings makes sense. We can revisit this design decision if we find a compelling reason to have setters. * Rename TheProblem to SolverblaProblem * Take problem as const reference * Remove CompositePlanner::addPlanner() * Move constraint to Problem * Add missing [in] * Fix util according to the API changes * Address a few TODOs * Remove constraint from concrete problems * Code format * Fix typo: SolverbleProblem --> SolvableProblem * Be further strict to const-correctness * Add type checking assertions * Add docstrings * Update changelog * Address Brian's comments (needs code format) * Format code * Address Gilwoo's feedback * Update header guard name * Throw exception for zero-sized direction vector * Use \throw instead of \throws * Pass planner by const reference to check existency * Fix compilation errors per Clang 9.1.0
1 parent a565cd7 commit 693537d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1503
-173
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
* Common
66

7-
* Cleaned up doxygen errors: [#357](https://github.com/personalrobotics/aikido/pull/357)
87
* Fixed bug in StepSequence::getMaxSteps(): [#305](https://github.com/personalrobotics/aikido/pull/305)
98
* Fixed bug in StepSequence iterator: [#320](https://github.com/personalrobotics/aikido/pull/320)
9+
* Cleaned up doxygen errors: [#357](https://github.com/personalrobotics/aikido/pull/357)
1010

1111
* Constraint
1212

@@ -31,10 +31,11 @@
3131

3232
* Planner
3333

34-
* Changed interface for TrajectoryPostProcessor: [#341](https://github.com/personalrobotics/aikido/pull/341)
3534
* Added parabolic timing for linear spline [#302](https://github.com/personalrobotics/aikido/pull/302), [#324](https://github.com/personalrobotics/aikido/pull/324)
3635
* Fixed step sequence iteration in VPF: [#303](https://github.com/personalrobotics/aikido/pull/303)
36+
* Refactored planning API: [#314](https://github.com/personalrobotics/aikido/pull/314)
3737
* Added flags to WorldStateSaver to specify what to save: [#339](https://github.com/personalrobotics/aikido/pull/339)
38+
* Changed interface for TrajectoryPostProcessor: [#341](https://github.com/personalrobotics/aikido/pull/341)
3839
* Planning calls with InverseKinematicsSampleable constraints explicitly set MetaSkeleton to solve IK with: [#379](https://github.com/personalrobotics/aikido/pull/379)
3940

4041
* Robot
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#ifndef AIKIDO_PLANNER_COMPOSITEPLANNER_HPP_
2+
#define AIKIDO_PLANNER_COMPOSITEPLANNER_HPP_
3+
4+
#include <vector>
5+
6+
#include "aikido/planner/Planner.hpp"
7+
#include "aikido/statespace/StateSpace.hpp"
8+
9+
namespace aikido {
10+
namespace planner {
11+
12+
AIKIDO_DECLARE_POINTERS(CompositePlanner)
13+
14+
/// CompositePlanner is a base class for concrete planner classes that contain
15+
/// multiple planners.
16+
class CompositePlanner : public Planner
17+
{
18+
public:
19+
/// Constructs given list of planners.
20+
///
21+
/// \param[in] stateSpace State space that this planner associated with.
22+
/// \param[in] planners Planners that this CompositePlanner will contain.
23+
/// \throw If any of \c planners are null.
24+
CompositePlanner(
25+
statespace::ConstStateSpacePtr stateSpace,
26+
const std::vector<PlannerPtr>& planners = std::vector<PlannerPtr>());
27+
28+
/// Returns true if this CompositePlanner contains \c planner.
29+
bool hasPlanner(const Planner& planner) const;
30+
31+
// Documentation inherited.
32+
bool canSolve(const Problem& problem) const override;
33+
34+
protected:
35+
/// Planners.
36+
const std::vector<PlannerPtr> mPlanners;
37+
// We use std::vector to keep the order of planners. This is because some
38+
// concrete planners rely on the order. Alternatively, we could remove
39+
// mPlanners from here and let the concrete classes maintain the planner
40+
// containers accordingly. In that case, we should also remove getPlanner and
41+
// make addPlanner/hasPlanner/getPlanners as pure virtual functions.
42+
};
43+
44+
} // namespace planner
45+
} // namespace aikido
46+
47+
#endif // AIKIDO_PLANNER_COMPOSITEPLANNER_HPP_
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#ifndef AIKIDO_PLANNER_CONFIGURATIONTOCONFIGURATION_HPP_
2+
#define AIKIDO_PLANNER_CONFIGURATIONTOCONFIGURATION_HPP_
3+
4+
#include "aikido/constraint/Testable.hpp"
5+
#include "aikido/planner/Problem.hpp"
6+
#include "aikido/statespace/StateSpace.hpp"
7+
#include "aikido/trajectory/Interpolated.hpp"
8+
9+
namespace aikido {
10+
namespace planner {
11+
12+
/// Planning problem to plan to a single goal configuration.
13+
class ConfigurationToConfiguration : public Problem
14+
{
15+
public:
16+
/// Constructor.
17+
///
18+
/// \param[in] stateSpace State space that this problem associated with.
19+
/// \param[in] startState Start state.
20+
/// \param[in] goalState Goal state.
21+
/// \param[in] constraint Trajectory-wide constraint that must be satisfied.
22+
/// \throw If \c stateSpace is not compatible with \c constraint's state
23+
/// space.
24+
ConfigurationToConfiguration(
25+
statespace::ConstStateSpacePtr stateSpace,
26+
const statespace::StateSpace::State* startState,
27+
const statespace::StateSpace::State* goalState,
28+
constraint::ConstTestablePtr constraint);
29+
30+
// Documentation inherited.
31+
const std::string& getType() const override;
32+
33+
/// Returns the type of the planning problem.
34+
static const std::string& getStaticType();
35+
36+
/// Returns the start state.
37+
const statespace::StateSpace::State* getStartState() const;
38+
39+
/// Returns the goal state.
40+
const statespace::StateSpace::State* getGoalState() const;
41+
42+
protected:
43+
/// Start state.
44+
const statespace::StateSpace::State* mStartState;
45+
46+
/// Goal state.
47+
const statespace::StateSpace::State* mGoalState;
48+
};
49+
50+
} // namespace planner
51+
} // namespace aikido
52+
53+
#endif // AIKIDO_PLANNER_CONFIGURATIONTOCONFIGURATION_HPP_
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#ifndef AIKIDO_PLANNER_CONFIGURATIONTOCONFIGURATIONPLANNER_HPP_
2+
#define AIKIDO_PLANNER_CONFIGURATIONTOCONFIGURATIONPLANNER_HPP_
3+
4+
#include "aikido/planner/ConfigurationToConfiguration.hpp"
5+
#include "aikido/planner/SingleProblemPlanner.hpp"
6+
#include "aikido/trajectory/Trajectory.hpp"
7+
8+
namespace aikido {
9+
namespace planner {
10+
11+
/// Base planner class for ConfigurationToConfiguration planning problem.
12+
class ConfigurationToConfigurationPlanner
13+
: public SingleProblemPlanner<ConfigurationToConfigurationPlanner,
14+
ConfigurationToConfiguration>
15+
{
16+
public:
17+
// Expose the implementation of Planner::plan(const Problem&, Result*) in
18+
// SingleProblemPlanner. Note that plan() of the base class takes Problem
19+
// while the virtual function defined in this class takes SolverbleProblem,
20+
// which is simply ConfigurationToConfiguration.
21+
using SingleProblemPlanner::plan;
22+
23+
/// Constructor
24+
///
25+
/// \param[in] stateSpace State space that this planner associated with.
26+
explicit ConfigurationToConfigurationPlanner(
27+
statespace::ConstStateSpacePtr stateSpace);
28+
29+
/// Solves \c problem returning the result to \c result.
30+
///
31+
/// \param[in] problem Planning problem to be solved by the planner.
32+
/// \param[out] result Result of planning procedure.
33+
virtual trajectory::TrajectoryPtr plan(
34+
const SolvableProblem& problem, Result* result = nullptr)
35+
= 0;
36+
// Note: SolvableProblem is defined in SingleProblemPlanner.
37+
};
38+
39+
} // namespace planner
40+
} // namespace aikido
41+
42+
#endif // AIKIDO_PLANNER_CONFIGURATIONTOCONFIGURATIONPLANNER_HPP_
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#ifndef AIKIDO_PLANNER_CONFIGURATIONTOCONFIGURATIONS_HPP_
2+
#define AIKIDO_PLANNER_CONFIGURATIONTOCONFIGURATIONS_HPP_
3+
4+
#include <unordered_set>
5+
#include "aikido/constraint/Testable.hpp"
6+
#include "aikido/planner/Problem.hpp"
7+
#include "aikido/statespace/Interpolator.hpp"
8+
#include "aikido/statespace/StateSpace.hpp"
9+
10+
namespace aikido {
11+
namespace planner {
12+
13+
/// Planning problem to plan to multiple goal configurations.
14+
///
15+
/// Plan a trajectory from start state to any of the goal states using an
16+
/// interpolator to interpolate between the states.
17+
class ConfigurationToConfigurations : public Problem
18+
{
19+
public:
20+
using GoalStates = std::unordered_set<const statespace::StateSpace::State*>;
21+
22+
/// Constructor.
23+
///
24+
/// \param[in] stateSpace State space.
25+
/// \param[in] startState Start state.
26+
/// \param[in] goalStates Goal states.
27+
/// \param[in] constraint Trajectory-wide constraint that must be satisfied.
28+
/// \throw If \c stateSpace is not compatible with \c constraint's state
29+
/// space.
30+
ConfigurationToConfigurations(
31+
statespace::ConstStateSpacePtr stateSpace,
32+
const statespace::StateSpace::State* startState,
33+
const GoalStates& goalStates,
34+
constraint::ConstTestablePtr constraint);
35+
36+
// Documentation inherited.
37+
const std::string& getType() const override;
38+
39+
/// Returns the type of the planning problem.
40+
static const std::string& getStaticType();
41+
42+
/// Returns the start state.
43+
const statespace::StateSpace::State* getStartState() const;
44+
45+
/// Returns the number of the goal states.
46+
std::size_t getNumGoalStates() const;
47+
48+
/// Returns goal states.
49+
const GoalStates& getGoalStates() const;
50+
51+
protected:
52+
/// Start state.
53+
const statespace::StateSpace::State* mStartState;
54+
55+
/// Goal States.
56+
const GoalStates mGoalStates;
57+
};
58+
59+
} // namespace planner
60+
} // namespace aikido
61+
62+
#endif // AIKIDO_PLANNER_CONFIGURATIONTOCONFIGURATIONS_HPP_
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#ifndef AIKIDO_PLANNER_CONFIGURATIONTOENDEFFECTOROFFSET_HPP_
2+
#define AIKIDO_PLANNER_CONFIGURATIONTOENDEFFECTOROFFSET_HPP_
3+
4+
#include <dart/dart.hpp>
5+
#include "aikido/constraint/Testable.hpp"
6+
#include "aikido/planner/Problem.hpp"
7+
#include "aikido/statespace/StateSpace.hpp"
8+
#include "aikido/trajectory/Interpolated.hpp"
9+
10+
namespace aikido {
11+
namespace planner {
12+
13+
/// Planning problem to plan to desired end-effector offset while maintaining
14+
/// the current end-effector orientation.
15+
class ConfigurationToEndEffectorOffset : public Problem
16+
{
17+
public:
18+
/// Constructor.
19+
///
20+
/// \param[in] stateSpace State space.
21+
/// \param[in] endEffectorBodyNode BodyNode to be planned to move to a desired
22+
/// offest while maintaining the current orientation.
23+
/// \param[in] startState Start state.
24+
/// \param[in] direction Unit vector that represents the direction of motion
25+
/// [unit vector in the world frame].
26+
/// \param[in] signedDistance Signed distance to move, in meters.
27+
/// \param[in] interpolator Interpolator used to produce the output
28+
/// trajectory.
29+
/// \param[in] constraint Trajectory-wide constraint that must be satisfied.
30+
/// \throw If the size of \c direction is zero.
31+
ConfigurationToEndEffectorOffset(
32+
statespace::ConstStateSpacePtr stateSpace,
33+
dart::dynamics::ConstBodyNodePtr endEffectorBodyNode,
34+
const statespace::StateSpace::State* startState,
35+
const Eigen::Vector3d& direction,
36+
double signedDistance,
37+
constraint::ConstTestablePtr constraint);
38+
39+
// Documentation inherited.
40+
const std::string& getType() const override;
41+
42+
/// Returns the type of the planning problem.
43+
static const std::string& getStaticType();
44+
45+
/// Returns the end-effector BodyNode to be planned to move a desired offest
46+
/// while maintaining the current orientation.
47+
dart::dynamics::ConstBodyNodePtr getEndEffectorBodyNode() const;
48+
49+
/// Returns the start state.
50+
const statespace::StateSpace::State* getStartState() const;
51+
52+
/// Returns the direction of motion specified in the world frame.
53+
///
54+
/// \note The direction is allowed to be zero vector.
55+
const Eigen::Vector3d& getDirection() const;
56+
57+
/// Returns the signed distance in meters to move in the specified direction.
58+
double getDistance() const;
59+
60+
protected:
61+
/// End-effector body node.
62+
const dart::dynamics::ConstBodyNodePtr mEndEffectorBodyNode;
63+
64+
/// Start state.
65+
const statespace::StateSpace::State* mStartState;
66+
67+
/// Direction of motion.
68+
const Eigen::Vector3d mDirection;
69+
70+
/// Signed distance to move in the direction specified.
71+
const double mDistance;
72+
};
73+
74+
} // namespace planner
75+
} // namespace aikido
76+
77+
#endif // AIKIDO_PLANNER_CONFIGURATIONTOENDEFFECTOROFFSET_HPP_
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#ifndef AIKIDO_PLANNER_CONFIGURATIONTOENDEFFECTORPOSE_HPP_
2+
#define AIKIDO_PLANNER_CONFIGURATIONTOENDEFFECTORPOSE_HPP_
3+
4+
#include <dart/dart.hpp>
5+
#include "aikido/planner/Problem.hpp"
6+
#include "aikido/statespace/StateSpace.hpp"
7+
#include "aikido/trajectory/Interpolated.hpp"
8+
9+
namespace aikido {
10+
namespace planner {
11+
12+
/// Planning problem to plan to a desired end-effector pose.
13+
class ConfigurationToEndEffectorPose : public Problem
14+
{
15+
public:
16+
/// Constructor.
17+
///
18+
/// \param[in] stateSpace State space.
19+
/// \param[in] endEffectorBodyNode BodyNode to be planned to move to a desired
20+
/// pose.
21+
/// \param[in] startState Start state.
22+
/// \param[in] goalPose Goal pose.
23+
/// \throw If \c stateSpace is not compatible with \c constraint's state
24+
/// space.
25+
ConfigurationToEndEffectorPose(
26+
statespace::ConstStateSpacePtr stateSpace,
27+
dart::dynamics::ConstBodyNodePtr endEffectorBodyNode,
28+
const statespace::StateSpace::State* startState,
29+
const Eigen::Isometry3d& goalPose,
30+
constraint::ConstTestablePtr constraint);
31+
32+
// Documentation inherited.
33+
const std::string& getType() const override;
34+
35+
/// Returns the type of the planning problem.
36+
static const std::string& getStaticType();
37+
38+
/// Returns the end-effector BodyNode to be planned to move to a desired pose.
39+
dart::dynamics::ConstBodyNodePtr getEndEffectorBodyNode() const;
40+
41+
/// Returns the start state.
42+
const statespace::StateSpace::State* getStartState() const;
43+
44+
/// Returns the goal pose.
45+
const Eigen::Isometry3d& getGoalPose() const;
46+
47+
protected:
48+
// Need this due to mGoalPose.
49+
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
50+
51+
/// End-effector body node.
52+
const dart::dynamics::ConstBodyNodePtr mEndEffectorBodyNode;
53+
54+
/// Start state.
55+
const statespace::StateSpace::State* mStartState;
56+
57+
/// Goal pose.
58+
const Eigen::Isometry3d mGoalPose;
59+
};
60+
61+
} // namespace planner
62+
} // namespace aikido
63+
64+
#endif // AIKIDO_PLANNER_CONFIGURATIONTOENDEFFECTORPOSE_HPP_

0 commit comments

Comments
 (0)