From 4bb61e912e54d45b8de4795219b41a14f294fd7d Mon Sep 17 00:00:00 2001 From: lross03 <136214176+lross03@users.noreply.github.com> Date: Sat, 28 Feb 2026 12:11:20 -0800 Subject: [PATCH] removed example node (cached_fib) --- src/integration_tests/testplans/example.yaml | 10 --- src/network_systems/README.md | 4 +- src/network_systems/config/all_disable.yaml | 6 +- .../config/default_dev_en.yaml | 4 -- .../config/default_prod_en.yaml | 6 +- .../config/example/example_en.yaml | 4 -- src/network_systems/launch/main_launch.py | 34 --------- src/network_systems/projects/CMakeLists.txt | 1 - .../projects/example/CMakeLists.txt | 31 -------- .../projects/example/README.md | 13 ---- .../projects/example/inc/cached_fib.h | 17 ----- .../projects/example/src/cached_fib.cpp | 24 ------- .../example/src/cached_fib_ros_intf.cpp | 71 ------------------- .../projects/example/test/test_cached_fib.cpp | 29 -------- src/network_systems/ros_info.yaml | 1 - 15 files changed, 4 insertions(+), 251 deletions(-) delete mode 100644 src/network_systems/config/example/example_en.yaml delete mode 100755 src/network_systems/projects/example/CMakeLists.txt delete mode 100755 src/network_systems/projects/example/README.md delete mode 100755 src/network_systems/projects/example/inc/cached_fib.h delete mode 100755 src/network_systems/projects/example/src/cached_fib.cpp delete mode 100644 src/network_systems/projects/example/src/cached_fib_ros_intf.cpp delete mode 100755 src/network_systems/projects/example/test/test_cached_fib.cpp diff --git a/src/integration_tests/testplans/example.yaml b/src/integration_tests/testplans/example.yaml index d5200e1c0..0df9165a0 100644 --- a/src/integration_tests/testplans/example.yaml +++ b/src/integration_tests/testplans/example.yaml @@ -8,11 +8,6 @@ required_packages: - example/example_en.yaml - mock_ais/mock_ais_en_default.yaml inputs: - - type: ROS - name: cached_fib_in - data: - dtype: uint64 - val: 6 - type: ROS name: aisship data: @@ -93,11 +88,6 @@ inputs: val: -3 expected_outputs: - - type: ROS - name: cached_fib_out - data: - dtype: uint64 - val: 5 - type: ROS name: aisships data: diff --git a/src/network_systems/README.md b/src/network_systems/README.md index 4445abcd0..f1032d2b9 100755 --- a/src/network_systems/README.md +++ b/src/network_systems/README.md @@ -54,7 +54,7 @@ For example: ## Testing Unit tests specific to Network Systems is done using [GoogleTest](https://github.com/google/googletest). Unit tests -are defined per module. For example, under [projects/example/test/](projects/example/test/test_cached_fib.cpp). +are defined per module. ### Run All Tests @@ -68,7 +68,7 @@ unnecessary. ### Run and Debug Specific Tests This is the preferred way to run and debug tests. When you open a test source file like -[the example's](projects/example/test/test_cached_fib.cpp), there will be green arrows next to each `TEST_F` macro. +[the example's](projects/can_transceiver/test/test_can_transceiver.cpp), there will be green arrows next to each `TEST_F` macro. Clicking a double green arrow runs a test suite, while clicking single green arrow runs one unit test. Right clicking either arrow will open a prompt with a debug test option. When running a test via the debug option, we can set breakpoints and step through our code line by line to resolve issues. diff --git a/src/network_systems/config/all_disable.yaml b/src/network_systems/config/all_disable.yaml index 4c65913e8..929a7ca1d 100644 --- a/src/network_systems/config/all_disable.yaml +++ b/src/network_systems/config/all_disable.yaml @@ -3,11 +3,7 @@ can_transceiver_node: ros__parameters: enabled: false - -cached_fib_subscriber: - ros__parameters: - enabled: false - + local_transceiver_node: ros__parameters: enabled: false diff --git a/src/network_systems/config/default_dev_en.yaml b/src/network_systems/config/default_dev_en.yaml index 675c4ec30..998e9a0cf 100644 --- a/src/network_systems/config/default_dev_en.yaml +++ b/src/network_systems/config/default_dev_en.yaml @@ -3,10 +3,6 @@ can_transceiver_node: ros__parameters: enabled: true -cached_fib_subscriber: - ros__parameters: - enabled: false - local_transceiver_node: ros__parameters: enabled: true diff --git a/src/network_systems/config/default_prod_en.yaml b/src/network_systems/config/default_prod_en.yaml index d698d0e7d..6618c8964 100644 --- a/src/network_systems/config/default_prod_en.yaml +++ b/src/network_systems/config/default_prod_en.yaml @@ -2,11 +2,7 @@ can_transceiver_node: ros__parameters: enabled: true - -cached_fib_node: - ros__parameters: - enabled: false - + local_transceiver_node: ros__parameters: enabled: true diff --git a/src/network_systems/config/example/example_en.yaml b/src/network_systems/config/example/example_en.yaml deleted file mode 100644 index 91f0e758e..000000000 --- a/src/network_systems/config/example/example_en.yaml +++ /dev/null @@ -1,4 +0,0 @@ -# Configuration that enables the cached_fib example module -cached_fib_node: - ros__parameters: - enabled: true diff --git a/src/network_systems/launch/main_launch.py b/src/network_systems/launch/main_launch.py index 742ca4696..e1257a5ff 100644 --- a/src/network_systems/launch/main_launch.py +++ b/src/network_systems/launch/main_launch.py @@ -17,7 +17,6 @@ SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) sys.path.append(SCRIPT_DIR) from ros_info import ( # noqa: E402 - CACHED_FIB_NODE, CAN_TRANSCEIVER_NODE, MOCK_AIS_NODE, REMOTE_TRANSCEIVER_NODE, @@ -87,7 +86,6 @@ def setup_launch(context: LaunchContext) -> List[Node]: name="ROS_LOG_DIR", value="/workspaces/sailbot_workspace/log" ).visit(context) launch_description_entities = list() - launch_description_entities.append(get_cached_fib_description(context)) launch_description_entities.append(get_mock_ais_description(context)) launch_description_entities.append(get_can_transceiver_description(context)) launch_description_entities.append(get_remote_transceiver_description(context)) @@ -95,38 +93,6 @@ def setup_launch(context: LaunchContext) -> List[Node]: return launch_description_entities -def get_cached_fib_description(context: LaunchContext) -> Node: - """Gets the launch description for the cached_fib_node. - - Args: - context (LaunchContext): The current launch context. - - Returns: - Node: The node object that launches the cached_fib_node. - """ - node_name = CACHED_FIB_NODE - ros_parameters = [ - global_launch_config, - {"mode": LaunchConfiguration("mode")}, - *LaunchConfiguration("config").perform(context).split(","), - ] - ros_arguments: List[SomeSubstitutionsType] = [ - "--log-level", - [f"{node_name}:=", LaunchConfiguration("log_level")], - ] - - node = Node( - package=PACKAGE_NAME, - namespace=NAMESPACE, - executable="example", - name=node_name, - parameters=ros_parameters, - ros_arguments=ros_arguments, - ) - - return node - - def get_mock_ais_description(context: LaunchContext) -> Node: """Gets the launch description for the mock_ais_node. diff --git a/src/network_systems/projects/CMakeLists.txt b/src/network_systems/projects/CMakeLists.txt index 2f187bfef..1fbf41b28 100755 --- a/src/network_systems/projects/CMakeLists.txt +++ b/src/network_systems/projects/CMakeLists.txt @@ -1,6 +1,5 @@ add_subdirectory(mock_ais) add_subdirectory(can_transceiver) -add_subdirectory(example) add_subdirectory(local_transceiver) add_subdirectory(remote_transceiver) diff --git a/src/network_systems/projects/example/CMakeLists.txt b/src/network_systems/projects/example/CMakeLists.txt deleted file mode 100755 index 910bc8993..000000000 --- a/src/network_systems/projects/example/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -set(module example) - -# define external dependencies with link_libs and inc_dirs variables -set(link_libs -) - -set(inc_dirs -) - -set(compile_defs -) - -# Create module library -set(srcs - ${CMAKE_CURRENT_LIST_DIR}/src/cached_fib.cpp -) -make_lib(${module} "${srcs}" "${link_libs}" "${inc_dirs}" "${compile_defs}") - -# Create module ROS executable -set(bin_srcs - ${srcs} - ${CMAKE_CURRENT_LIST_DIR}/src/cached_fib_ros_intf.cpp -) -make_exe(${module} "${bin_srcs}" "${link_libs}" "${inc_dirs}" "${compile_defs}") - -# Create unit test -set(test_srcs - ${srcs} - ${CMAKE_CURRENT_LIST_DIR}/test/test_cached_fib.cpp -) -make_unit_test(${module} "${test_srcs}" "${link_libs}" "${inc_dirs}" "${compile_defs}") diff --git a/src/network_systems/projects/example/README.md b/src/network_systems/projects/example/README.md deleted file mode 100755 index 5926c7332..000000000 --- a/src/network_systems/projects/example/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Example - Cached Fibonacci - -This is a simple example program to showcase and evaluate the workspace structure for Network Systems. - -Run it with `ros2 run network_systems example --ros-args -p enabled:=true`. - -Alternatively, using launch files run `ros2 launch network_systems main_launch.py config:=example/example_en.yaml`. - -Publish to the topic using: `ros2 topic pub cached_fib_in std_msgs/msg/UInt64 "{data: }" --once`. Run it -without the `--once` flag to repeatedly publish. - -The output will be shown in the terminal where the example is running. You can also see the output by running -`ros2 topic echo cached_fib_out` before sending the publish command. diff --git a/src/network_systems/projects/example/inc/cached_fib.h b/src/network_systems/projects/example/inc/cached_fib.h deleted file mode 100755 index 25aab1bfa..000000000 --- a/src/network_systems/projects/example/inc/cached_fib.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include -#include - -constexpr auto CACHED_FIB_TOPIC_IN = "cached_fib_in"; -constexpr auto CACHED_FIB_TOPIC_OUT = "cached_fib_out"; - -class CachedFib -{ -private: - std::vector cache_; - -public: - explicit CachedFib(std::size_t); - int getFib(std::size_t); -}; diff --git a/src/network_systems/projects/example/src/cached_fib.cpp b/src/network_systems/projects/example/src/cached_fib.cpp deleted file mode 100755 index c00d7eb47..000000000 --- a/src/network_systems/projects/example/src/cached_fib.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "cached_fib.h" - -#include -#include - -CachedFib::CachedFib(const std::size_t n) -{ - cache_.push_back(0); - cache_.push_back(1); - for (std::size_t i = 2; i < n; i++) { - cache_.push_back(cache_[i - 1] + cache_[i - 2]); - } -} - -int CachedFib::getFib(const std::size_t n) -{ - if (this->cache_.size() < n) { - for (std::size_t i = cache_.size(); i < n; i++) { - cache_.push_back(cache_[i - 1] + cache_[i - 2]); - } - } - std::cout << cache_[n - 1] << std::endl; - return cache_[n - 1]; -} diff --git a/src/network_systems/projects/example/src/cached_fib_ros_intf.cpp b/src/network_systems/projects/example/src/cached_fib_ros_intf.cpp deleted file mode 100644 index c949c033f..000000000 --- a/src/network_systems/projects/example/src/cached_fib_ros_intf.cpp +++ /dev/null @@ -1,71 +0,0 @@ -// Include this module -#include "cached_fib.h" -#include "cmn_hdrs/ros_info.h" -#include "net_node.h" -// Include ROS headers -#include -#include - -namespace -{ -constexpr int ROS_Q_SIZE = 10; -constexpr int INIT_FIB_SIZE = 5; -} // namespace - -class CachedFibNode : public NetNode -{ -public: - explicit CachedFibNode(const std::size_t initSize) : NetNode(ros_nodes::CACHED_FIB), c_fib_(initSize) - { - this->declare_parameter("enabled", false); - bool enabled = this->get_parameter("enabled").as_bool(); - if (enabled) { - RCLCPP_INFO(this->get_logger(), "Running example cached fib node"); - - // This registers a callback function that gets called whenever CACHED_FIB_TOPIC_IN gets updated - sub_ = this->create_subscription( - CACHED_FIB_TOPIC_IN, ROS_Q_SIZE, std::bind(&CachedFibNode::subCb, this, std::placeholders::_1)); - - pub_ = this->create_publisher(CACHED_FIB_TOPIC_OUT, ROS_Q_SIZE); - } - } - -private: - CachedFib c_fib_; - rclcpp::Subscription::SharedPtr sub_; - rclcpp::Publisher::SharedPtr pub_; - - /** - * @brief Callback function that runs whenever the subscribed topic is updated - * - * @param in_msg msg that was sent to the topic - */ - void subCb(const std_msgs::msg::UInt64::SharedPtr in_msg) - { - int fibNum = this->c_fib_.getFib(in_msg->data); - RCLCPP_INFO(this->get_logger(), "Fib num for '%lu' is '%d'", in_msg->data, fibNum); - std_msgs::msg::UInt64 out_msg{}; - out_msg.data = fibNum; - pub_->publish(out_msg); - } -}; - -int main(int argc, char * argv[]) -{ - bool err = false; - rclcpp::init(argc, argv); - try { - std::shared_ptr node = std::make_shared(INIT_FIB_SIZE); - try { - rclcpp::spin(node); - } catch (std::exception & e) { - RCLCPP_ERROR(node->get_logger(), "%s", e.what()); - throw e; - } - } catch (std::exception & e) { - std::cerr << e.what() << std::endl; - err = true; - } - rclcpp::shutdown(); - return err ? -1 : 0; -} diff --git a/src/network_systems/projects/example/test/test_cached_fib.cpp b/src/network_systems/projects/example/test/test_cached_fib.cpp deleted file mode 100755 index 60b8950f2..000000000 --- a/src/network_systems/projects/example/test/test_cached_fib.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include - -#include "cached_fib.h" - -static constexpr int DEFAULT_SIZE = 5; -static CachedFib g_test_fib = CachedFib(DEFAULT_SIZE); - -class TestFib : public ::testing::Test -{ -protected: - TestFib() - { - // Every time a test is started, testFib is reinitialized with a constructor parameter of 5 - g_test_fib = CachedFib(DEFAULT_SIZE); - } - - ~TestFib() override - { - // Clean up after a test - } -}; - -TEST_F(TestFib, TestBasic) { ASSERT_EQ(g_test_fib.getFib(5), 3) << "5th fibonacci number must be 3!"; } - -TEST_F(TestFib, TestBasic2) -{ - ASSERT_EQ(g_test_fib.getFib(6), 5); - ASSERT_EQ(g_test_fib.getFib(7), 8); -} diff --git a/src/network_systems/ros_info.yaml b/src/network_systems/ros_info.yaml index b4415bc6d..dadc0b009 100644 --- a/src/network_systems/ros_info.yaml +++ b/src/network_systems/ros_info.yaml @@ -20,7 +20,6 @@ ros_topics: ros_nodes: CAN_TRANSCEIVER: can_transceiver_node - CACHED_FIB: cached_fib_node LOCAL_TRANSCEIVER: local_transceiver_node MOCK_AIS: mock_ais_node REMOTE_TRANSCEIVER: remote_transceiver_node