Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Harmonic links in the tutorials #439

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions example/publisher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*
*/

//! [complete]
#include <atomic>
#include <chrono>
#include <csignal>
Expand Down Expand Up @@ -71,3 +72,4 @@ int main(int argc, char **argv)

return 0;
}
//! [complete]
2 changes: 2 additions & 0 deletions example/subscriber.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*
*/

//! [complete]
#include <iostream>
#include <string>
#include <gz/msgs.hh>
Expand Down Expand Up @@ -45,3 +46,4 @@ int main(int argc, char **argv)

return 0;
}
//! [complete]
108 changes: 11 additions & 97 deletions tutorials/04_messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,66 +17,10 @@ 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`
azeey marked this conversation as resolved.
Show resolved Hide resolved
folder and open it with your favorite editor:

```{.cpp}
#include <atomic>
#include <chrono>
#include <csignal>
#include <iostream>
#include <string>
#include <thread>
#include <gz/msgs.hh>
#include <gz/transport.hh>

/// brief Flag used to break the publisher loop and terminate the program.
static std::atomic<bool> 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<gz::msgs::StringMsg>(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

Expand Down Expand Up @@ -132,40 +76,10 @@ 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}
#include <iostream>
#include <string>
#include <gz/msgs.hh>
#include <gz/transport.hh>

//////////////////////////////////////////////////
/// 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

Expand Down Expand Up @@ -212,7 +126,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.
Expand Down Expand Up @@ -359,7 +273,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 <google/protobuf/message.h>
Expand Down Expand Up @@ -488,12 +402,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.

Expand Down
20 changes: 10 additions & 10 deletions tutorials/05_services.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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:

Expand Down Expand Up @@ -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:

Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions tutorials/07_relay.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
6 changes: 3 additions & 3 deletions tutorials/10_logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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:

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tutorials/23_topic_statistics.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down