Skip to content

Commit

Permalink
Integrated feedback, and fixes to have tests to pass
Browse files Browse the repository at this point in the history
  • Loading branch information
roveri-marco committed Apr 5, 2024
1 parent 0382612 commit 5a55251
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 18 deletions.
4 changes: 2 additions & 2 deletions plansys2_bringup/params/plansys2_params.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
planner_client:
ros__parameters:
plan_solver_timeout: 15
plan_solver_timeout: 15.0
planner:
ros__parameters:
plan_solver_timeout: 15
plan_solver_timeout: 15.0
plan_solver_plugins: ["POPF"]
POPF:
plugin: "plansys2/POPFPlanSolver"
Expand Down
4 changes: 3 additions & 1 deletion plansys2_core/include/plansys2_core/PlanSolverBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "rclcpp/rclcpp.hpp"
#include "rclcpp_lifecycle/lifecycle_node.hpp"

using namespace std::chrono_literals;

namespace plansys2
{

Expand Down Expand Up @@ -53,7 +55,7 @@ class PlanSolverBase
virtual std::optional<plansys2_msgs::msg::Plan> getPlan(
const std::string & domain, const std::string & problem,
const std::string & node_namespace = "",
const int solver_timeout = 15) = 0;
const rclcpp::Duration solver_timeout = 15s) = 0;

/**
* @brief Exposes a capability to validate a PDDL domain.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class PlannerClient : public PlannerInterface
get_plan_client_;

rclcpp::Node::SharedPtr node_;
int solver_timeout_ = 15;
rclcpp::Duration solver_timeout_ = rclcpp::Duration(15, 0);
};

} // namespace plansys2
Expand Down
2 changes: 1 addition & 1 deletion plansys2_planner/include/plansys2_planner/PlannerNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class PlannerNode : public rclcpp_lifecycle::LifecycleNode
std::vector<std::string> default_types_;
std::vector<std::string> solver_ids_;
std::vector<std::string> solver_types_;
int solver_timeout_;
rclcpp::Duration solver_timeout_;

rclcpp::Service<plansys2_msgs::srv::GetPlan>::SharedPtr
get_plan_service_;
Expand Down
14 changes: 9 additions & 5 deletions plansys2_planner/src/plansys2_planner/PlannerClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ PlannerClient::PlannerClient()

get_plan_client_ = node_->create_client<plansys2_msgs::srv::GetPlan>("planner/get_plan");

node_->declare_parameter("plan_solver_timeout", solver_timeout_);
double timeout;
node_->declare_parameter("plan_solver_timeout", timeout);

node_->get_parameter("plan_solver_timeout", solver_timeout_);
RCLCPP_INFO(node_->get_logger(), "Planner CLient created with timeout %d", solver_timeout_);
node_->get_parameter("plan_solver_timeout", timeout);
solver_timeout_ = rclcpp::Duration((int32_t)timeout, 0);
RCLCPP_INFO(
node_->get_logger(), "Planner CLient created with timeout %g",
solver_timeout_.seconds());
}

std::optional<plansys2_msgs::msg::Plan>
Expand All @@ -49,10 +53,10 @@ PlannerClient::getPlan(
get_plan_client_->get_service_name() <<
" service client: waiting for service to appear...");
}
int timeout = solver_timeout_;
int32_t timeout = solver_timeout_.seconds();
if (timeout <= 0) {
std::string timeout_str = "Get Plan service called with negative timed out:";
timeout_str += std::to_string(solver_timeout_);
timeout_str += std::to_string(timeout);
timeout_str += ". Setting to 15 seconds";
RCLCPP_ERROR(node_->get_logger(), timeout_str.c_str());
timeout = 15;
Expand Down
16 changes: 11 additions & 5 deletions plansys2_planner/src/plansys2_planner/PlannerNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,21 @@

#include "lifecycle_msgs/msg/state.hpp"

using namespace std::chrono_literals;

namespace plansys2
{

PlannerNode::PlannerNode()
: rclcpp_lifecycle::LifecycleNode("planner"),
lp_loader_("plansys2_core", "plansys2::PlanSolverBase"),
default_ids_{},
default_types_{}
default_types_{},
solver_timeout_(15s)
{
declare_parameter("plan_solver_plugins", default_ids_);
solver_timeout_ = 15;
declare_parameter("plan_solver_timeout", solver_timeout_);
double timeout = solver_timeout_.seconds();
declare_parameter("plan_solver_timeout", timeout);
}


Expand All @@ -44,11 +47,14 @@ CallbackReturnT
PlannerNode::on_configure(const rclcpp_lifecycle::State & state)
{
auto node = shared_from_this();
double timeout;

RCLCPP_INFO(get_logger(), "[%s] Configuring...", get_name());

get_parameter("plan_solver_plugins", solver_ids_);
get_parameter("plan_solver_timeout", solver_timeout_);
get_parameter("plan_solver_timeout", timeout);

solver_timeout_ = rclcpp::Duration((int32_t)timeout, 0);

if (!solver_ids_.empty()) {
if (solver_ids_ == default_ids_) {
Expand Down Expand Up @@ -86,7 +92,7 @@ PlannerNode::on_configure(const rclcpp_lifecycle::State & state)
"POPF", "plansys2/POPFPlanSolver");
}

RCLCPP_INFO(get_logger(), "[%s] Solver Timeout %d", get_name(), solver_timeout_);
RCLCPP_INFO(get_logger(), "[%s] Solver Timeout %g", get_name(), solver_timeout_.seconds());

get_plan_service_ = create_service<plansys2_msgs::srv::GetPlan>(
"planner/get_plan",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

#include "plansys2_core/PlanSolverBase.hpp"

// using namespace std::chrono_literals;
using std::chrono_literals::operator""s;

namespace plansys2
{

Expand All @@ -42,7 +45,7 @@ class POPFPlanSolver : public PlanSolverBase
std::optional<plansys2_msgs::msg::Plan> getPlan(
const std::string & domain, const std::string & problem,
const std::string & node_namespace = "",
const int solver_timeout = 15);
const rclcpp::Duration solver_timeout = 15s);

bool isDomainValid(
const std::string & domain,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ std::optional<plansys2_msgs::msg::Plan>
POPFPlanSolver::getPlan(
const std::string & domain, const std::string & problem,
const std::string & node_namespace,
const int solver_timeout)
const rclcpp::Duration solver_timeout)
{
if (system(nullptr) == 0) {
return {};
Expand Down Expand Up @@ -114,7 +114,7 @@ POPFPlanSolver::getPlan(

RCLCPP_INFO(
lc_node_->get_logger(), "[%s-popf] called with timeout %d seconds",
lc_node_->get_name(), solver_timeout);
lc_node_->get_name(), solver_timeout.seconds());

const auto plan_file_path = output_dir / std::filesystem::path("plan");
const auto args = lc_node_->get_parameter(arguments_parameter_name_).value_to_string();
Expand Down

0 comments on commit 5a55251

Please sign in to comment.