diff --git a/.fish/activate.fish b/.fish/activate.fish new file mode 100755 index 0000000..61bd88a --- /dev/null +++ b/.fish/activate.fish @@ -0,0 +1,79 @@ +# Self-contained environment: ros2-lectures +# Exported on: Thu Dec 4 09:45:42 AM CET 2025 +# Original environment from: /home/wessel/.config/fish/environments/configs/ros2-lectures + +# ROS2 development environment (requires distrobox) +# Environment: ros2-lectures + +# First check if running inside distrobox +if not test -f /run/.containerenv; and test -z "$CONTAINER_ID" + echo (set_color red)"This ROS2 environment should only be run inside a distrobox container"(set_color normal) + return 1 +end + +# Check if a previous initialization has occurred +if test -n "$__ENV_INITIALIZED" + echo (set_color yellow)"Environment already initialized"(set_color normal) + return 0 +end + +# Mark as initialized (only after distrobox check passes) +set -gx __ENV_INITIALIZED "1" +set -gx CURRENT_ENV "ros2-lectures" +# Source ROS2 setup files using bass +if type -q bass + bass source /opt/ros/jazzy/setup.bash + if test -f ./install/setup.bash + bass source ./install/setup.bash + end +else + echo (set_color red)"Error: bass is required for ROS2 environment. Install with: fisher install edc/bass"(set_color normal) + return 1 +end + +# Set environment variable for the prompt prefix +set -gx ROS2_ACTIVE 1 + +# Save the original prompt function if it exists +# Only save if we don't already have a backup or if current prompt is not from an environment +if not functions -q __env_orig_prompt + if functions -q fish_prompt + functions -c fish_prompt __env_orig_prompt + else + function __env_orig_prompt + echo -n (whoami)'@'(prompt_hostname)' '(set_color $fish_color_cwd)(prompt_pwd)(set_color normal)'> ' + end + end +else + # If we already have a backup, we're switching environments + # No need to create a new backup +end + +# Define new prompt with ROS2 prefix +function fish_prompt + echo -n (set_color magenta)'(ros2-lectures)'(set_color normal)' ' + __env_orig_prompt +end + +# ROS2 aliases and functions +alias cb="colcon build" +alias cbe="colcon build && env deactivate && cd ." +alias cbs="colcon build --symlink-install" +alias cbt="colcon build --packages-select" +alias ct="colcon test" +alias ctr="colcon test-result" + +# For communication between nodes on other devices +export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp +export ROS_DOMAIN_ID=5 + +echo (set_color green)"Activated ROS2 environment: ros2-lectures"(set_color normal) + +# Custom deactivation function +function __env_custom_deactivate + # Remove ROS2-specific variables and aliases + set -e ROS2_ACTIVE + functions -e cb cbs cbt ct ctr 2>/dev/null + + echo (set_color blue)"ROS2 environment cleanup completed"(set_color normal) +end diff --git a/.fish/readme.norg b/.fish/readme.norg new file mode 100644 index 0000000..cc3d876 --- /dev/null +++ b/.fish/readme.norg @@ -0,0 +1,60 @@ +* Exported Fish Environment: ros2-lectures +This directory contains a self-contained fish environment. + +** Files Structure + @code + .fish/ + |-- activate.fish + |-- readme.norg + |-- bin/ + @end + +** Usage + +*** Automatic Activation (Recommended) + The environment will automatically activate when you `cd` into this directory + if your Fish shell is configured with the auto-activation script. + + @code fish + function check_and_source_activate + if test -f (pwd)/.fish/activate.fish + source (pwd)/.fish/activate.fish + elif test -f (pwd)/activate.fish + source (pwd)/activate.fish + end + end + + function cd + builtin cd $argv && check_and_source_activate + end + @end + +*** Manual Activation + To manually activate the environment, run from the project root: + @code bash + source ./.fish/activate.fish + @end + +*** Deactivation + To deactivate the environment, run: + @code bash + env deactivate + @end + + Or simply `cd` to a different directory if using auto-activation. + +** What This Environment Provides + - Prompt showing the environment name + - Environment-specific aliases and functions + - Custom environment variables + - Automatic cleanup when deactivated + +** Requirements + - Fish shell + - `bass` plugin (`fisher install edc/bass`) for compatibility with bash scripts + +** Sharing + This environment is completely self-contained. You can: + - Copy this directory to another machine + - Share it with others + - Version control it with your project (add .fish/ to your repo) \ No newline at end of file diff --git a/src/soup_relay_pkg/CMakeLists.txt b/src/soup_relay_pkg/CMakeLists.txt new file mode 100644 index 0000000..2878272 --- /dev/null +++ b/src/soup_relay_pkg/CMakeLists.txt @@ -0,0 +1,39 @@ +cmake_minimum_required(VERSION 3.8) +project(soup_relay_pkg) + +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wall -Wextra -Wpedantic) +endif() + +# find dependencies +find_package(ament_cmake REQUIRED) +find_package(rclcpp REQUIRED) +find_package(std_msgs REQUIRED) + +add_executable(soup_relay src/soup_relay.cpp) +target_include_directories(soup_relay PUBLIC + $ + $) +target_compile_features(soup_relay PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17 +ament_target_dependencies( + soup_relay + "rclcpp" + "std_msgs" +) + +install(TARGETS soup_relay + DESTINATION lib/${PROJECT_NAME}) + +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() + +ament_package() diff --git a/src/soup_relay_pkg/package.xml b/src/soup_relay_pkg/package.xml new file mode 100644 index 0000000..57258eb --- /dev/null +++ b/src/soup_relay_pkg/package.xml @@ -0,0 +1,21 @@ + + + + soup_relay_pkg + 0.0.0 + TODO: Package description + wessel + TODO: License declaration + + ament_cmake + + rclcpp + std_msgs + + ament_lint_auto + ament_lint_common + + + ament_cmake + + diff --git a/src/soup_relay_pkg/src/soup_relay.cpp b/src/soup_relay_pkg/src/soup_relay.cpp new file mode 100644 index 0000000..1d8b249 --- /dev/null +++ b/src/soup_relay_pkg/src/soup_relay.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include + +class SoupRelayNode : public rclcpp::Node { +public: + SoupRelayNode() : Node("soup_relay_node") { + auto topic_publisher = this->declare_parameter("topic_publisher", "vin7"); + auto topic_subscriber = this->declare_parameter("topic_subscriber", "vin6"); + + publisher_ = this->create_publisher(topic_publisher, 10); + subscriber_ = this->create_subscription( + topic_subscriber, 10, + std::bind(&SoupRelayNode::message_callback, this, std::placeholders::_1) + ); + + RCLCPP_INFO(this->get_logger(), + "listener='%s', publisher='%s'", topic_subscriber.c_str(), topic_publisher.c_str() + ); + } + +private: + rclcpp::Subscription::SharedPtr subscriber_; + rclcpp::Publisher::SharedPtr publisher_; + + void message_callback(const std_msgs::msg::String::SharedPtr msg) { + auto new_msg = std_msgs::msg::String(); + new_msg.data = trim(msg->data, " ") + " makkelijk"; + + RCLCPP_INFO(this->get_logger(), + "incoming='%s', outgoing='%s'", msg->data.c_str(), new_msg.data.c_str() + ); + + publisher_->publish(new_msg); + } + + std::string trim(const std::string& str, const std::string& whitespace = " \t") { + const auto strBegin = str.find_first_not_of(whitespace); + if (strBegin == std::string::npos) return ""; + + const auto strEnd = str.find_last_not_of(whitespace); + const auto strRange = strEnd - strBegin + 1; + + return str.substr(strBegin, strRange); + } +}; + +int main(int argc, char *argv[]) { + rclcpp::init(argc, argv); + rclcpp::spin(std::make_shared()); + rclcpp::shutdown(); + return 0; +}