Skip to content

Commit

Permalink
fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Rezenders committed Sep 2, 2024
1 parent 2262740 commit 298f39e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ class DomainExpertClient : public DomainExpertInterface
rclcpp::Client<plansys2_msgs::srv::GetStates>::SharedPtr get_predicates_client_;
rclcpp::Client<plansys2_msgs::srv::GetStates>::SharedPtr get_functions_client_;
rclcpp::Client<plansys2_msgs::srv::GetStates>::SharedPtr get_derived_predicates_client_;
rclcpp::Client<plansys2_msgs::srv::GetDomainDerivedPredicateDetails>::SharedPtr get_derived_predicate_details_client_;
rclcpp::Client<plansys2_msgs::srv::GetDomainDerivedPredicateDetails>::SharedPtr
get_derived_predicate_details_client_;
rclcpp::Client<plansys2_msgs::srv::GetDomainActions>::SharedPtr get_actions_client_;
rclcpp::Client<plansys2_msgs::srv::GetDomainActions>::SharedPtr get_durative_actions_client_;
rclcpp::Client<plansys2_msgs::srv::GetNodeDetails>::SharedPtr get_predicate_details_client_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ DomainExpert::getFunction(const std::string & function)
}

std::vector<plansys2::Predicate>
DomainExpert::getDerivedPredicates(){
DomainExpert::getDerivedPredicates()
{
std::vector<plansys2::Predicate> ret;
for (unsigned i = 0; i < domain_->derived.size(); i++) {
plansys2_msgs::msg::Node pred;
Expand All @@ -179,7 +180,9 @@ DomainExpert::getDerivedPredicates(){
}

std::vector<plansys2_msgs::msg::Derived>
DomainExpert::getDerivedPredicate(const std::string & predicate, const std::vector<std::string> & params){
DomainExpert::getDerivedPredicate(
const std::string & predicate, const std::vector<std::string> & params)
{
std::vector<plansys2_msgs::msg::Derived> ret;

std::string predicate_search = predicate;
Expand All @@ -194,7 +197,7 @@ DomainExpert::getDerivedPredicate(const std::string & predicate, const std::vect
plansys2_msgs::msg::Derived derived;
derived.predicate.name = predicate_search;

//Parameters
// Parameters
for (unsigned j = 0; j < domain_->derived[i]->params.size(); j++) {
plansys2_msgs::msg::Param param;
param.name = "?" + domain_->types[domain_->derived[i]->params[j]]->getName() +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ DomainExpertClient::DomainExpertClient()
"domain_expert/get_domain_functions");
get_derived_predicates_client_ = node_->create_client<plansys2_msgs::srv::GetStates>(
"domain_expert/get_domain_derived_predicates");
get_derived_predicate_details_client_ = node_->create_client<plansys2_msgs::srv::GetDomainDerivedPredicateDetails>(
get_derived_predicate_details_client_ =
node_->create_client<plansys2_msgs::srv::GetDomainDerivedPredicateDetails>(
"domain_expert/get_domain_derived_predicate_details");
get_actions_client_ = node_->create_client<plansys2_msgs::srv::GetDomainActions>(
"domain_expert/get_domain_actions");
Expand Down Expand Up @@ -334,7 +335,8 @@ DomainExpertClient::getDerivedPredicates()
}

std::vector<plansys2_msgs::msg::Derived>
DomainExpertClient::getDerivedPredicate(const std::string & predicate, const std::vector<std::string> & params)
DomainExpertClient::getDerivedPredicate(
const std::string & predicate, const std::vector<std::string> & params)
{
while (!get_derived_predicate_details_client_->wait_for_service(std::chrono::seconds(1))) {
if (!rclcpp::ok()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ DomainExpertNode::DomainExpertNode()
&DomainExpertNode::get_domain_derived_predicates_service_callback,
this, std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3));
get_domain_derived_predicate_details_service_ = create_service<plansys2_msgs::srv::GetDomainDerivedPredicateDetails>(
get_domain_derived_predicate_details_service_ =
create_service<plansys2_msgs::srv::GetDomainDerivedPredicateDetails>(
"domain_expert/get_domain_derived_predicate_details", std::bind(
&DomainExpertNode::get_domain_derived_predicate_details_service_callback,
this, std::placeholders::_1, std::placeholders::_2,
Expand Down Expand Up @@ -453,11 +454,14 @@ DomainExpertNode::get_domain_derived_predicate_details_service_callback(
} else {
auto predicates = domain_expert_->getDerivedPredicate(request->predicate);

if (predicates.size()>0) {
if (predicates.size() > 0) {
response->predicates = predicates;
response->success = true;
} else {
RCLCPP_WARN(get_logger(), "Requesting a non-existing derived predicate [%s]", request->predicate.c_str());
RCLCPP_WARN(
get_logger(),
"Requesting a non-existing derived predicate [%s]",
request->predicate.c_str());
response->success = false;
response->error_info = "Derived predicate not found";
}
Expand Down
2 changes: 1 addition & 1 deletion plansys2_domain_expert/test/unit/domain_expert_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ TEST(domain_expert, get_derived_predicate_params)
plansys2::DomainExpert domain_expert(domain_str);

auto pred_1 = domain_expert.getDerivedPredicate("inferred-robot_at");
ASSERT_TRUE(pred_1.size()>0);
ASSERT_GT(pred_1.size(), 0);
ASSERT_EQ(pred_1[0].predicate.name, "inferred-robot_at");
ASSERT_EQ(pred_1[0].predicate.parameters.size(), 2);
ASSERT_EQ(pred_1[0].predicate.parameters[0].name, "?robot0");
Expand Down
6 changes: 4 additions & 2 deletions plansys2_domain_expert/test/unit/domain_reader_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,10 @@ TEST(domain_reader, derived_predicates)

std::string req0_str = "(:predicates\n(robot_at leia bedroom) (person_at paco kitchen)\n)";

std::string req1_str = "(:derived (inferred-robot_localized ?r)\n(exists (?l)\n(and\n(robot_at ?r ?l)))\n)";
std::string req1_estr = "(:derived (inferred-robot_localized ?r)\n(exists (?l)\n(and\n(robot_at ?r ?l)))\n)";
std::string req1_str =
"(:derived (inferred-robot_localized ?r)\n(exists (?l)\n(and\n(robot_at ?r ?l)))\n)";
std::string req1_estr =
"(:derived (inferred-robot_localized ?r)\n(exists (?l)\n(and\n(robot_at ?r ?l)))\n)";

auto res0 = dr.get_derived_test(req0_str);
auto res1 = dr.get_derived_test(req1_str);
Expand Down

0 comments on commit 298f39e

Please sign in to comment.