fix(cmake): Compile libpaho with the project

This commit is contained in:
2025-11-06 10:56:41 +01:00
committed by Vincent Winter
parent 0fd0eb693f
commit 998d471eda
2 changed files with 28 additions and 51 deletions

View File

@@ -42,54 +42,17 @@ ros2 launch g2_2025_imu_reader_pkg imu_reader.launch.xml
``` ```
To change parameters when using the launch file it will need to be edited in the `src/g2_2025_imu_reader_pkg/launch` folder. All parameters are already added to this document and thus only the values will need to be changed To change parameters when using the launch file it will need to be edited in the `src/g2_2025_imu_reader_pkg/launch` folder. All parameters are already added to this document and thus only the values will need to be changed
### installation and setup for mqtt ## For launching lifecycle mqtt node
```bash First:
sudo apt install mosquitto
sudo apt-get install libpaho-mqtt-dev
git clone https://github.com/eclipse/paho.mqtt.cpp
cd paho.mqtt.cpp
git co v1.5.4
git submodule init
git submodule update
cmake -Bbuild -H. -DPAHO_WITH_MQTT_C=ON -DPAHO_BUILD_EXAMPLES=ON
sudo cmake --build build/ --target install
```
## for launching lifecycle mqtt node
first:
```bash ```bash
ros2 run g2_2025_imu_reader_pkg g2_2025_lifecycle_node --ros-args -p comm_t:='mqtt' ros2 run g2_2025_imu_reader_pkg g2_2025_lifecycle_node --ros-args -p comm_t:='mqtt'
``` ```
in other terminal:
```bash
mosquitto
```
and in other terminal to inialize the subscriber: and in other terminal to inialize the subscriber:
```bash ```bash
ros2 lifecycle set /lifecycle_manager configure ros2 lifecycle set /lifecycle_manager configure
ros2 lifecycle set /lifecycle_manager activate ros2 lifecycle set /lifecycle_manager activate
ros2 lifecycle set /lifecycle_manager deactivate ros2 lifecycle set /lifecycle_manager deactivate
ros2 lifecycle set /lifecycle_manager shutdown ros2 lifecycle set /lifecycle_manager shutdown
```
And finally publish a message to the sub in other terminal:
```bash
mosquitto_pub -h localhost -p 1883 -t "esp32/imu" -m "test"
```
close connection via:
```bash
ros2 lifecycle set /lifecycle_manager deactivate
``` ```

View File

@@ -8,13 +8,35 @@ endif()
# external packages # external packages
include(FetchContent) include(FetchContent)
fetchcontent_declare( FetchContent_Declare(
tomlplusplus tomlplusplus
GIT_REPOSITORY https://github.com/marzer/tomlplusplus.git GIT_REPOSITORY https://github.com/marzer/tomlplusplus.git
GIT_TAG v3.4.0 GIT_TAG v3.4.0
) )
fetchcontent_makeavailable(tomlplusplus) FetchContent_MakeAvailable(tomlplusplus)
FetchContent_Declare(
paho_mqtt_cpp
GIT_REPOSITORY https://github.com/eclipse/paho.mqtt.cpp.git
GIT_TAG v1.5.2
)
set(PAHO_WITH_MQTT_C ON CACHE BOOL "Build with Paho MQTT C library" FORCE)
set(PAHO_MQTT_CPP_BUILD_STATIC ON CACHE BOOL "Build static library" FORCE)
set(PAHO_MQTT_CPP_BUILD_SHARED OFF CACHE BOOL "Build shared library" FORCE)
set(PAHO_WITH_SSL OFF CACHE BOOL "Build with SSL support" FORCE)
set(PAHO_BUILD_EXAMPLES OFF CACHE BOOL "Build example programs" FORCE)
FetchContent_MakeAvailable(paho_mqtt_cpp)
FetchContent_Declare(
nlohmann_json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.12.0
)
FetchContent_MakeAvailable(nlohmann_json)
# find dependencies # find dependencies
find_package(ament_cmake REQUIRED) find_package(ament_cmake REQUIRED)
@@ -23,7 +45,6 @@ find_package(rclcpp_action REQUIRED)
find_package(std_msgs REQUIRED) find_package(std_msgs REQUIRED)
find_package(sensor_msgs REQUIRED) find_package(sensor_msgs REQUIRED)
find_package(rclcpp_lifecycle REQUIRED) find_package(rclcpp_lifecycle REQUIRED)
find_package(nlohmann_json REQUIRED)
add_executable(g2_2025_imu_database_writer_node add_executable(g2_2025_imu_database_writer_node
src/g2_2025_imu_database_writer_node/Main.cpp src/g2_2025_imu_database_writer_node/Main.cpp
@@ -38,9 +59,6 @@ target_include_directories(g2_2025_imu_database_writer_node PRIVATE
) )
ament_target_dependencies(g2_2025_imu_database_writer_node rclcpp sensor_msgs) ament_target_dependencies(g2_2025_imu_database_writer_node rclcpp sensor_msgs)
target_link_libraries(g2_2025_imu_database_writer_node pqxx pq tomlplusplus::tomlplusplus) target_link_libraries(g2_2025_imu_database_writer_node pqxx pq tomlplusplus::tomlplusplus)
ament_target_dependencies(g2_2025_imu_database_writer_node rclcpp sensor_msgs)
target_link_libraries(g2_2025_imu_database_writer_node pqxx pq tomlplusplus::tomlplusplus)
add_executable(g2_2025_lifecycle_node add_executable(g2_2025_lifecycle_node
src/g2_2025_lifecycle_node/main.cpp src/g2_2025_lifecycle_node/main.cpp
@@ -56,13 +74,10 @@ target_include_directories(g2_2025_lifecycle_node PRIVATE
ament_target_dependencies(g2_2025_lifecycle_node rclcpp rclcpp_lifecycle std_msgs sensor_msgs) ament_target_dependencies(g2_2025_lifecycle_node rclcpp rclcpp_lifecycle std_msgs sensor_msgs)
target_link_libraries(g2_2025_lifecycle_node target_link_libraries(g2_2025_lifecycle_node
paho-mqttpp3 paho-mqttpp3-static
paho-mqtt3a
nlohmann_json::nlohmann_json nlohmann_json::nlohmann_json
) )
install( install(
TARGETS TARGETS
g2_2025_imu_database_writer_node g2_2025_imu_database_writer_node
@@ -142,8 +157,7 @@ if(BUILD_TESTING)
sensor_msgs sensor_msgs
) )
target_link_libraries(${PROJECT_NAME}_test_lifecycle_manager target_link_libraries(${PROJECT_NAME}_test_lifecycle_manager
paho-mqttpp3 paho-mqttpp3-static
paho-mqtt3a
nlohmann_json::nlohmann_json nlohmann_json::nlohmann_json
) )
set_target_properties(${PROJECT_NAME}_test_lifecycle_manager PROPERTIES INSTALL_RPATH "/usr/local/lib") set_target_properties(${PROJECT_NAME}_test_lifecycle_manager PROPERTIES INSTALL_RPATH "/usr/local/lib")