Skip to content

Commit eadbf0d

Browse files
authored
Merge pull request #31 from ika-rwth-aachen/features/ros2-component
ROS2 Component
2 parents 8cef761 + b7db7d2 commit eadbf0d

File tree

9 files changed

+63
-63
lines changed

9 files changed

+63
-63
lines changed

.github/workflows/docker-ros.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
ros:
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: ika-rwth-aachen/docker-ros@v1.0.0
10+
- uses: ika-rwth-aachen/docker-ros@main
1111
with:
1212
image-tag: ros
1313
base-image: rwthika/ros:latest
@@ -18,7 +18,7 @@ jobs:
1818
ros2:
1919
runs-on: ubuntu-latest
2020
steps:
21-
- uses: ika-rwth-aachen/docker-ros@v1.0.0
21+
- uses: ika-rwth-aachen/docker-ros@main
2222
with:
2323
image-tag: ros2
2424
base-image: rwthika/ros2:latest

.gitlab-ci.ros.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

.gitlab-ci.ros2.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

.gitlab-ci.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
ros:
22
trigger:
3-
include: .gitlab-ci.ros.yml
3+
include:
4+
- remote: https://raw.githubusercontent.com/ika-rwth-aachen/docker-ros/main/.gitlab-ci/docker-ros.yml
45
strategy: depend
6+
variables:
7+
IMAGE_TAG: ros
8+
BASE_IMAGE: rwthika/ros:latest
9+
COMMAND: roslaunch mqtt_client standalone.launch
10+
PLATFORM: amd64,arm64
11+
TARGET: dev,run
12+
ENABLE_INDUSTRIAL_CI: 'true'
513

614
ros2:
715
trigger:
8-
include: .gitlab-ci.ros2.yml
16+
include:
17+
- remote: https://raw.githubusercontent.com/ika-rwth-aachen/docker-ros/main/.gitlab-ci/docker-ros.yml
918
strategy: depend
19+
variables:
20+
IMAGE_TAG: ros2
21+
BASE_IMAGE: rwthika/ros2:latest
22+
COMMAND: ros2 launch mqtt_client standalone.launch.ros2.xml
23+
PLATFORM: amd64,arm64
24+
TARGET: dev,run
25+
ENABLE_INDUSTRIAL_CI: 'true'
26+
ENABLE_PUSH_AS_LATEST: 'true'

README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<a href="https://github.com/ika-rwth-aachen/mqtt_client"><img src="https://img.shields.io/github/stars/ika-rwth-aachen/mqtt_client?style=social"/></a>
1111
</p>
1212

