Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transparent pddl #62

Merged
merged 5 commits into from
Jan 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions plansys2_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,31 @@ set(dependencies

include_directories(include)

add_library(${PROJECT_NAME} SHARED
src/plansys2_core/Utils.cpp
)

install(DIRECTORY include/
DESTINATION include/
)

install(TARGETS
${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION lib/${PROJECT_NAME}
)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()

find_package(ament_cmake_gtest REQUIRED)
add_subdirectory(test)
endif()

ament_export_include_directories(include)
ament_export_dependencies(${dependencies})
ament_export_libraries(${PROJECT_NAME})

ament_package()
28 changes: 28 additions & 0 deletions plansys2_core/include/plansys2_core/Utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2019 Intelligent Robotics Lab
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef PLANSYS2_CORE__UTILS_HPP_
#define PLANSYS2_CORE__UTILS_HPP_

#include <string>
#include <vector>

namespace plansys2
{

std::vector<std::string> tokenize(const std::string & string, const std::string & delim);

} // namespace plansys2

#endif // PLANSYS2_CORE__UTILS_HPP_
42 changes: 42 additions & 0 deletions plansys2_core/src/plansys2_core/Utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2019 Intelligent Robotics Lab
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <string>
#include <vector>

#include "plansys2_core/Utils.hpp"

namespace plansys2
{

std::vector<std::string> tokenize(const std::string & string, const std::string & delim)
{
std::string::size_type lastPos = 0, pos = string.find_first_of(delim, lastPos);
std::vector<std::string> tokens;

while (lastPos != std::string::npos) {
if (pos != lastPos) {
tokens.push_back(string.substr(lastPos, pos - lastPos));
}
lastPos = pos;
if (lastPos == std::string::npos || lastPos + 1 == string.length()) {
break;
}
pos = string.find_first_of(delim, ++lastPos);
}

return tokens;
}

} // namespace plansys2
2 changes: 2 additions & 0 deletions plansys2_core/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ament_add_gtest(utils_test utils_test.cpp)
target_link_libraries(utils_test ${PROJECT_NAME})
49 changes: 49 additions & 0 deletions plansys2_core/test/utils_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2029 Intelligent Robotics Lab
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <string>
#include <vector>

#include "gtest/gtest.h"
#include "plansys2_core/Utils.hpp"


TEST(domain_expert, functions)
{
std::string st1("this is a message");
std::vector<std::string> est1 = {"this", "is", "a", "message"};
std::vector<std::string> est1b = {"this", "a", "message"};
auto res1 = plansys2::tokenize(st1, " ");

ASSERT_EQ(res1, est1);
ASSERT_NE(res1, est1b);

std::string st2("this:is:a:message");
std::vector<std::string> est2 = {"this", "is", "a", "message"};
auto res2 = plansys2::tokenize(st2, ":");

ASSERT_EQ(res2, est2);

std::string st3("this is a message");
std::vector<std::string> est3 = {"this", "is", "a", "message"};
auto res3 = plansys2::tokenize(st3, " ");

ASSERT_EQ(res3, est3);
}

int main(int argc, char ** argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
3 changes: 3 additions & 0 deletions plansys2_domain_expert/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ find_package(rclcpp_lifecycle REQUIRED)
find_package(ament_index_cpp REQUIRED)
find_package(plansys2_pddl_parser REQUIRED)
find_package(plansys2_msgs REQUIRED)
find_package(plansys2_core REQUIRED)

set(CMAKE_CXX_STANDARD 17)

Expand All @@ -21,13 +22,15 @@ set(dependencies
plansys2_pddl_parser
ament_index_cpp
plansys2_msgs
plansys2_core
)

include_directories(include)

set(DOMAIN_EXPERT_SOURCES
src/plansys2_domain_expert/DomainExpert.cpp
src/plansys2_domain_expert/DomainExpertClient.cpp
src/plansys2_domain_expert/DomainReader.cpp
src/plansys2_domain_expert/Types.cpp
src/plansys2_domain_expert/DomainExpertNode.cpp
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
#include <optional>
#include <string>
#include <vector>
#include <memory>

#include "plansys2_pddl_parser/Domain.h"

#include "plansys2_domain_expert/DomainExpertInterface.hpp"
#include "plansys2_domain_expert/Types.hpp"
#include "plansys2_domain_expert/DomainReader.hpp"

namespace plansys2
{
Expand Down Expand Up @@ -112,7 +114,8 @@ class DomainExpert : public DomainExpertInterface
std::string getDomain();

private:
parser::pddl::Domain domain_;
std::shared_ptr<parser::pddl::Domain> domain_;
DomainReader domains_;
};

} // namespace plansys2
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2020 Intelligent Robotics Lab
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef PLANSYS2_DOMAIN_EXPERT__DOMAINREADER_HPP_
#define PLANSYS2_DOMAIN_EXPERT__DOMAINREADER_HPP_

#include <string>
#include <vector>

namespace plansys2
{

struct Domain
{
std::string requirements;
std::string types;
std::string predicates;
std::string functions;
std::vector<std::string> actions;
};

class DomainReader
{
public:
DomainReader();

void add_domain(const std::string & domain);
std::string get_joint_domain() const;

protected:
int get_end_block(const std::string & domain, std::size_t init_pos);

std::string get_requirements(std::string & domain);
std::string get_types(const std::string & domain);
std::string get_predicates(const std::string & domain);
std::string get_functions(const std::string & domain);
std::vector<std::string> get_actions(const std::string & domain);

private:
std::vector<Domain> domains_;
};

} // namespace plansys2

#endif // PLANSYS2_DOMAIN_EXPERT__DOMAINREADER_HPP_
1 change: 1 addition & 0 deletions plansys2_domain_expert/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<depend>ament_index_cpp</depend>
<depend>plansys2_pddl_parser</depend>
<depend>plansys2_msgs</depend>
<depend>plansys2_core</depend>

<test_depend>ament_lint_common</test_depend>
<test_depend>ament_lint_auto</test_depend>
Expand Down
Loading