{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "b9aee55e-f346-423e-9fd9-ac1fedaa9b3e", "metadata": {}, "outputs": [], "source": [ "! ../scripts/generate_cling_ros2.py ~/ros2_foxy/install" ] }, { "cell_type": "code", "execution_count": null, "id": "649f51ab-b279-404d-b86f-fae965ca4645", "metadata": {}, "outputs": [], "source": [ "#include \"load_ros2.h\"" ] }, { "cell_type": "code", "execution_count": null, "id": "317d888a-751f-4260-bba1-ce6f70265661", "metadata": {}, "outputs": [], "source": [ "#include \n", "#include \n", "#include \n", "#include \n", "\n", "#include \"rclcpp/rclcpp.hpp\"\n", "#include \"std_msgs/msg/string.hpp\"\n", "\n", "using namespace std::chrono_literals;" ] }, { "cell_type": "code", "execution_count": null, "id": "f5fb0b33-c0d7-41a6-9dd5-9b3084652569", "metadata": {}, "outputs": [], "source": [ "class MinimalPublisher : public rclcpp::Node\n", "{\n", " public:\n", " MinimalPublisher()\n", " : Node(\"minimal_publisher\"), count_(0)\n", " {\n", " publisher_ = this->create_publisher(\"topic\", 10);\n", " timer_ = this->create_wall_timer(\n", " 500ms, std::bind(&MinimalPublisher::timer_callback, this));\n", " }\n", "\n", " private:\n", " void timer_callback()\n", " {\n", " auto message = std_msgs::msg::String();\n", " message.data = \"Hello, world! \" + std::to_string(count_++);\n", " RCLCPP_INFO(this->get_logger(), \"Publishing: '%s'\", message.data.c_str());\n", " publisher_->publish(message);\n", " }\n", " rclcpp::TimerBase::SharedPtr timer_;\n", " rclcpp::Publisher::SharedPtr publisher_;\n", " size_t count_;\n", "};" ] }, { "cell_type": "code", "execution_count": null, "id": "5501a245-20ac-4efd-979f-f164fea027ff", "metadata": {}, "outputs": [], "source": [ "int argc = 1;\n", "char *argv[1];\n", "argv[0] = new char[10];\n", "strncpy(argv[0],\"publisher\", 10);\n", "\n", "rclcpp::init(argc, argv);\n", "rclcpp::spin(std::make_shared());\n", "rclcpp::shutdown();" ] }, { "cell_type": "code", "execution_count": null, "id": "4fb8e16d-6065-42ee-8e15-9c73303e3b26", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "C++17", "language": "C++17", "name": "xcpp17" }, "language_info": { "codemirror_mode": "text/x-c++src", "file_extension": ".cpp", "mimetype": "text/x-c++src", "name": "c++", "version": "17" } }, "nbformat": 4, "nbformat_minor": 5 }