Skip to content

Commit 3efb4e2

Browse files
authored
Merge pull request #46 from CoreSenseEU/cs_core_base_1
Cs core base 1
2 parents c4fae06 + d9b4f3e commit 3efb4e2

26 files changed

Lines changed: 665 additions & 34 deletions

cs4home_core/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
cmake_minimum_required(VERSION 3.8)
22
project(cs4home_core)
33

4+
set(CMAKE_BUILD_TYPE debug)
5+
46
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
57
add_compile_options(-Wall -Wextra -Wpedantic)
68
endif()
@@ -20,6 +22,7 @@ set(dependencies
2022
include_directories(include)
2123

2224
add_library(${PROJECT_NAME} SHARED
25+
src/cs4home_core/Master.cpp
2326
src/cs4home_core/CognitiveModule.cpp
2427
src/cs4home_core/Afferent.cpp
2528
src/cs4home_core/Efferent.cpp

cs4home_core/include/cs4home_core/Afferent.hpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
1516
#ifndef CS4HOME_CORE__AFFERENT_HPP_
1617
#define CS4HOME_CORE__AFFERENT_HPP_
1718

18-
#include "rclcpp/macros.hpp"
19+
#include <memory>
20+
#include <vector>
21+
#include <string>
22+
1923
#include "rclcpp_lifecycle/lifecycle_node.hpp"
24+
#include "rclcpp/rclcpp.hpp"
25+
#include "rclcpp/macros.hpp"
2026

2127
namespace cs4home_core
2228
{
@@ -32,6 +38,11 @@ class Afferent
3238

3339
protected:
3440
rclcpp_lifecycle::LifecycleNode::SharedPtr parent_;
41+
42+
std::vector<std::shared_ptr<rclcpp::GenericSubscription>> subs_;
43+
44+
private:
45+
bool create_subscriber(const std::string & topic, const std::string & type);
3546
};
3647

3748
} // namespace cs4home_core

cs4home_core/include/cs4home_core/CognitiveModule.hpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,21 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
1516
#ifndef CS4HOME_CORE__COGNITIVEMODULE_HPP_
1617
#define CS4HOME_CORE__COGNITIVEMODULE_HPP_
1718

19+
#include <dlfcn.h>
20+
21+
#include <tuple>
22+
#include <string>
23+
1824
#include "cs4home_core/Afferent.hpp"
1925
#include "cs4home_core/Core.hpp"
2026
#include "cs4home_core/Coupling.hpp"
2127
#include "cs4home_core/Efferent.hpp"
2228
#include "cs4home_core/Meta.hpp"
29+
2330
#include "rclcpp/macros.hpp"
2431
#include "rclcpp/rclcpp.hpp"
2532
#include "rclcpp_lifecycle/lifecycle_node.hpp"
@@ -31,7 +38,8 @@ class CognitiveModule : public rclcpp_lifecycle::LifecycleNode
3138
{
3239
public:
3340
RCLCPP_SMART_PTR_DEFINITIONS(CognitiveModule)
34-
using CallbackReturnT = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;
41+
using CallbackReturnT =
42+
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;
3543

3644
explicit CognitiveModule(const rclcpp::NodeOptions & options = rclcpp::NodeOptions());
3745

@@ -48,6 +56,16 @@ class CognitiveModule : public rclcpp_lifecycle::LifecycleNode
4856
Core::SharedPtr core_;
4957
Meta::SharedPtr meta_;
5058
Coupling::SharedPtr coupling_;
59+
60+
std::string core_name_;
61+
std::string afferent_name_;
62+
std::string efferent_name_;
63+
std::string meta_name_;
64+
std::string coupling_name_;
65+
66+
template<class T>
67+
std::tuple<typename T::SharedPtr, std::string> load_component(
68+
const std::string & name, rclcpp_lifecycle::LifecycleNode::SharedPtr parent);
5169
};
5270

5371
} // namespace cs4home_core

cs4home_core/include/cs4home_core/Core.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
1516
#ifndef CS4HOME_CORE__CORE_HPP_
1617
#define CS4HOME_CORE__CORE_HPP_
1718

18-
#include "rclcpp/macros.hpp"
19+
#include <memory>
20+
1921
#include "rclcpp_lifecycle/lifecycle_node.hpp"
22+
#include "rclcpp/macros.hpp"
2023