13-
The *mqtt_client* package provides a ROS nodelet or ROS 2 node that enables connected ROS-based devices or robots to exchange ROS messages via an MQTT broker using the [MQTT](http://mqtt.org) protocol. This works generically for arbitrary ROS message types. The *mqtt_client* can also exchange primitive messages with MQTT clients running on devices not based on ROS.
13+
The *mqtt_client* package provides a ROS nodelet or ROS 2 component node that enables connected ROS-based devices or robots to exchange ROS messages via an MQTT broker using the [MQTT](http://mqtt.org) protocol. This works generically for arbitrary ROS message types. The *mqtt_client* can also exchange primitive messages with MQTT clients running on devices not based on ROS.
1414

1515
- [Installation](#installation)
1616
- [docker-ros](#docker-ros)
@@ -109,7 +109,7 @@ bridge:
109109
110110
#### Demo Client Launch
111111
112-
After building your ROS workspace, launch the *mqtt_client* nodelet with the pre-configured demo parameters using *roslaunch*, which should yield the following output.
112+
After building your ROS workspace, launch the *mqtt_client* node with the pre-configured demo parameters using *roslaunch*, which should yield the following output.
113113
114114
```bash
115115
# ROS
@@ -126,8 +126,8 @@ ros2 launch mqtt_client standalone.launch.ros2.xml
126126
[ WARN] [1665575657.360300703]: Parameter 'client/clean_session' not set, defaulting to '1'
127127
[ WARN] [1665575657.360576344]: Parameter 'client/keep_alive_interval' not set, defaulting to '60.000000'
128128
[ WARN] [1665575657.360847295]: Parameter 'client/max_inflight' not set, defaulting to '65535'
129-
[ INFO] [1665575657.361281461]: Bridging ROS topic '/ping/ros' to MQTT topic 'pingpong/ros'
130-
[ INFO] [1665575657.361303380]: Bridging primitive ROS topic '/ping/primitive' to MQTT topic 'pingpong/primitive'
129+
[ INFO] [1665575657.361281461]: Bridging ROS topic '/ping/ros' to MQTT topic 'pingpong/ros'
130+
[ INFO] [1665575657.361303380]: Bridging primitive ROS topic '/ping/primitive' to MQTT topic 'pingpong/primitive'
131131
[ INFO] [1665575657.361352809]: Bridging MQTT topic 'pingpong/ros' to ROS topic '/pong/ros'
132132
[ INFO] [1665575657.361370558]: Bridging MQTT topic 'pingpong/primitive' to primitive ROS topic '/pong/primitive'
133133
[ INFO] [1665575657.362153083]: Connecting to broker at 'tcp://localhost:1883' ...
@@ -169,7 +169,7 @@ ros2 launch mqtt_client standalone.launch.ros2.xml params_file:=$(ros2 pkg prefi
169169
```bash
170170
# 3rd terminal: publish primitive ROS message to /ping/primitive
171171

172-
# ROS1
172+
# ROS
173173
rostopic pub -r 1 /ping/primitive std_msgs/Int32 42
174174

175175
# ROS2
@@ -195,7 +195,7 @@ If everything works as expected, the second terminal should print a message at 1
195195

196196
### Launch
197197

198-
You can start the *mqtt_client* nodelet in a standalone nodelet manager with:
198+
You can start the *mqtt_client* node with:
199199

200200
```bash
201201
# ROS
@@ -215,7 +215,7 @@ roslaunch mqtt_client standalone.launch params_file:="</PATH/TO/PARAMS.YAML>"
215215
ros2 launch mqtt_client standalone.launch.ros2.xml params_file:="</PATH/TO/PARAMS.YAML>"
216216
```
217217

218-
In order to exploit the benefits of *mqtt_client* being a ROS 1 nodelet, load the nodelet to your own nodelet manager shared with other nodelets.
218+
In order to exploit the benefits of *mqtt_client* being a ROS nodelet / ROS 2 component, load the nodelet / component to your own nodelet manager / component container.
219219

220220
### Configuration
221221

@@ -261,7 +261,7 @@ client:
261261
262262
#### Bridge Parameters
263263
264-
##### ROS 1
264+
##### ROS
265265
266266
```yaml
267267
bridge:
@@ -369,19 +369,19 @@ Enables connected ROS-based devices or robots to exchange ROS messages via an MQ
369369

370370
###### Subscribed Topics
371371

372-
- `<bridge/ros2mqtt[*]/ros_topic>` ([`topic_tools/ShapeShifter`](http://wiki.ros.org/topic_tools))
372+
- `<bridge/ros2mqtt[*]/ros_topic>` ([`topic_tools/ShapeShifter`](http://wiki.ros.org/topic_tools))
373373
ROS topic whose messages are transformed to MQTT messages and sent to the MQTT broker. May have arbitrary ROS message type.
374374

375375
###### Published Topics
376376

377-
- `<bridge/mqtt2ros[*]/ros_topic>` ([`topic_tools/ShapeShifter`](http://wiki.ros.org/topic_tools))
377+
- `<bridge/mqtt2ros[*]/ros_topic>` ([`topic_tools/ShapeShifter`](http://wiki.ros.org/topic_tools))
378378
ROS topic on which MQTT messages received from the MQTT broker are published. May have arbitrary ROS message type.
379-
- `~/latencies/<bridge/mqtt2ros[*]/ros_topic>` ([`std_msgs/Float64`](https://docs.ros.org/en/api/std_msgs/html/msg/Float64.html))
379+
- `~/latencies/<bridge/mqtt2ros[*]/ros_topic>` ([`std_msgs/Float64`](https://docs.ros.org/en/api/std_msgs/html/msg/Float64.html))
380380
Latencies measured on the message transfer to `<bridge/mqtt2ros[*]/ros_topic>` are published here, if the received messages have a timestamp injected (see [Latency Computation](#latency-computation)).
381381

382382
###### Services
383383

384-
- `is_connected` ([`mqtt_client/srv/IsConnected`](mqtt_client_interfaces/srv/IsConnected.srv))
384+
- `is_connected` ([`mqtt_client/srv/IsConnected`](mqtt_client_interfaces/srv/IsConnected.srv))
385385
Returns whether the client is connected to the MQTT broker.
386386

387387
###### Parameters
@@ -390,27 +390,27 @@ See [Configuration](#configuration).
390390

391391
### ROS 2
392392

393-
#### Nodes
393+
#### Components
394394

395-
##### `mqtt_client/mqtt_client`
395+
##### `mqtt_client/MqttClient`
396396

397397
Enables connected ROS-based devices or robots to exchange ROS messages via an MQTT broker using the [MQTT](http://mqtt.org) protocol.
398398

399399
###### Subscribed Topics
400400

401-
- `<bridge/ros2mqtt/ros_topic>` ([`rclcpp::SerializedMessage`](https://docs.ros.org/en/ros2_packages/rolling/api/rclcpp/generated/classrclcpp_1_1GenericSubscription.html))
401+
- `<bridge/ros2mqtt/ros_topic>` ([`rclcpp::SerializedMessage`](https://docs.ros.org/en/ros2_packages/rolling/api/rclcpp/generated/classrclcpp_1_1GenericSubscription.html))
402402
ROS topic whose messages are transformed to MQTT messages and sent to the MQTT broker. May have arbitrary ROS message type.
403403

404404
###### Published Topics
405405

406-
- `<bridge/mqtt2ros/ros_topic>` ([`rclcpp::SerializedMessage`](https://docs.ros.org/en/ros2_packages/rolling/api/rclcpp/generated/classrclcpp_1_1GenericPublisher.html))
406+
- `<bridge/mqtt2ros/ros_topic>` ([`rclcpp::SerializedMessage`](https://docs.ros.org/en/ros2_packages/rolling/api/rclcpp/generated/classrclcpp_1_1GenericPublisher.html))
407407
ROS topic on which MQTT messages received from the MQTT broker are published. May have arbitrary ROS message type.
408-
- `~/latencies/<bridge/mqtt2ros/ros_topic>` ([`std_msgs/Float64`](https://docs.ros.org/en/api/std_msgs/html/msg/Float64.html))
408+
- `~/latencies/<bridge/mqtt2ros/ros_topic>` ([`std_msgs/Float64`](https://docs.ros.org/en/api/std_msgs/html/msg/Float64.html))
409409
Latencies measured on the message transfer to `<bridge/mqtt2ros/ros_topic>` are published here, if the received messages have a timestamp injected (see [Latency Computation](#latency-computation)).
410410

411411
###### Services
412412

413-
- `is_connected` ([`mqtt_client/srv/IsConnected`](mqtt_client_interfaces/srv/IsConnected.srv))
413+
- `is_connected` ([`mqtt_client/srv/IsConnected`](mqtt_client_interfaces/srv/IsConnected.srv))
414414
Returns whether the client is connected to the MQTT broker.
415415

416416
###### Parameters

mqtt_client/CMakeLists.txt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,42 @@ if(${ROS_VERSION} EQUAL 2)
1818
find_package(fmt REQUIRED)
1919
find_package(mqtt_client_interfaces REQUIRED)
2020
find_package(rclcpp REQUIRED)
21+
find_package(rclcpp_components REQUIRED)
2122
find_package(std_msgs REQUIRED)
2223

2324
# Paho MQTT C++ apt package doesn't include CMake config
2425
# find_package(PahoMqttCpp REQUIRED)
2526
find_library(PahoMqttC_LIBRARY libpaho-mqtt3as.so.1 REQUIRED)
2627
find_library(PahoMqttCpp_LIBRARY libpaho-mqttpp3.so.1 REQUIRED)
2728

28-
add_executable(${PROJECT_NAME} src/MqttClient.ros2.cpp)
29+
add_library(${PROJECT_NAME}_lib SHARED src/MqttClient.ros2.cpp)
2930

30-
target_include_directories(${PROJECT_NAME} PUBLIC
31+
rclcpp_components_register_node(${PROJECT_NAME}_lib
32+
PLUGIN "mqtt_client::MqttClient"
33+
EXECUTABLE ${PROJECT_NAME}
34+
)
35+
36+
target_include_directories(${PROJECT_NAME}_lib PUBLIC
3137
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
3238
$<INSTALL_INTERFACE:include>)
3339

34-
target_link_libraries(${PROJECT_NAME}
40+
target_link_libraries(${PROJECT_NAME}_lib
3541
${PahoMqttC_LIBRARY}
3642
${PahoMqttCpp_LIBRARY}
3743
)
3844

39-
ament_target_dependencies(${PROJECT_NAME}
45+
ament_target_dependencies(${PROJECT_NAME}_lib
4046
fmt
4147
mqtt_client_interfaces
4248
rclcpp
49+
rclcpp_components
4350
std_msgs
4451
)
4552

46-
install(TARGETS
47-
${PROJECT_NAME}
48-
DESTINATION lib/${PROJECT_NAME}
53+
install(TARGETS ${PROJECT_NAME}_lib
54+
ARCHIVE DESTINATION lib
55+
LIBRARY DESTINATION lib
56+
RUNTIME DESTINATION bin
4957
)
5058

5159
install(

mqtt_client/include/mqtt_client/MqttClient.ros2.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ class MqttClient : public rclcpp::Node,
6363
public:
6464
/**
6565
* @brief Initializes node.
66+
*
67+
* @param[in] options ROS node options
6668
*/
67-
MqttClient();
69+
explicit MqttClient(const rclcpp::NodeOptions& options);
6870

6971
protected:
7072
/**

mqtt_client/package.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@
2727
<depend condition="$ROS_VERSION == 2">libpaho-mqtt-dev</depend>
2828
<depend condition="$ROS_VERSION == 2">libpaho-mqttpp-dev</depend>
2929
<depend condition="$ROS_VERSION == 2">rclcpp</depend>
30+
<depend condition="$ROS_VERSION == 2">rclcpp_components</depend>
3031
<depend condition="$ROS_VERSION == 2">rcpputils</depend>
3132

3233
<!-- ROS1 -->
3334
<buildtool_depend condition="$ROS_VERSION == 1">catkin</buildtool_depend>
3435
<depend condition="$ROS_VERSION == 1">nodelet</depend>
3536
<depend condition="$ROS_VERSION == 1">paho-mqtt-cpp</depend>
3637
<depend condition="$ROS_VERSION == 1">roscpp</depend>
37-
<depend condition="$ROS_VERSION == 1">rosfmt</depend> <!-- Needed for fmt library. -->
38+
<depend condition="$ROS_VERSION == 1">rosfmt</depend>
3839
<depend condition="$ROS_VERSION == 1">topic_tools</depend>
3940

4041
<export>

mqtt_client/src/MqttClient.ros2.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ SOFTWARE.
4747
#include <std_msgs/msg/u_int64.hpp>
4848
#include <std_msgs/msg/u_int8.hpp>
4949

50+
#include <rclcpp_components/register_node_macro.hpp>
51+
RCLCPP_COMPONENTS_REGISTER_NODE(mqtt_client::MqttClient)
52+
5053

5154
namespace mqtt_client {
5255

@@ -138,7 +141,7 @@ bool primitiveRosMessageToString(
138141
}
139142

140143

141-
MqttClient::MqttClient() : Node("mqtt_client") {
144+
MqttClient::MqttClient(const rclcpp::NodeOptions& options) : Node("mqtt_client", options) {
142145

143146
loadParameters();
144147
setup();
@@ -1007,13 +1010,3 @@ void MqttClient::on_failure(const mqtt::token& token) {
10071010
}
10081011

10091012
} // namespace mqtt_client
1010-
1011-
1012-
int main(int argc, char* argv[]) {
1013-
1014-
rclcpp::init(argc, argv);
1015-
rclcpp::spin(std::make_shared<mqtt_client::MqttClient>());
1016-
rclcpp::shutdown();
1017-
1018-
return 0;
1019-
}

0 commit comments

Comments
 (0)