Skip to content

Commit

Permalink
Add examples module (#18)
Browse files Browse the repository at this point in the history
# Description


## Type of change
Please delete options that are not relevant.

- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing
functionality to not work as expected)

## Checklist before requesting a review
- [ ] I have performed a self-review of my code.
- [ ] If it is a core feature, I have added thorough tests.
- [ ] If this is a new component I have added examples.
- [ ] I updated the README and related documentation.
  • Loading branch information
filippobrizzi authored Feb 2, 2024
1 parent 7a18aae commit 01e8b1d
Show file tree
Hide file tree
Showing 38 changed files with 187 additions and 224 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
PRESET: preferred
PRESET: CI

jobs:
docker_build_and_publish:
Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
run: cmake --build ${{github.workspace}}/build -- all examples

- name: Test
working-directory: ${{github.workspace}}/build
# working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ninja checks
run: cd ${{github.workspace}}/build && ninja check
8 changes: 4 additions & 4 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"installDir": "/install",
"toolchainFile": "${sourceDir}/toolchains/toolchain_clang.cmake",
"cacheVariables": {
"BUILD_MODULES": "all"
"BUILD_MODULES": "all;examples"
}
},
{
Expand All @@ -20,7 +20,7 @@
"installDir": "/install",
"toolchainFile": "${sourceDir}/toolchains/toolchain_clang.cmake",
"cacheVariables": {
"BUILD_MODULES": "all",
"BUILD_MODULES": "all;examples",
"ENABLE_LINTER": "OFF",
"CMAKE_BUILD_TYPE": "Release"
}
Expand All @@ -33,7 +33,7 @@
"installDir": "/install",
"toolchainFile": "${sourceDir}/toolchains/toolchain_clang.cmake",
"cacheVariables": {
"BUILD_MODULES": "all",
"BUILD_MODULES": "all;examples",
"ENABLE_LINTER": "OFF",
"CMAKE_BUILD_TYPE": "Release"
}
Expand All @@ -46,7 +46,7 @@
"installDir": "/install",
"toolchainFile": "${sourceDir}/toolchains/toolchain_clang.cmake",
"cacheVariables": {
"BUILD_MODULES": "all",
"BUILD_MODULES": "all;examples",
"ENABLE_LINTER": "ON",
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_PREFIX_PATH": "/install"
Expand Down
4 changes: 2 additions & 2 deletions cmake/05_modules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ endmacro()
# DEPENDS_ON_EXTERNAL_PROJECTS (list): List of tags to external projects that this module depends on
#
macro(declare_module)
set(flags ALWAYS_BUILD)
set(flags ALWAYS_BUILD EXCLUDE_FROM_ALL)
set(single_opts NAME)
set(multi_opts DEPENDS_ON_MODULES DEPENDS_ON_EXTERNAL_PROJECTS)

Expand All @@ -161,7 +161,7 @@ macro(declare_module)

# Either have it always build, or allow user to choose at configuration-time
if(("${MODULE_ARG_NAME}" IN_LIST BUILD_MODULES)
OR ("all" IN_LIST BUILD_MODULES)
OR (("all" IN_LIST BUILD_MODULES) AND NOT MODULE_ARG_EXCLUDE_FROM_ALL)
OR MODULE_ARG_ALWAYS_BUILD)
# Explicitly disable modules
if((NOT MODULE_ARG_ALWAYS_BUILD)
Expand Down
2 changes: 1 addition & 1 deletion modules/cli/include/eolo/cli/program_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ProgramOptions {
/// @brief Holds program options and their details
struct Option {
std::string key;
char short_key;
char short_key{};
std::string description;
std::string value_type;
std::string value;
Expand Down
59 changes: 59 additions & 0 deletions modules/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
declare_module(
NAME examples
DEPENDS_ON_MODULES base ipc serdes
DEPENDS_ON_EXTERNAL_PROJECTS Eigen3 fmt Protobuf
EXCLUDE_FROM_ALL
)

find_package(Eigen3 REQUIRED)
find_package(fmt REQUIRED)

add_subdirectory(proto)

# library sources
set(TYPES_SOURCES
src/types/pose.cpp
README.md
include/eolo/examples/types/pose.h)

# library target
define_module_library(
NAME examples_types
PUBLIC_LINK_LIBS
Eigen3::Eigen
fmt::fmt
PRIVATE_LINK_LIBS ""
SOURCES ${TYPES_SOURCES}
PUBLIC_INCLUDE_PATHS
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE_INCLUDE_PATHS ""
SYSTEM_PRIVATE_INCLUDE_PATHS "")

# library sources
set(TYPES_PROTOBUF_SOURCES
src/types_protobuf/geometry.cpp
src/types_protobuf/pose.cpp
include/eolo/examples/types_protobuf/geometry.h
include/eolo/examples/types_protobuf/pose.h)

# library target
define_module_library(
NAME examples_types_protobuf
PUBLIC_LINK_LIBS
eolo::base
eolo::serdes
eolo::examples_types
eolo::examples_types_proto
Eigen3::Eigen
PRIVATE_LINK_LIBS ""
SOURCES ${TYPES_PROTOBUF_SOURCES}
PUBLIC_INCLUDE_PATHS
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE_INCLUDE_PATHS ""
SYSTEM_PRIVATE_INCLUDE_PATHS "")

# Subprojects
add_subdirectory(tests)
add_subdirectory(examples)
4 changes: 2 additions & 2 deletions modules/types/README.md → modules/examples/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# README: types
# README: examples

## Brief

types provides .. <one line description>
examples provides .. <one line description>

## Detailed description

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@
#=================================================================================================

define_module_example(
NAME example
SOURCES example.cpp
NAME zenoh_pub
SOURCES zenoh_pub.cpp zenoh_program_options.h
PUBLIC_INCLUDE_PATHS
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
PUBLIC_LINK_LIBS "")
PUBLIC_LINK_LIBS eolo::ipc)

define_module_example(
NAME zenoh_sub
SOURCES zenoh_sub.cpp zenoh_program_options.h
PUBLIC_INCLUDE_PATHS
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
PUBLIC_LINK_LIBS eolo::ipc)
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
#include <zenohc.hxx>

#include "eolo/base/exception.h"
#include "eolo/examples/types/pose.h"
#include "eolo/examples/types_protobuf/pose.h"
#include "eolo/ipc/publisher.h"
#include "eolo/ipc/zenoh/publisher.h"
#include "eolo/ipc/zenoh/session.h"
#include "eolo/types/pose.h"
#include "eolo/types_protobuf/pose.h"
#include "zenoh_program_options.h"

auto main(int argc, const char* argv[]) -> int {
Expand All @@ -38,7 +38,7 @@ auto main(int argc, const char* argv[]) -> int {

static constexpr auto LOOP_WAIT = std::chrono::seconds(1);
while (true) {
eolo::types::Pose pose;
eolo::examples::types::Pose pose;
pose.position = Eigen::Vector3d{ 1, 2, 3 };

fmt::println("Publishing Data ('{} : {})", config.topic, pose);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
#include <zenoh.h>
#include <zenohc.hxx>

#include "eolo/examples/types/pose.h"
#include "eolo/examples/types_protobuf/pose.h"
#include "eolo/ipc/subscriber.h"
#include "eolo/ipc/zenoh/session.h"
#include "eolo/ipc/zenoh/subscriber.h"
#include "eolo/types/pose.h"
#include "eolo/types_protobuf/pose.h"
#include "zenoh_program_options.h"

auto main(int argc, const char* argv[]) -> int {
Expand All @@ -32,13 +32,13 @@ auto main(int argc, const char* argv[]) -> int {
auto session = eolo::ipc::zenoh::createSession(config);

auto cb = [topic = config.topic](const eolo::ipc::MessageMetadata& metadata,
const std::shared_ptr<eolo::types::Pose>& pose) {
const std::shared_ptr<eolo::examples::types::Pose>& pose) {
fmt::println(">> Time: {}. Topic {}. From: {}. Counter: {}. Received {}",
std::chrono::system_clock::time_point{
std::chrono::duration_cast<std::chrono::system_clock::duration>(metadata.timestamp) },
topic, metadata.sender_id, metadata.sequence_id, *pose);
};
auto subscriber = eolo::ipc::subscribe<eolo::ipc::zenoh::Subscriber, eolo::types::Pose>(
auto subscriber = eolo::ipc::subscribe<eolo::ipc::zenoh::Subscriber, eolo::examples::types::Pose>(
session, std::move(config), std::move(cb));
(void)subscriber;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include <fmt/format.h>

namespace eolo::types {
namespace eolo::examples::types {

struct Pose {
Eigen::Quaterniond orientation = Eigen::Quaterniond::Identity();
Expand All @@ -24,20 +24,20 @@ struct Pose {
pose.orientation.z());
}

} // namespace eolo::types
} // namespace eolo::examples::types

template <>
struct std::formatter<eolo::types::Pose> final : public std::formatter<std::string_view> {
struct std::formatter<eolo::examples::types::Pose> final : public std::formatter<std::string_view> {
template <typename FormatContext>
auto format(const eolo::types::Pose& pose, FormatContext& ctx) {
auto format(const eolo::examples::types::Pose& pose, FormatContext& ctx) {
return std::format_to(ctx.out(), toString(pose));
}
};

template <>
struct fmt::formatter<eolo::types::Pose> : fmt::formatter<std::string_view> {
struct fmt::formatter<eolo::examples::types::Pose> : fmt::formatter<std::string_view> {
template <typename FormatContext>
auto format(const eolo::types::Pose& pose, FormatContext& ctx) {
auto format(const eolo::examples::types::Pose& pose, FormatContext& ctx) {
return fmt::format_to(ctx.out(), "{}", toString(pose));
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include <Eigen/Dense>

#include "eolo/base/exception.h"
#include "eolo/types/proto/geometry.pb.h"
#include "eolo/examples/types/proto/geometry.pb.h"

namespace eolo::types {
namespace eolo::examples::types {

template <class TypeT, int ROWS, int COLS, class ProtoMatrixT>
inline void toProto(ProtoMatrixT& proto_matrix, const Eigen::Matrix<TypeT, ROWS, COLS>& matrix) {
Expand Down Expand Up @@ -91,4 +91,4 @@ inline void fromProto(const proto::Quaterniond& proto_q, Eigen::Quaterniond& q)
q.w() = proto_q.w();
}

} // namespace eolo::types
} // namespace eolo::examples::types
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

#pragma once

#include "eolo/examples/types/pose.h"
#include "eolo/examples/types/proto/pose.pb.h"
#include "eolo/serdes/protobuf/buffers.h"
#include "eolo/types/pose.h"
#include "eolo/types/proto/pose.pb.h"

namespace eolo::types {
namespace eolo::examples::types {
void toProto(proto::Pose& proto_pose, const Pose& pose);
void fromProto(const proto::Pose& proto_pose, Pose& pose);

void toProtobuf(serdes::protobuf::SerializerBuffer& buffer, const Pose& pose);
void fromProtobuf(serdes::protobuf::DeserializerBuffer& buffer, Pose& pose);

} // namespace eolo::types
} // namespace eolo::examples::types
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#=================================================================================================

set(SOURCES
eolo/types/proto/geometry.proto
eolo/types/proto/pose.proto
eolo/examples/types/proto/geometry.proto
eolo/examples/types/proto/pose.proto
)

define_module_proto_library(NAME types_proto SOURCES ${SOURCES})
define_module_proto_library(NAME examples_types_proto SOURCES ${SOURCES})
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
syntax = "proto3";

package eolo.types.proto;
package eolo.examples.types.proto;

message Vector3d {
double x = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
syntax = "proto3";

package eolo.types.proto;
package eolo.examples.types.proto;

import "eolo/types/proto/geometry.proto";
import "eolo/examples/types/proto/geometry.proto";

message Pose {
Vector3d position = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
// Copyright (C) 2023-2024 EOLO Contributors
//=================================================================================================

#include "eolo/types/pose.h"
#include "eolo/examples/types/pose.h"
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
// Copyright (C) 2023-2024 EOLO Contributors
//=================================================================================================

#include "eolo/types_protobuf/geometry.h"
#include "eolo/examples/types_protobuf/geometry.h"
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// Copyright (C) 2023-2024 EOLO Contributors
//=================================================================================================

#include "eolo/types_protobuf/pose.h"
#include "eolo/examples/types_protobuf/pose.h"

#include "eolo/examples/types_protobuf/geometry.h"
#include "eolo/serdes/protobuf/protobuf.h"
#include "eolo/types_protobuf/geometry.h"

namespace eolo::types {
namespace eolo::examples::types {
void toProto(proto::Pose& proto_pose, const Pose& pose) {
toProto(*proto_pose.mutable_position(), pose.position);
toProto(*proto_pose.mutable_orientation(), pose.orientation);
Expand All @@ -25,4 +25,4 @@ void toProtobuf(serdes::protobuf::SerializerBuffer& buffer, const Pose& pose) {
void fromProtobuf(serdes::protobuf::DeserializerBuffer& buffer, Pose& pose) {
serdes::protobuf::fromProtobuf<proto::Pose>(buffer, pose);
}
} // namespace eolo::types
} // namespace eolo::examples::types
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#=================================================================================================

define_module_test(
NAME tests
SOURCES tests.cpp
NAME types_protobuf_tests
SOURCES types_protobuf_tests.cpp
PUBLIC_INCLUDE_PATHS
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
PUBLIC_LINK_LIBS "")
Loading

0 comments on commit 01e8b1d

Please sign in to comment.