adapted the environment for EnvInterfaceBase
This commit is contained in:
parent
71063b19aa
commit
18d2772cef
17 changed files with 447 additions and 74 deletions
56
env_manager/env_interface/CMakeLists.txt
Normal file
56
env_manager/env_interface/CMakeLists.txt
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
cmake_minimum_required(VERSION 3.8)
|
||||||
|
project(env_interface)
|
||||||
|
|
||||||
|
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||||
|
add_compile_options(-Wall -Wextra -Wpedantic)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(INCLUDE_DEPENDS
|
||||||
|
rclcpp_lifecycle
|
||||||
|
)
|
||||||
|
|
||||||
|
# find dependencies
|
||||||
|
find_package(ament_cmake REQUIRED)
|
||||||
|
foreach(Dependency IN LISTS INCLUDE_DEPENDS)
|
||||||
|
find_package(${Dependency} REQUIRED)
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
add_library(${PROJECT_NAME} SHARED
|
||||||
|
src/env_interface_base.cpp)
|
||||||
|
|
||||||
|
target_include_directories(${PROJECT_NAME} PUBLIC
|
||||||
|
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
|
||||||
|
$<INSTALL_INTERFACE:include/env_interface>
|
||||||
|
)
|
||||||
|
|
||||||
|
ament_target_dependencies(${PROJECT_NAME} PUBLIC ${INCLUDE_DEPENDS})
|
||||||
|
|
||||||
|
target_compile_definitions(${PROJECT_NAME} PRIVATE "ENVIROMENT_INTERFACE_BUILDING_DLL")
|
||||||
|
|
||||||
|
if(BUILD_TESTING)
|
||||||
|
find_package(ament_lint_auto REQUIRED)
|
||||||
|
# the following line skips the linter which checks for copyrights
|
||||||
|
# comment the line when a copyright and license is added to all source files
|
||||||
|
set(ament_cmake_copyright_FOUND TRUE)
|
||||||
|
# the following line skips cpplint (only works in a git repo)
|
||||||
|
# comment the line when this package is in a git repo and when
|
||||||
|
# a copyright and license is added to all source files
|
||||||
|
set(ament_cmake_cpplint_FOUND TRUE)
|
||||||
|
ament_lint_auto_find_test_dependencies()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
install(
|
||||||
|
DIRECTORY include/
|
||||||
|
DESTINATION include/env_interface
|
||||||
|
)
|
||||||
|
install(TARGETS ${PROJECT_NAME}
|
||||||
|
EXPORT export_${PROJECT_NAME}
|
||||||
|
ARCHIVE DESTINATION lib
|
||||||
|
LIBRARY DESTINATION lib
|
||||||
|
RUNTIME DESTINATION bin
|
||||||
|
)
|
||||||
|
|
||||||
|
ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
|
||||||
|
ament_export_dependencies(${INCLUDE_DEPENDS})
|
||||||
|
|
||||||
|
ament_package()
|
202
env_manager/env_interface/LICENSE
Normal file
202
env_manager/env_interface/LICENSE
Normal file
|
@ -0,0 +1,202 @@
|
||||||
|
|
||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
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.
|
|
@ -0,0 +1,14 @@
|
||||||
|
#include "env_interface/env_interface_base.hpp"
|
||||||
|
|
||||||
|
namespace env_interface
|
||||||
|
{
|
||||||
|
class EnvInterface : public EnvInterfaceBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
EnvInterface() = default;
|
||||||
|
virtual ~EnvInterface() = default;
|
||||||
|
|
||||||
|
};
|
||||||
|
} // namespace env_interface
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
#include "rclcpp/rclcpp.hpp"
|
#include "rclcpp/rclcpp.hpp"
|
||||||
#include "rclcpp_lifecycle/lifecycle_node.hpp"
|
#include "rclcpp_lifecycle/lifecycle_node.hpp"
|
||||||
|
|
||||||
// TODO: BaseInterface class for next enviroments based on LifecycleNodeInterface
|
|
||||||
// It's should be like ControllerInterfaceBase class from ros2_control
|
|
||||||
|
|
||||||
namespace env_interface
|
namespace env_interface
|
||||||
{
|
{
|
||||||
|
|
18
env_manager/env_interface/package.xml
Normal file
18
env_manager/env_interface/package.xml
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
|
||||||
|
<package format="3">
|
||||||
|
<name>env_interface</name>
|
||||||
|
<version>0.0.0</version>
|
||||||
|
<description>TODO: Package description</description>
|
||||||
|
<maintainer email="ur.narmak@gmail.com">bill-finger</maintainer>
|
||||||
|
<license>Apache-2.0</license>
|
||||||
|
|
||||||
|
<buildtool_depend>ament_cmake</buildtool_depend>
|
||||||
|
|
||||||
|
<test_depend>ament_lint_auto</test_depend>
|
||||||
|
<test_depend>ament_lint_common</test_depend>
|
||||||
|
|
||||||
|
<export>
|
||||||
|
<build_type>ament_cmake</build_type>
|
||||||
|
</export>
|
||||||
|
</package>
|
|
@ -1,4 +1,4 @@
|
||||||
#include "env_manager/env_base_interface.hpp"
|
#include "env_interface/env_interface_base.hpp"
|
||||||
|
|
||||||
namespace env_interface
|
namespace env_interface
|
||||||
{
|
{
|
|
@ -10,6 +10,7 @@ set(INCLUDE_DEPENDS
|
||||||
rclcpp_lifecycle
|
rclcpp_lifecycle
|
||||||
env_manager_interfaces
|
env_manager_interfaces
|
||||||
pluginlib
|
pluginlib
|
||||||
|
env_interface
|
||||||
)
|
)
|
||||||
|
|
||||||
# find dependencies
|
# find dependencies
|
||||||
|
|
9
env_manager/env_manager/config/test_params.yaml
Normal file
9
env_manager/env_manager/config/test_params.yaml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
env_manager:
|
||||||
|
ros__parameters:
|
||||||
|
gz_enviroment:
|
||||||
|
type: gz_enviroment/GzEnviroment
|
||||||
|
|
||||||
|
|
||||||
|
gz_enviroment:
|
||||||
|
ros__parameters:
|
||||||
|
mesh_name: "monkey"
|
|
@ -7,12 +7,15 @@
|
||||||
#include "env_manager_interfaces/srv/configure_env.hpp"
|
#include "env_manager_interfaces/srv/configure_env.hpp"
|
||||||
#include "env_manager_interfaces/srv/unload_env.hpp"
|
#include "env_manager_interfaces/srv/unload_env.hpp"
|
||||||
|
|
||||||
|
#include "env_interface/env_interface.hpp"
|
||||||
|
|
||||||
#include "pluginlib/class_loader.hpp"
|
#include "pluginlib/class_loader.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace env_manager
|
namespace env_manager
|
||||||
{
|
{
|
||||||
using EnvInterfaceSharedPtr = std::shared_ptr<rclcpp_lifecycle::LifecycleNode>;
|
using EnvInterface = env_interface::EnvInterface;
|
||||||
|
using EnvInterfaceSharedPtr = std::shared_ptr<env_interface::EnvInterface>;
|
||||||
using EnvStateReturnType = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;
|
using EnvStateReturnType = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;
|
||||||
|
|
||||||
struct EnvSpec
|
struct EnvSpec
|
||||||
|
@ -43,7 +46,7 @@ public:
|
||||||
|
|
||||||
// EnvInterfaceSharedPtr loadEnv(const std::string& env_name);
|
// EnvInterfaceSharedPtr loadEnv(const std::string& env_name);
|
||||||
EnvInterfaceSharedPtr loadEnv(const std::string& env_name, const std::string& env_class_type);
|
EnvInterfaceSharedPtr loadEnv(const std::string& env_name, const std::string& env_class_type);
|
||||||
EnvInterfaceSharedPtr unloadEnv();
|
EnvStateReturnType unloadEnv(const std::string &env_name);
|
||||||
EnvStateReturnType configureEnv(const std::string& env_name);
|
EnvStateReturnType configureEnv(const std::string& env_name);
|
||||||
EnvInterfaceSharedPtr addEnv(const EnvSpec& enviment);
|
EnvInterfaceSharedPtr addEnv(const EnvSpec& enviment);
|
||||||
|
|
||||||
|
@ -87,7 +90,7 @@ private:
|
||||||
rclcpp::CallbackGroup::SharedPtr m_callback_group;
|
rclcpp::CallbackGroup::SharedPtr m_callback_group;
|
||||||
rclcpp::Executor::SharedPtr m_executor;
|
rclcpp::Executor::SharedPtr m_executor;
|
||||||
|
|
||||||
std::shared_ptr<pluginlib::ClassLoader<rclcpp_lifecycle::LifecycleNode>> m_loader;
|
std::shared_ptr<pluginlib::ClassLoader<env_interface::EnvInterface>> m_loader;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
<depend>env_manager_interfaces</depend>
|
<depend>env_manager_interfaces</depend>
|
||||||
<depend>rclcpp</depend>
|
<depend>rclcpp</depend>
|
||||||
<depend>rclcpp_lifecycle</depend>
|
<depend>rclcpp_lifecycle</depend>
|
||||||
|
<depend>env_inteface</depend>
|
||||||
|
|
||||||
<test_depend>ament_lint_auto</test_depend>
|
<test_depend>ament_lint_auto</test_depend>
|
||||||
<test_depend>ament_lint_common</test_depend>
|
<test_depend>ament_lint_common</test_depend>
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#include "env_manager/env_manager.hpp"
|
#include "env_manager/env_manager.hpp"
|
||||||
#include "nlohmann/json.hpp"
|
#include "nlohmann/json.hpp"
|
||||||
|
|
||||||
static constexpr const char * ENV_INTERFACE_BASE_CLASS_NAMESPACE = "rclcpp_lifecycle";
|
static constexpr const char * ENV_INTERFACE_BASE_CLASS_NAMESPACE = "env_interface";
|
||||||
static constexpr const char * ENV_INTERFACE_BASE_CLASS_NAME = "rclcpp_lifecycle::LifecycleNode";
|
static constexpr const char * ENV_INTERFACE_BASE_CLASS_NAME = "env_interface::EnvInterface";
|
||||||
|
|
||||||
namespace env_manager
|
namespace env_manager
|
||||||
{
|
{
|
||||||
|
@ -13,7 +13,7 @@ EnvManager::EnvManager(
|
||||||
rclcpp::NodeOptions & options)
|
rclcpp::NodeOptions & options)
|
||||||
: rclcpp::Node(node_name, node_namespace, options),
|
: rclcpp::Node(node_name, node_namespace, options),
|
||||||
m_executor(executor),
|
m_executor(executor),
|
||||||
m_loader(std::make_shared<pluginlib::ClassLoader<rclcpp_lifecycle::LifecycleNode>>(
|
m_loader(std::make_shared<pluginlib::ClassLoader<env_interface::EnvInterface>>(
|
||||||
ENV_INTERFACE_BASE_CLASS_NAMESPACE, ENV_INTERFACE_BASE_CLASS_NAME))
|
ENV_INTERFACE_BASE_CLASS_NAMESPACE, ENV_INTERFACE_BASE_CLASS_NAME))
|
||||||
{
|
{
|
||||||
initServices();
|
initServices();
|
||||||
|
@ -77,21 +77,7 @@ EnvManager::unloadEnv_cb(
|
||||||
env_manager_interfaces::srv::UnloadEnv::Response::SharedPtr response)
|
env_manager_interfaces::srv::UnloadEnv::Response::SharedPtr response)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(m_env_mutex);
|
std::lock_guard<std::mutex> lock(m_env_mutex);
|
||||||
|
response->ok = unloadEnv(request->name) == EnvStateReturnType::SUCCESS;
|
||||||
auto it = std::find_if(m_active_envs.begin(), m_active_envs.end(), [&request](const EnvSpec& env) {
|
|
||||||
return env.name == request->name;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (it != m_active_envs.end()) {
|
|
||||||
m_executor->remove_node(it->env_ptr->get_node_base_interface());
|
|
||||||
m_active_envs.erase(it);
|
|
||||||
response->ok = true;
|
|
||||||
} else {
|
|
||||||
RCLCPP_ERROR(this->get_logger(),
|
|
||||||
"Environment '%s' not found in the active environments list.",
|
|
||||||
request->name.c_str());
|
|
||||||
response->ok = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -102,8 +88,16 @@ EnvManager::addEnv(const EnvSpec& enviroment)
|
||||||
// generate list of active enviroments
|
// generate list of active enviroments
|
||||||
// std::string unique_env_name = enviroment.name;// + "_" + std::to_string(m_active_envs.size());
|
// std::string unique_env_name = enviroment.name;// + "_" + std::to_string(m_active_envs.size());
|
||||||
// m_active_envs[unique_env_name] = enviroment.env_ptr;
|
// m_active_envs[unique_env_name] = enviroment.env_ptr;
|
||||||
|
if (enviroment.env_ptr->init(
|
||||||
|
enviroment.name, get_namespace()) ==
|
||||||
|
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::ERROR)
|
||||||
|
{
|
||||||
|
RCLCPP_ERROR(get_logger(), "Enviroment with name %s cannot been initialized", enviroment.name.c_str());
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
m_active_envs.push_back(enviroment);
|
m_active_envs.push_back(enviroment);
|
||||||
m_executor->add_node(enviroment.env_ptr->get_node_base_interface());
|
m_executor->add_node(enviroment.env_ptr->getNode()->get_node_base_interface());
|
||||||
return enviroment.env_ptr;
|
return enviroment.env_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,6 +139,26 @@ EnvManager::loadEnv(const std::string& env_name, const std::string& env_class_ty
|
||||||
return addEnv(enviroment);
|
return addEnv(enviroment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EnvStateReturnType
|
||||||
|
EnvManager::unloadEnv(const std::string& env_name)
|
||||||
|
{
|
||||||
|
auto it = std::find_if(m_active_envs.begin(), m_active_envs.end(), [&env_name](const EnvSpec& env) {
|
||||||
|
return env.name == env_name;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (it != m_active_envs.end()) {
|
||||||
|
m_executor->remove_node(it->env_ptr->getNode()->get_node_base_interface());
|
||||||
|
m_active_envs.erase(it);
|
||||||
|
return EnvStateReturnType::SUCCESS;
|
||||||
|
} else {
|
||||||
|
RCLCPP_ERROR(this->get_logger(),
|
||||||
|
"Environment '%s' not found in the active environments list.",
|
||||||
|
env_name.c_str());
|
||||||
|
return EnvStateReturnType::ERROR;
|
||||||
|
}
|
||||||
|
return EnvStateReturnType::FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
// EnvInterfaceSharedPtr
|
// EnvInterfaceSharedPtr
|
||||||
// EnvManager::loadEnv(const std::string env_name)
|
// EnvManager::loadEnv(const std::string env_name)
|
||||||
// {
|
// {
|
||||||
|
@ -169,7 +183,10 @@ EnvManager::configureEnv(const std::string& env_name)
|
||||||
return EnvStateReturnType::FAILURE;
|
return EnvStateReturnType::FAILURE;
|
||||||
}
|
}
|
||||||
it->env_ptr->configure();
|
it->env_ptr->configure();
|
||||||
|
// it->env_ptr->getNode()->configure();
|
||||||
// it->env_ptr->activate();
|
// it->env_ptr->activate();
|
||||||
|
it->env_ptr->getNode()->activate();
|
||||||
|
|
||||||
return EnvStateReturnType::SUCCESS;
|
return EnvStateReturnType::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ set(THIS_PACKAGE_INCLUDE_DEPENDS
|
||||||
ignition-transport11
|
ignition-transport11
|
||||||
ignition-msgs8
|
ignition-msgs8
|
||||||
ros_gz_bridge
|
ros_gz_bridge
|
||||||
|
env_interface
|
||||||
)
|
)
|
||||||
|
|
||||||
# find dependencies
|
# find dependencies
|
||||||
|
@ -38,7 +39,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC
|
||||||
ament_target_dependencies(${PROJECT_NAME} PUBLIC ${THIS_PACKAGE_INCLUDE_DEPENDS})
|
ament_target_dependencies(${PROJECT_NAME} PUBLIC ${THIS_PACKAGE_INCLUDE_DEPENDS})
|
||||||
target_compile_definitions(${PROJECT_NAME} PRIVATE "GZENVIROMENT_BUILDING_DLL")
|
target_compile_definitions(${PROJECT_NAME} PRIVATE "GZENVIROMENT_BUILDING_DLL")
|
||||||
#TODO: replace rclcpp_lifecycle with custom interface class
|
#TODO: replace rclcpp_lifecycle with custom interface class
|
||||||
pluginlib_export_plugin_description_file(rclcpp_lifecycle gz_enviroment.xml)
|
pluginlib_export_plugin_description_file(env_interface gz_enviroment.xml)
|
||||||
|
|
||||||
if(BUILD_TESTING)
|
if(BUILD_TESTING)
|
||||||
find_package(ament_lint_auto REQUIRED)
|
find_package(ament_lint_auto REQUIRED)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<library path="gz_enviroment">
|
<library path="gz_enviroment">
|
||||||
<class
|
<class
|
||||||
type="gz_enviroment::GzEnviroment"
|
type="gz_enviroment::GzEnviroment"
|
||||||
base_class_type="rclcpp_lifecycle::LifecycleNode">
|
base_class_type="env_interface::EnvInterface">
|
||||||
<description>Gazebo enviroment for env_manager</description>
|
<description>Gazebo enviroment for env_manager</description>
|
||||||
</class>
|
</class>
|
||||||
</library>
|
</library>
|
|
@ -6,16 +6,18 @@
|
||||||
#include <geometry_msgs/msg/transform_stamped.hpp>
|
#include <geometry_msgs/msg/transform_stamped.hpp>
|
||||||
#include <gz/transport/Node.hh>
|
#include <gz/transport/Node.hh>
|
||||||
#include "gz/msgs/pose_v.pb.h"
|
#include "gz/msgs/pose_v.pb.h"
|
||||||
|
#include "env_interface/env_interface.hpp"
|
||||||
|
|
||||||
namespace gz_enviroment
|
namespace gz_enviroment
|
||||||
{
|
{
|
||||||
using CallbackReturn = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;
|
using CallbackReturn = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;
|
||||||
|
|
||||||
class GzEnviroment : public rclcpp_lifecycle::LifecycleNode
|
class GzEnviroment : public env_interface::EnvInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
GzEnviroment();
|
GzEnviroment();
|
||||||
|
CallbackReturn on_init() override;
|
||||||
CallbackReturn on_configure(const rclcpp_lifecycle::State&) override;
|
CallbackReturn on_configure(const rclcpp_lifecycle::State&) override;
|
||||||
CallbackReturn on_activate(const rclcpp_lifecycle::State&) override;
|
CallbackReturn on_activate(const rclcpp_lifecycle::State&) override;
|
||||||
CallbackReturn on_deactivate(const rclcpp_lifecycle::State&) override;
|
CallbackReturn on_deactivate(const rclcpp_lifecycle::State&) override;
|
||||||
|
@ -24,17 +26,20 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
void onGzPoseSub(const gz::msgs::Pose_V& pose_v);
|
||||||
|
|
||||||
|
bool doGzSpawn();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<tf2_ros::TransformBroadcaster> m_tf2_broadcaster;
|
std::unique_ptr<tf2_ros::TransformBroadcaster> m_tf2_broadcaster;
|
||||||
std::shared_ptr<gz::transport::Node> m_gz_node;
|
std::shared_ptr<gz::transport::Node> m_gz_node;
|
||||||
std::vector<std::string> m_follow_frames;
|
std::vector<std::string> m_follow_frames;
|
||||||
|
std::string m_topic_name;
|
||||||
void onGzPoseSub(const gz::msgs::Pose_V& pose_v);
|
std::string m_service_spawn;
|
||||||
|
|
||||||
void doGzSpawn();
|
|
||||||
|
|
||||||
std::string getGzWorldName();
|
std::string getGzWorldName();
|
||||||
|
std::string createGzModelString(const std::vector<double>& pose, const std::string& mesh_filepath, const std::string& name);
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
<depend>tf2_ros</depend>
|
<depend>tf2_ros</depend>
|
||||||
<depend>tf2_msgs</depend>
|
<depend>tf2_msgs</depend>
|
||||||
<depend>ros_gz</depend>
|
<depend>ros_gz</depend>
|
||||||
|
<depend>env_interface</depend>
|
||||||
|
|
||||||
<test_depend>ament_lint_auto</test_depend>
|
<test_depend>ament_lint_auto</test_depend>
|
||||||
<test_depend>ament_lint_common</test_depend>
|
<test_depend>ament_lint_common</test_depend>
|
||||||
|
|
|
@ -1,25 +1,46 @@
|
||||||
#include "gz_enviroment/gz_enviroment.hpp"
|
#include "gz_enviroment/gz_enviroment.hpp"
|
||||||
#include "geometry_msgs/msg/pose_stamped.hpp"
|
#include "geometry_msgs/msg/pose_stamped.hpp"
|
||||||
#include "ros_gz_bridge/convert.hpp"
|
#include "ros_gz_bridge/convert.hpp"
|
||||||
namespace gz_enviroment
|
#include "rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp"
|
||||||
|
|
||||||
|
namespace gz_enviroment {
|
||||||
|
|
||||||
|
GzEnviroment::GzEnviroment() : env_interface::EnvInterface() {}
|
||||||
|
|
||||||
|
CallbackReturn GzEnviroment::on_init()
|
||||||
{
|
{
|
||||||
|
RCLCPP_INFO(getNode()->get_logger(), "GzEnviroment in on_init()");
|
||||||
GzEnviroment::GzEnviroment()
|
|
||||||
: rclcpp_lifecycle::LifecycleNode("gz_enviroment") {}
|
|
||||||
|
|
||||||
CallbackReturn
|
|
||||||
GzEnviroment::on_configure(const rclcpp_lifecycle::State& )
|
|
||||||
{
|
|
||||||
RCLCPP_INFO(this->get_logger(), "GzEnviroment is on_configure");
|
|
||||||
|
|
||||||
|
|
||||||
return CallbackReturn::SUCCESS;
|
return CallbackReturn::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CallbackReturn GzEnviroment::on_configure(const rclcpp_lifecycle::State& ) {
|
||||||
|
// Configuration of parameters
|
||||||
|
RCLCPP_INFO(getNode()->get_logger(), "GzEnviroment is on_configure");
|
||||||
|
m_gz_node = std::make_shared<gz::transport::Node>();
|
||||||
|
m_topic_name = std::string("/world/") + getGzWorldName() +"/dynamic_pose/info";
|
||||||
|
m_service_spawn = std::string("/world/") + getGzWorldName() + "/create";
|
||||||
|
|
||||||
|
if (!doGzSpawn()) {
|
||||||
|
return CallbackReturn::ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return CallbackReturn::SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
CallbackReturn GzEnviroment::on_activate(const rclcpp_lifecycle::State&) {
|
||||||
|
// Setting up the subscribers and publishers
|
||||||
|
RCLCPP_INFO(getNode()->get_logger(), "GzEnviroment is on_activate");
|
||||||
|
|
||||||
|
m_gz_node->Subscribe(m_topic_name, &GzEnviroment::onGzPoseSub, this);
|
||||||
|
m_tf2_broadcaster = std::make_unique<tf2_ros::TransformBroadcaster>(getNode());
|
||||||
|
|
||||||
|
return CallbackReturn::SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
CallbackReturn
|
CallbackReturn
|
||||||
GzEnviroment::on_cleanup(const rclcpp_lifecycle::State&)
|
GzEnviroment::on_cleanup(const rclcpp_lifecycle::State&)
|
||||||
{
|
{
|
||||||
RCLCPP_INFO(this->get_logger(), "GzEnviroment is on_cleanup");
|
RCLCPP_INFO(getNode()->get_logger(), "GzEnviroment is on_cleanup");
|
||||||
|
|
||||||
m_tf2_broadcaster.reset();
|
m_tf2_broadcaster.reset();
|
||||||
m_gz_node.reset();
|
m_gz_node.reset();
|
||||||
|
@ -27,34 +48,21 @@ GzEnviroment::on_cleanup(const rclcpp_lifecycle::State&)
|
||||||
return CallbackReturn::SUCCESS;
|
return CallbackReturn::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
CallbackReturn
|
|
||||||
GzEnviroment::on_activate(const rclcpp_lifecycle::State&)
|
|
||||||
{
|
|
||||||
RCLCPP_INFO(this->get_logger(), "GzEnviroment is on_activate");
|
|
||||||
m_tf2_broadcaster = std::make_unique<tf2_ros::TransformBroadcaster>(this);
|
|
||||||
m_gz_node = std::make_shared<ignition::transport::Node>();
|
|
||||||
|
|
||||||
std::string m_topic_name = "/world/" + getGzWorldName() +"/dynamic_pose/info";
|
|
||||||
std::string m_service_spawn = "/world/" + getGzWorldName() + "/create";
|
|
||||||
|
|
||||||
m_gz_node->Subscribe(m_topic_name, &GzEnviroment::onGzPoseSub, this);
|
|
||||||
|
|
||||||
return CallbackReturn::SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
CallbackReturn
|
CallbackReturn
|
||||||
GzEnviroment::on_deactivate(const rclcpp_lifecycle::State&)
|
GzEnviroment::on_deactivate(const rclcpp_lifecycle::State&)
|
||||||
{
|
{
|
||||||
RCLCPP_INFO(this->get_logger(), "GzEnviroment is on_deactivate");
|
RCLCPP_INFO(getNode()->get_logger(), "GzEnviroment is on_deactivate");
|
||||||
|
|
||||||
|
|
||||||
return CallbackReturn::SUCCESS;
|
return CallbackReturn::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Check do this via EntityComponentManager
|
||||||
void
|
void
|
||||||
GzEnviroment::onGzPoseSub(const gz::msgs::Pose_V& pose_v)
|
GzEnviroment::onGzPoseSub(const gz::msgs::Pose_V& pose_v)
|
||||||
{
|
{
|
||||||
m_follow_frames = {"box1", "box2", "box3", "box4"};
|
// TODO: Read from config
|
||||||
|
m_follow_frames = {"box1", "box2", "box3", "box4", "box5", "box6", "monkey"};
|
||||||
for (const auto &it: pose_v.pose())
|
for (const auto &it: pose_v.pose())
|
||||||
{
|
{
|
||||||
if (std::find(m_follow_frames.begin(), m_follow_frames.end(), it.name()) == m_follow_frames.end())
|
if (std::find(m_follow_frames.begin(), m_follow_frames.end(), it.name()) == m_follow_frames.end())
|
||||||
|
@ -65,7 +73,7 @@ GzEnviroment::onGzPoseSub(const gz::msgs::Pose_V& pose_v)
|
||||||
|
|
||||||
geometry_msgs::msg::TransformStamped t;
|
geometry_msgs::msg::TransformStamped t;
|
||||||
|
|
||||||
t.header.stamp = this->get_clock()->now();
|
t.header.stamp = getNode()->get_clock()->now();
|
||||||
t.header.frame_id = "world";
|
t.header.frame_id = "world";
|
||||||
t.child_frame_id = it.name();
|
t.child_frame_id = it.name();
|
||||||
|
|
||||||
|
@ -92,35 +100,75 @@ GzEnviroment::getGzWorldName()
|
||||||
gz::msgs::StringMsg_V worlds_msg;
|
gz::msgs::StringMsg_V worlds_msg;
|
||||||
|
|
||||||
while (rclcpp::ok() && !executed) {
|
while (rclcpp::ok() && !executed) {
|
||||||
RCLCPP_INFO(this->get_logger(), "Requesting list of world names.");
|
RCLCPP_INFO(getNode()->get_logger(), "Requesting list of world names.");
|
||||||
executed = m_gz_node->Request(service, timeout, worlds_msg, result);
|
executed = m_gz_node->Request(service, timeout, worlds_msg, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!executed) {
|
if (!executed) {
|
||||||
RCLCPP_INFO(this->get_logger(), "Timed out when getting world names.");
|
RCLCPP_INFO(getNode()->get_logger(), "Timed out when getting world names.");
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result || worlds_msg.data().empty()) {
|
if (!result || worlds_msg.data().empty()) {
|
||||||
RCLCPP_INFO(this->get_logger(), "Failed to get world names.");
|
RCLCPP_INFO(getNode()->get_logger(), "Failed to get world names.");
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
RCLCPP_INFO(this->get_logger(), "%s", worlds_msg.data(0).c_str());
|
RCLCPP_INFO(getNode()->get_logger(), "%s", worlds_msg.data(0).c_str());
|
||||||
return worlds_msg.data(0);
|
return worlds_msg.data(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
bool
|
||||||
GzEnviroment::doGzSpawn()
|
GzEnviroment::doGzSpawn()
|
||||||
{
|
{
|
||||||
gz::msgs::EntityFactory entity;
|
gz::msgs::EntityFactory req;
|
||||||
gz::msgs::Model model;
|
gz::msgs::Boolean rep;
|
||||||
gz::msgs::Link link;
|
bool result;
|
||||||
|
unsigned int timeout = 5000;
|
||||||
|
// TODO: From Config
|
||||||
|
std::vector<double> pps{1.0, 0.0, 1.0, 0.0, 0.0};
|
||||||
|
std::string mesh_file = "monkey.stl";
|
||||||
|
std::string mesh_name = "monkey";
|
||||||
|
// ENDTODO
|
||||||
|
std::string sdf_string = createGzModelString(pps, mesh_file, mesh_name);
|
||||||
|
req.set_sdf(sdf_string);
|
||||||
|
bool executed = m_gz_node->Request(m_service_spawn, req, timeout, rep, result);
|
||||||
|
|
||||||
|
return executed;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string
|
||||||
|
GzEnviroment::createGzModelString(
|
||||||
|
const std::vector<double>& pose,
|
||||||
|
const std::string& mesh_filepath,
|
||||||
|
const std::string& name
|
||||||
|
)
|
||||||
|
{
|
||||||
|
std::string model_template =
|
||||||
|
std::string("<sdf version='1.7'>") +
|
||||||
|
"<model name='"+ name +"'>" +
|
||||||
|
"<link name='link_"+ name +"'>" +
|
||||||
|
"<pose>"
|
||||||
|
+std::to_string(pose[0])+" "
|
||||||
|
+std::to_string(pose[1])+" "
|
||||||
|
+std::to_string(pose[2])+" "
|
||||||
|
+std::to_string(pose[3])+" "
|
||||||
|
+std::to_string(pose[4])+" "
|
||||||
|
+std::to_string(pose[5])+"</pose>" +
|
||||||
|
"<visual name='visual_"+name+"'>" +
|
||||||
|
"<geometry><mesh><uri>file://"+mesh_filepath+"</uri></mesh></geometry>" +
|
||||||
|
"</visual>" +
|
||||||
|
"<collision name='collision_"+name+"'>" +
|
||||||
|
"<geometry><mesh><uri>file://"+mesh_filepath+"</uri></mesh></geometry>" +
|
||||||
|
"</collision>" +
|
||||||
|
"</link>" +
|
||||||
|
"</model>" +
|
||||||
|
"</sdf>";
|
||||||
|
return model_template;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "pluginlib/class_list_macros.hpp"
|
#include "pluginlib/class_list_macros.hpp"
|
||||||
PLUGINLIB_EXPORT_CLASS(
|
PLUGINLIB_EXPORT_CLASS(
|
||||||
gz_enviroment::GzEnviroment, rclcpp_lifecycle::LifecycleNode
|
gz_enviroment::GzEnviroment, env_interface::EnvInterface
|
||||||
);
|
);
|
|
@ -26,7 +26,7 @@ def generate_launch_description():
|
||||||
DeclareLaunchArgument("env_manager", default_value="false", description="Launch env_manager?")
|
DeclareLaunchArgument("env_manager", default_value="false", description="Launch env_manager?")
|
||||||
)
|
)
|
||||||
declared_arguments.append(
|
declared_arguments.append(
|
||||||
DeclareLaunchArgument("gazebo_gui", default_value="false", description="Launch env_manager?")
|
DeclareLaunchArgument("gazebo_gui", default_value="true", description="Launch env_manager?")
|
||||||
)
|
)
|
||||||
|
|
||||||
sim_gazebo = LaunchConfiguration("sim_gazebo")
|
sim_gazebo = LaunchConfiguration("sim_gazebo")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue