|
1 | 1 | #include <chrono> |
| 2 | +#include <sstream> |
2 | 3 | #include <stdexcept> |
3 | 4 |
|
4 | 5 | #include <roboplan/core/path_utils.hpp> |
@@ -32,28 +33,16 @@ RRT::RRT(const std::shared_ptr<Scene> scene, const RRTOptions& options) |
32 | 33 | state_space_.set_bounds(lower_bounds, upper_bounds); |
33 | 34 | }; |
34 | 35 |
|
35 | | -tl::expected<JointPath, std::string> RRT::plan_expected(const JointConfiguration& start, |
36 | | - const JointConfiguration& goal) { |
37 | | - std::optional<JointPath> maybe_path = plan(start, goal); |
38 | | - |
39 | | - if (maybe_path.has_value()) { |
40 | | - return maybe_path.value(); |
41 | | - } else { |
42 | | - return tl::make_unexpected("Failed to find path!"); |
43 | | - } |
44 | | -} |
45 | | - |
46 | | -std::optional<JointPath> RRT::plan(const JointConfiguration& start, |
47 | | - const JointConfiguration& goal) { |
| 36 | +tl::expected<JointPath, std::string> RRT::plan(const JointConfiguration& start, |
| 37 | + const JointConfiguration& goal) { |
48 | 38 | std::cout << "Planning...\n"; |
49 | 39 |
|
50 | 40 | const auto& q_start = start.positions; |
51 | 41 | const auto& q_goal = goal.positions; |
52 | 42 |
|
53 | 43 | // Ensure the start and goal poses are valid |
54 | 44 | if (!scene_->isValidPose(q_start) || !scene_->isValidPose(q_goal)) { |
55 | | - std::cout << "Invalid poses requested, cannot plan!\n"; |
56 | | - return std::nullopt; |
| 45 | + return tl::make_unexpected("Invalid poses requested, cannot plan!"); |
57 | 46 | } |
58 | 47 |
|
59 | 48 | // Check whether direct connection between the start and goal are possible. |
@@ -83,14 +72,18 @@ std::optional<JointPath> RRT::plan(const JointConfiguration& start, |
83 | 72 | auto elapsed = |
84 | 73 | std::chrono::duration<double>(std::chrono::steady_clock::now() - start_time).count(); |
85 | 74 | if (options_.max_planning_time > 0 && options_.max_planning_time <= elapsed) { |
86 | | - std::cout << "RRT timed out after " << options_.max_planning_time << " seconds.\n"; |
87 | | - break; |
| 75 | + std::stringstream ss; |
| 76 | + ss << "RRT timed out after " << options_.max_planning_time << " seconds."; |
| 77 | + std::cout << ss.str() << "\n"; |
| 78 | + return tl::make_unexpected(ss.str()); |
88 | 79 | } |
89 | 80 |
|
90 | 81 | // Check loop termination criteria. |
91 | 82 | if (start_nodes_.size() + goal_nodes_.size() >= options_.max_nodes) { |
92 | | - std::cout << "Added maximum number of nodes (" << options_.max_nodes << ").\n"; |
93 | | - break; |
| 83 | + std::stringstream ss; |
| 84 | + ss << "Added maximum number of nodes (" << options_.max_nodes << ")."; |
| 85 | + std::cout << ss.str() << "\n"; |
| 86 | + return tl::make_unexpected(ss.str()); |
94 | 87 | } |
95 | 88 |
|
96 | 89 | // Set grow and target tree for this loop iteration. |
@@ -126,8 +119,7 @@ std::optional<JointPath> RRT::plan(const JointConfiguration& start, |
126 | 119 | } |
127 | 120 | } |
128 | 121 |
|
129 | | - std::cout << "Unable to find a plan!\n"; |
130 | | - return std::nullopt; |
| 122 | + return tl::make_unexpected("Unable to find a path!"); |
131 | 123 | } |
132 | 124 |
|
133 | 125 | void RRT::initializeTree(KdTree& tree, std::vector<Node>& nodes, const Eigen::VectorXd& q_init, |
|
0 commit comments