From 741505a84e97a710a2e0027d3362557051bc77b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ag=C3=BCero?= Date: Thu, 14 Sep 2023 20:42:13 +0200 Subject: [PATCH 1/2] Fix Harmonic links in the tutorials. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Agüero --- tutorials/04_messages.md | 18 +++++++++--------- tutorials/05_services.md | 20 ++++++++++---------- tutorials/07_relay.md | 10 +++++----- tutorials/10_logging.md | 6 +++--- tutorials/23_topic_statistics.md | 2 +- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/tutorials/04_messages.md b/tutorials/04_messages.md index 672322d6b..0f07e4c3c 100644 --- a/tutorials/04_messages.md +++ b/tutorials/04_messages.md @@ -17,7 +17,7 @@ cd ~/gz_transport_tutorial ## Publisher -Download the [publisher.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport12/example/publisher.cc) file within the `gz_transport_tutorial` +Download the [publisher.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport13/example/publisher.cc) file within the `gz_transport_tutorial` folder and open it with your favorite editor: ```{.cpp} @@ -132,7 +132,7 @@ The method *Publish()* sends a message to all the subscribers. ## Subscriber -Download the [subscriber.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport12/example/subscriber.cc) +Download the [subscriber.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport13/example/subscriber.cc) file into the `gz_transport_tutorial` folder and open it with your favorite editor: ```{.cpp} @@ -212,7 +212,7 @@ until you hit *CTRL-C*. Note that this function captures the *SIGINT* and ## Building the code -Download the [CMakeLists.txt](https://github.com/gazebosim/gz-transport/raw/gz-transport12/example/CMakeLists.txt) file within the `gz_transport_tutorial` folder. +Download the [CMakeLists.txt](https://github.com/gazebosim/gz-transport/raw/gz-transport13/example/CMakeLists.txt) file within the `gz_transport_tutorial` folder. Once you have all your files, go ahead and create a `build/` directory within the `gz_transport_tutorial` directory. @@ -359,7 +359,7 @@ between Gazebo Transport and another protocol or if you want to just print the content of a generic protobuf message using `DebugString()`, among other use cases. -Download the [subscriber_generic.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport12/example/subscriber_generic.cc) file within the `gz_transport_tutorial` folder and open it with your favorite editor: +Download the [subscriber_generic.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport13/example/subscriber_generic.cc) file within the `gz_transport_tutorial` folder and open it with your favorite editor: ```{.cpp} #include @@ -488,12 +488,12 @@ often the integration of the message generation into the build system of your project. Next, you can find an example of a publisher and subscriber using a custom Protobuf message integrated with CMake. -Download the [publisher_custom_msg.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport12/example/publisher_custom_msg.cc) -and the [subscriber_custom_msg.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport12/example/subscriber_custom_msg.cc) +Download the [publisher_custom_msg.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport13/example/publisher_custom_msg.cc) +and the [subscriber_custom_msg.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport13/example/subscriber_custom_msg.cc) files within the `gz_transport_tutorial`. Then, create a `msgs` folder and -download the [stringmsg.proto](https://github.com/gazebosim/gz-transport/raw/gz-transport12/example/msgs/stringmsg.proto) -and the [CMakeLists.txt](https://github.com/gazebosim/gz-transport/raw/gz-transport12/example/msgs/CMakeLists.txt) -files within the `msgs` folder. Finally, we'll need the main [CMakeLists.txt](https://github.com/gazebosim/gz-transport/raw/gz-transport12/example/CMakeLists.txt) +download the [stringmsg.proto](https://github.com/gazebosim/gz-transport/raw/gz-transport13/example/msgs/stringmsg.proto) +and the [CMakeLists.txt](https://github.com/gazebosim/gz-transport/raw/gz-transport13/example/msgs/CMakeLists.txt) +files within the `msgs` folder. Finally, we'll need the main [CMakeLists.txt](https://github.com/gazebosim/gz-transport/raw/gz-transport13/example/CMakeLists.txt) file. You should have this file from the previous examples. Otherwise, download and place it within the `gz_transport_tutorial` folder. diff --git a/tutorials/05_services.md b/tutorials/05_services.md index 965586538..a411195cd 100644 --- a/tutorials/05_services.md +++ b/tutorials/05_services.md @@ -25,7 +25,7 @@ cd ~/gz_transport_tutorial ## Responser -Download the [responser.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport12/example/responser.cc) file within the ``gz_transport_tutorial`` +Download the [responser.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport13/example/responser.cc) file within the ``gz_transport_tutorial`` folder and open it with your favorite editor: ```{.cpp} @@ -133,7 +133,7 @@ until you hit *CTRL-C*. Note that this function captures the *SIGINT* and ## Synchronous requester -Download the [requester.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport12/example/requester.cc) file within the ``gz_transport_tutorial`` +Download the [requester.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport13/example/requester.cc) file within the ``gz_transport_tutorial`` folder and open it with your favorite editor: ```{.cpp} @@ -228,7 +228,7 @@ message. ## Asynchronous requester -Download the [requester_async.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport12/example/requester_async.cc) file within the +Download the [requester_async.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport13/example/requester_async.cc) file within the ``gz_transport_tutorial`` folder and open it with your favorite editor: ```{.cpp} @@ -314,7 +314,7 @@ oneway service to process service requests without sending back responses. Oneway services don't accept any output parameters nor the requests have to wait for the response. -Download the [responser_oneway.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport12/example/responser_oneway.cc) file within the +Download the [responser_oneway.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport13/example/responser_oneway.cc) file within the ``gz_transport_tutorial`` folder and open it with your favorite editor: ```{.cpp} @@ -389,7 +389,7 @@ This case is similar to the oneway service provider. This code can be used for requesting a service that does not need a response back. We don't need any output parameters in this case nor we have to wait for the response. -Download the [requester_oneway.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport12/example/requester_oneway.cc) file within the +Download the [requester_oneway.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport13/example/requester_oneway.cc) file within the ``gz_transport_tutorial`` folder and open it with your favorite editor: ```{.cpp} @@ -454,7 +454,7 @@ request was already published. Sometimes we want to receive some result but don't have any input parameter to send. -Download the [responser_no_input.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport12/example/responser_no_input.cc) +Download the [responser_no_input.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport13/example/responser_no_input.cc) file within the ``gz_transport_tutorial`` folder and open it with your favorite editor: @@ -534,7 +534,7 @@ service requests. This case is similar to the service without input parameter. We don't send any request. -Download the [requester_no_input.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport12/example/requester_no_input.cc) +Download the [requester_no_input.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport13/example/requester_no_input.cc) file within the ``gz_transport_tutorial`` folder and open it with your favorite editor: @@ -577,14 +577,14 @@ request timed out or reached the service provider and ``result`` shows if the service was successfully executed. We also have the async version for service request without input. You should -download [requester_async_no_input.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport12/example/requester_async_no_input.cc) +download [requester_async_no_input.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport13/example/requester_async_no_input.cc) file within the ``gz_transport_tutorial`` folder. ## Building the code -Download the [CMakeLists.txt](https://github.com/gazebosim/gz-transport/raw/gz-transport12/example/CMakeLists.txt) file +Download the [CMakeLists.txt](https://github.com/gazebosim/gz-transport/raw/gz-transport13/example/CMakeLists.txt) file within the ``gz_transport_tutorial`` folder. Then, create a `msgs` directory -and download [CMakeLists.txt](https://github.com/gazebosim/gz-transport/raw/gz-transport12/example/msgs/CMakeLists.txt) and [stringmsg.proto](https://github.com/gazebosim/gz-transport/raw/gz-transport12/example/msgs/stringmsg.proto) inside the +and download [CMakeLists.txt](https://github.com/gazebosim/gz-transport/raw/gz-transport13/example/msgs/CMakeLists.txt) and [stringmsg.proto](https://github.com/gazebosim/gz-transport/raw/gz-transport13/example/msgs/stringmsg.proto) inside the ``msgs`` directory. Once you have all your files, go ahead and create a ``build/`` folder within diff --git a/tutorials/07_relay.md b/tutorials/07_relay.md index 3ee5c3a11..8eab9676a 100644 --- a/tutorials/07_relay.md +++ b/tutorials/07_relay.md @@ -25,13 +25,13 @@ install Docker following any of the existing guides available ([here](https://docs.docker.com/get-docker/)'s one). We're going to build a Docker image and run it inside your host computer. -Download the [build.bash](https://github.com/gazebosim/gz-transport/raw/gz-transport12/docker/build.bash), [run.bash](https://github.com/gazebosim/gz-transport/raw/gz-transport12/docker/run.bash) and -[Dockerfile](https://github.com/gazebosim/gz-transport/raw/gz-transport12/docker/gz-transport/Dockerfile) files. +Download the [build.bash](https://github.com/gazebosim/gz-transport/raw/gz-transport13/docker/build.bash), [run.bash](https://github.com/gazebosim/gz-transport/raw/gz-transport13/docker/run.bash) and +[Dockerfile](https://github.com/gazebosim/gz-transport/raw/gz-transport13/docker/gz-transport/Dockerfile) files. ```{.sh} -wget https://github.com/gazebosim/gz-transport/raw/gz-transport12/docker/build.bash -wget https://github.com/gazebosim/gz-transport/raw/gz-transport12/docker/run.bash -mkdir gz-transport && wget https://github.com/gazebosim/gz-transport/raw/gz-transport12/docker/gz-transport/Dockerfile -O gz-transport/Dockerfile +wget https://github.com/gazebosim/gz-transport/raw/gz-transport13/docker/build.bash +wget https://github.com/gazebosim/gz-transport/raw/gz-transport13/docker/run.bash +mkdir gz-transport && wget https://github.com/gazebosim/gz-transport/raw/gz-transport13/docker/gz-transport/Dockerfile -O gz-transport/Dockerfile chmod +x build.bash run.bash ``` diff --git a/tutorials/10_logging.md b/tutorials/10_logging.md index c2de0e48d..7cb22cd4c 100644 --- a/tutorials/10_logging.md +++ b/tutorials/10_logging.md @@ -25,7 +25,7 @@ cd ~/gz_transport_tutorial ## Record -Download the [record.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport12/example/record.cc) +Download the [record.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport13/example/record.cc) file within the `gz_transport_tutorial` folder and open it with your favorite editor: ```{.cpp} @@ -126,7 +126,7 @@ stops the log recording as expected. ## Play back -Download the [playback.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport12/example/playback.cc) +Download the [playback.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport13/example/playback.cc) file within the `gz_transport_tutorial` folder and open it with your favorite editor: @@ -215,7 +215,7 @@ thread until all messages have been published. ## Building the code -Download the [CMakeLists.txt](https://github.com/gazebosim/gz-transport/raw/gz-transport12/example/CMakeLists.txt) +Download the [CMakeLists.txt](https://github.com/gazebosim/gz-transport/raw/gz-transport13/example/CMakeLists.txt) file within the `gz_transport_tutorial` folder. Once you have all your files, go ahead and create a `build/` directory within diff --git a/tutorials/23_topic_statistics.md b/tutorials/23_topic_statistics.md index eb2011cd3..8d55d17bf 100644 --- a/tutorials/23_topic_statistics.md +++ b/tutorials/23_topic_statistics.md @@ -44,7 +44,7 @@ if (!node.EnableStats(topic, true)) } ``` -A complete example can be found in the [subscriber_stats example program](https://github.com/gazebosim/gz-transport/blob/gz-transport12/example/subscriber_stats.cc). +A complete example can be found in the [subscriber_stats example program](https://github.com/gazebosim/gz-transport/blob/gz-transport13/example/subscriber_stats.cc). With both `GZ_TRANSPORT_TOPIC_STATISTICS` set to `1` and a node enabling topic statistics, then you will be able to echo statistic From e1175c954bc8bfd8b1e3d63f86b5f1801845710c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ag=C3=BCero?= Date: Wed, 27 Sep 2023 22:21:10 +0200 Subject: [PATCH 2/2] Use snippet to include two files. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Agüero --- example/publisher.cc | 2 + example/subscriber.cc | 2 + tutorials/04_messages.md | 90 +--------------------------------------- 3 files changed, 6 insertions(+), 88 deletions(-) diff --git a/example/publisher.cc b/example/publisher.cc index c4e6717ab..0073c45a1 100644 --- a/example/publisher.cc +++ b/example/publisher.cc @@ -15,6 +15,7 @@ * */ +//! [complete] #include #include #include @@ -71,3 +72,4 @@ int main(int argc, char **argv) return 0; } +//! [complete] diff --git a/example/subscriber.cc b/example/subscriber.cc index f4b02d9f9..41ac6baed 100644 --- a/example/subscriber.cc +++ b/example/subscriber.cc @@ -15,6 +15,7 @@ * */ +//! [complete] #include #include #include @@ -45,3 +46,4 @@ int main(int argc, char **argv) return 0; } +//! [complete] diff --git a/tutorials/04_messages.md b/tutorials/04_messages.md index 0f07e4c3c..98528d5fe 100644 --- a/tutorials/04_messages.md +++ b/tutorials/04_messages.md @@ -20,63 +20,7 @@ cd ~/gz_transport_tutorial Download the [publisher.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport13/example/publisher.cc) file within the `gz_transport_tutorial` folder and open it with your favorite editor: -```{.cpp} -#include -#include -#include -#include -#include -#include -#include -#include - -/// brief Flag used to break the publisher loop and terminate the program. -static std::atomic g_terminatePub(false); - -////////////////////////////////////////////////// -/// brief Function callback executed when a SIGINT or SIGTERM signals are -/// captured. This is used to break the infinite loop that publishes messages -/// and exit the program smoothly. -void signal_handler(int _signal) -{ - if (_signal == SIGINT || _signal == SIGTERM) - g_terminatePub = true; -} - -////////////////////////////////////////////////// -int main(int argc, char **argv) -{ - // Install a signal handler for SIGINT and SIGTERM. - std::signal(SIGINT, signal_handler); - std::signal(SIGTERM, signal_handler); - - // Create a transport node and advertise a topic. - gz::transport::Node node; - std::string topic = "/foo"; - - auto pub = node.Advertise(topic); - if (!pub) - { - std::cerr << "Error advertising topic [" << topic << "]" << std::endl; - return -1; - } - - // Prepare the message. - gz::msgs::StringMsg msg; - msg.set_data("HELLO"); - - // Publish messages at 1Hz. - while (!g_terminatePub) - { - if (!pub.Publish(msg)) - break; - std::cout << "Publishing hello on topic [" << topic << "]" << std::endl; - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - } - - return 0; -} -``` +\snippet example/publisher.cc complete ### Walkthrough @@ -135,37 +79,7 @@ The method *Publish()* sends a message to all the subscribers. Download the [subscriber.cc](https://github.com/gazebosim/gz-transport/raw/gz-transport13/example/subscriber.cc) file into the `gz_transport_tutorial` folder and open it with your favorite editor: -```{.cpp} -#include -#include -#include -#include - -////////////////////////////////////////////////// -/// brief Function called each time a topic update is received. -void cb(const gz::msgs::StringMsg &_msg) -{ - std::cout << "Msg: " << _msg.data() << std::endl << std::endl; -} - -////////////////////////////////////////////////// -int main(int argc, char **argv) -{ - gz::transport::Node node; - std::string topic = "/foo"; - // Subscribe to a topic by registering a callback. - if (!node.Subscribe(topic, cb)) - { - std::cerr << "Error subscribing to topic [" << topic << "]" << std::endl; - return -1; - } - - // Zzzzzz. - gz::transport::waitForShutdown(); - - return 0; -} -``` +\snippet example/subscriber.cc complete ### Walkthrough