2124
namespace cs4home_core
2225
{

cs4home_core/include/cs4home_core/Coupling.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
1516
#ifndef CS4HOME_CORE__COUPLING_HPP_
1617
#define CS4HOME_CORE__COUPLING_HPP_
1718

18-
#include "rclcpp/macros.hpp"
1919
#include "rclcpp_lifecycle/lifecycle_node.hpp"
20+
#include "rclcpp/macros.hpp"
2021

2122
namespace cs4home_core
2223
{

cs4home_core/include/cs4home_core/Efferent.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
1516
#ifndef CS4HOME_CORE__EFFERENT_HPP_
1617
#define CS4HOME_CORE__EFFERENT_HPP_
1718

18-
#include "rclcpp/macros.hpp"
1919
#include "rclcpp_lifecycle/lifecycle_node.hpp"
20+
#include "rclcpp/macros.hpp"
2021

2122
namespace cs4home_core
2223
{
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright 2024 Intelligent Robotics Lab
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
16+
#ifndef CS4HOME_CORE__MASTER_HPP_
17+
#define CS4HOME_CORE__MASTER_HPP_
18+
19+
#include <map>
20+
#include <string>
21+
22+
#include "cs4home_core/CognitiveModule.hpp"
23+
24+
#include "rclcpp_lifecycle/lifecycle_node.hpp"
25+
#include "rclcpp/rclcpp.hpp"
26+
#include "rclcpp/macros.hpp"
27+
28+
namespace cs4home_core
29+
{
30+
31+
class Master : public rclcpp_lifecycle::LifecycleNode
32+
{
33+
public:
34+
RCLCPP_SMART_PTR_DEFINITIONS(Master)
35+
using CallbackReturnT =
36+
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;
37+
38+
explicit Master(const rclcpp::NodeOptions & options = rclcpp::NodeOptions());
39+
40+
CallbackReturnT on_configure(const rclcpp_lifecycle::State & state);
41+
CallbackReturnT on_activate(const rclcpp_lifecycle::State & state);
42+
CallbackReturnT on_deactivate(const rclcpp_lifecycle::State & state);
43+
CallbackReturnT on_cleanup(const rclcpp_lifecycle::State & state);
44+
CallbackReturnT on_shutdown(const rclcpp_lifecycle::State & state);
45+
CallbackReturnT on_error(const rclcpp_lifecycle::State & state);
46+
47+
protected:
48+
std::map<std::string, cs4home_core::CognitiveModule::SharedPtr> cog_modules_;
49+
};
50+
51+
} // namespace cs4home_core
52+
53+
#endif // CS4HOME_CORE__MASTER_HPP_
54+
55+
// #include "rclcpp_components/register_node_macro.hpp"
56+
//
57+
// // Register the component with class_loader.
58+
// // This acts as a sort of entry point, allowing the component to be discoverable when its library
59+
// // is being loaded into a running process.
60+
// RCLCPP_COMPONENTS_REGISTER_NODE(cs4home_core::Master)

cs4home_core/include/cs4home_core/Meta.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
1516
#ifndef CS4HOME_CORE__META_HPP_
1617
#define CS4HOME_CORE__META_HPP_
1718

18-
#include "rclcpp/macros.hpp"
1919
#include "rclcpp_lifecycle/lifecycle_node.hpp"
20+
#include "rclcpp/macros.hpp"
2021

2122
namespace cs4home_core
2223
{
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2024 Intelligent Robotics Lab
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
16+
#ifndef CS4HOME_CORE__MACROS_HPP_
17+
#define CS4HOME_CORE__MACROS_HPP_
18+
19+
#include "rclcpp_lifecycle/lifecycle_node.hpp"
20+
#include "rclcpp/rclcpp.hpp"
21+
#include "rclcpp/macros.hpp"
22+
23+
namespace cs4home_core
24+
{
25+
26+
#define CS_REGISTER_COMPONENT(class_name) \
27+
extern "C" class_name::SharedPtr create_instance( \
28+
rclcpp_lifecycle::LifecycleNode::SharedPtr parent) \
29+
{ \
30+
return class_name::make_shared(parent); \
31+
}
32+
33+
} // namespace cs4home_core
34+
35+
#endif // CS4HOME_CORE__MACROS_HPP_

cs4home_core/package.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
<test_depend>ament_lint_auto</test_depend>
1616
<test_depend>ament_lint_common</test_depend>
17+
<test_depend>sensor_msgs</test_depend>
18+
<test_depend>vision_msgs</test_depend>
1719

1820
<export>
1921
<build_type>ament_cmake</build_type>

0 commit comments

Comments
 (0)