Skip to content

Commit 1eb0a15

Browse files
tobifalkcassava
authored andcommitted
osi: Initial commit of message handler and utils
1 parent 1d6311a commit 1eb0a15

23 files changed

+966
-111
lines changed

optional/osi/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/

optional/osi/CMakeLists.txt

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
2+
3+
project(cloe-osi LANGUAGES CXX)
4+
5+
include(GNUInstallDirs)
6+
include(TargetLinting)
7+
8+
# Module -------------------------------------------------------------
9+
find_package(cloe-models REQUIRED)
10+
find_package(cloe-runtime REQUIRED)
11+
find_package(Eigen3 REQUIRED)
12+
find_package(Boost COMPONENTS headers REQUIRED)
13+
find_package(open-simulation-interface REQUIRED)
14+
15+
message(STATUS "-> Building cloe-osi library.")
16+
file(GLOB cloe-osi_PUBLIC_HEADERS "include/**/*.hpp")
17+
add_library(cloe-osi
18+
# find src -type f -name "*.cpp" \! -name "*_test.cpp"
19+
src/osi/utility/osi_ground_truth.cpp
20+
src/osi/utility/osi_omni_sensor.cpp
21+
src/osi/utility/osi_transceiver_tcp.cpp
22+
src/osi/utility/osi_utils.cpp
23+
24+
# For IDE integration
25+
${cloe-osi_PUBLIC_HEADERS}
26+
)
27+
add_library(cloe::osi ALIAS cloe-osi)
28+
set_target_properties(cloe-osi PROPERTIES
29+
CXX_STANDARD 17
30+
CXX_STANDARD_REQUIRED ON
31+
VERSION ${CLOE_PROJECT_VERSION}
32+
)
33+
target_include_directories(cloe-osi
34+
PUBLIC
35+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
36+
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
37+
)
38+
target_link_libraries(cloe-osi
39+
PUBLIC
40+
cloe::models
41+
cloe::runtime
42+
Boost::headers
43+
Eigen3::Eigen
44+
open-simulation-interface::open-simulation-interface
45+
)
46+
47+
# Testing -------------------------------------------------------------
48+
include(CTest)
49+
if(BUILD_TESTING)
50+
find_package(GTest REQUIRED)
51+
include(GoogleTest)
52+
53+
add_executable(test-osi
54+
# find src -type f -name "*_test.cpp"
55+
src/osi/component/osi_sensor_test.cpp
56+
src/osi/utility/osi_test.cpp
57+
)
58+
set_target_properties(test-osi PROPERTIES
59+
CXX_STANDARD 17
60+
CXX_STANDARD_REQUIRED ON
61+
)
62+
target_link_libraries(test-osi
63+
PRIVATE
64+
GTest::gtest
65+
GTest::gtest_main
66+
Boost::boost
67+
cloe::runtime
68+
cloe::models
69+
cloe::osi
70+
open-simulation-interface::open-simulation-interface
71+
)
72+
gtest_add_tests(TARGET test-osi)
73+
endif()
74+
75+
# Installation -------------------------------------------------------
76+
install(TARGETS cloe-osi
77+
LIBRARY
78+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
79+
ARCHIVE
80+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
81+
)
82+
install(
83+
DIRECTORY include/
84+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
85+
)

optional/osi/Makefile

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
PROJECT_ROOT := ../..
2+
include ${PROJECT_ROOT}/Makefile.package
3+
4+
# -------------------------------------------------
5+
6+
ALL_VENDOR := $(wildcard vendor/*)
7+
.PHONY: ${ALL_VENDOR}
8+
9+
WITHOUT_VENDOR :=
10+
UNSELECT_VENDOR := ${WITHOUT_VENDOR}
11+
WITH_VENDOR :=
12+
SELECT_VENDOR := $(call uniq, $(filter-out ${UNSELECT_VENDOR}, ${ALL_VENDOR}) ${WITH_VENDOR})
13+
14+
vendor/open-simulation-interface-3.3.1: vendor/protoc
15+
16+
REGEX_TARGET := 's/(-vendor|-select)?-each//'
17+
${SELECT_VENDOR}:
18+
${MAKE} -C $@ $(shell echo ${MAKECMDGOALS} | sed -re ${REGEX_TARGET})
19+
20+
# Usage: $(call _make_target_rule, TARGET-NAME, MAKE-TARGET, HELP-DESCRIPTION, MAKE-ARGUMENTS)
21+
define _make_target_rule
22+
${1}:
23+
$(call print_header, "Proceeding to $(call unquote, ${3})")
24+
${MAKE} ${SUBMAKEFLAGS} PROJECT_ROOT=$(realpath ${PROJECT_ROOT}) ${4} ${2}
25+
endef
26+
27+
# Usage: $(call _make_target_rules, TARGET-NAME, HELP-DESCRIPTION, HELP-CATEGORY, PACKAGE-DIRS)
28+
define _make_target_rules
29+
help::
30+
$(call print_help_target, ${1}, ${2}, ${3})
31+
$(call _make_target_rule,${1},${1}-each,${2})
32+
${1}-each: ${4}
33+
endef
34+
35+
# Usage: $(call make_vendor_target, TARGET-NAME, HELP-DESCRIPTION, HELP-CATEGORY)
36+
define make_vendor_target
37+
$(eval $(call _make_target_rules,${1},${2},${3},${SELECT_VENDOR}))
38+
endef
39+
40+
help::
41+
$(call print_help_section, "Available vendor targets")
42+
43+
$(call make_vendor_target, export-vendor, "export all vendor packages", "[conan-cache]")
44+
$(call make_vendor_target, package-vendor, "create all vendor packages", "[conan-cache]")
45+
$(call make_vendor_target, download-vendor, "download or build vendor packages", "[conan-cache]")

optional/osi/conanfile.py

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# mypy: ignore-errors
2+
# pylint: skip-file
3+
4+
from pathlib import Path
5+
from conan import ConanFile
6+
from conan.tools import cmake, files, scm
7+
8+
9+
class CloeOsi(ConanFile):
10+
name = "cloe-osi"
11+
url = "https://github.com/eclipse/cloe"
12+
description = "OSI sensor component and utility functions for data conversion to Cloe"
13+
license = "Apache-2.0"
14+
settings = "os", "compiler", "build_type", "arch"
15+
options = {
16+
"shared": [True, False],
17+
"fPIC": [True, False],
18+
"pedantic": [True, False],
19+
}
20+
default_options = {
21+
"shared": True,
22+
"fPIC": True,
23+
"pedantic": True,
24+
}
25+
generators = "CMakeDeps", "VirtualRunEnv"
26+
no_copy_source = True
27+
exports_sources = [
28+
"include/*",
29+
"src/*",
30+
"CMakeLists.txt",
31+
]
32+
33+
def set_version(self):
34+
version_file = Path(self.recipe_folder) / "../../VERSION"
35+
if version_file.exists():
36+
self.version = files.load(self, version_file).strip()
37+
else:
38+
git = scm.Git(self, self.recipe_folder)
39+
self.version = git.run("describe --dirty=-dirty")[1:]
40+
41+
def requirements(self):
42+
self.requires(f"cloe-models/{self.version}@cloe/develop")
43+
self.requires(f"cloe-runtime/{self.version}@cloe/develop")
44+
self.requires("open-simulation-interface/3.3.1@cloe/stable")
45+
self.requires("boost/[>=1.65.1]")
46+
self.requires("eigen/3.4.0")
47+
48+
def configure(self):
49+
self.options["open-simulation-interface"].shared = self.options.shared
50+
self.options["open-simulation-interface"].fPIC = True
51+
52+
def build_requirements(self):
53+
self.test_requires("gtest/1.13.0")
54+
55+
def layout(self):
56+
cmake.cmake_layout(self)
57+
58+
def generate(self):
59+
tc = cmake.CMakeToolchain(self)
60+
tc.cache_variables["CMAKE_EXPORT_COMPILE_COMMANDS"] = True
61+
tc.cache_variables["CLOE_PROJECT_VERSION"] = self.version
62+
tc.cache_variables["TargetLintingExtended"] = self.options.pedantic
63+
tc.generate()
64+
65+
def build(self):
66+
cm = cmake.CMake(self)
67+
if self.should_configure:
68+
cm.configure()
69+
if self.should_build:
70+
cm.build()
71+
if self.should_test:
72+
cm.test()
73+
74+
def package(self):
75+
cm = cmake.CMake(self)
76+
if self.should_install:
77+
cm.install()
78+
79+
def package_id(self):
80+
self.info.requires["boost"].full_package_mode()
81+
self.info.requires["open-simulation-interface"].full_package_mode()
82+
del self.info.options.pedantic
83+
84+
def package_info(self):
85+
self.cpp_info.set_property("cmake_find_mode", "both")
86+
self.cpp_info.set_property("cmake_file_name", "cloe-osi")
87+
self.cpp_info.set_property("cmake_target_name", "cloe::osi")
88+
self.cpp_info.set_property("pkg_config_name", "cloe-osi")
89+
90+
# Make sure we can find the library, both in editable mode and in the
91+
# normal package mode:
92+
self.cpp_info.libdirs = [f"lib"]
93+
if not self.in_local_cache:
94+
self.cpp_info.libs = ["cloe-osi"]
95+
else:
96+
self.cpp_info.libs = files.collect_libs(self)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Copyright 2022 Robert Bosch GmbH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
*/
18+
/**
19+
* \file cloe/component/osi_sensor.hpp
20+
* \see cloe/component/osi.hpp
21+
*/
22+
23+
#pragma once
24+
#ifndef CLOE_COMPONENT_OSI_SENSOR_HPP_
25+
#define CLOE_COMPONENT_OSI_SENSOR_HPP_
26+
27+
#include <memory> // for shared_ptr
28+
29+
#include "osi_groundtruth.pb.h" // for GroundTruth
30+
#include "osi_sensordata.pb.h" // for SensorData
31+
#include "osi_sensorview.pb.h" // for SensorView
32+
33+
#include <cloe/component.hpp> // for Component, Json
34+
35+
namespace cloe_osi {
36+
37+
class OsiSensor : public cloe::Component {
38+
public:
39+
using cloe::Component::Component;
40+
OsiSensor() : Component("osi_sensor") {}
41+
virtual ~OsiSensor() noexcept = default;
42+
43+
/**
44+
* Return OSI data, if available.
45+
*/
46+
47+
virtual std::shared_ptr<osi3::GroundTruth> ground_truth() = 0;
48+
49+
virtual std::shared_ptr<osi3::SensorView> sensor_view() = 0;
50+
51+
virtual std::shared_ptr<osi3::SensorData> sensor_data() = 0;
52+
53+
/**
54+
* Writes JSON representation into j.
55+
*/
56+
cloe::Json active_state() const override {
57+
return cloe::Json{
58+
/*{"ground_truth", this->ground_truth()},
59+
{"sensor_view", this->sensor_view()},
60+
{"sensor_data", this->sensor_data()},*/
61+
};
62+
}
63+
};
64+
65+
class NopOsiSensor : public OsiSensor {
66+
public:
67+
using OsiSensor::OsiSensor;
68+
NopOsiSensor() : OsiSensor("nop_osi_sensor") {}
69+
virtual ~NopOsiSensor() noexcept = default;
70+
71+
std::shared_ptr<osi3::GroundTruth> ground_truth() override { return ground_truth_; }
72+
73+
std::shared_ptr<osi3::SensorView> sensor_view() override { return sensor_view_; }
74+
75+
std::shared_ptr<osi3::SensorData> sensor_data() override { return sensor_data_; }
76+
77+
void set_ground_truth(const osi3::GroundTruth& gt) {
78+
ground_truth_ = std::make_shared<osi3::GroundTruth>(gt);
79+
}
80+
81+
void set_sensor_view(const osi3::SensorView& view) {
82+
sensor_view_ = std::make_shared<osi3::SensorView>(view);
83+
}
84+
85+
void set_sensor_data(const osi3::SensorData& data) {
86+
sensor_data_ = std::make_shared<osi3::SensorData>(data);
87+
}
88+
89+
void reset() override {
90+
OsiSensor::reset();
91+
ground_truth_.reset();
92+
sensor_view_.reset();
93+
sensor_data_.reset();
94+
}
95+
96+
protected:
97+
std::shared_ptr<osi3::GroundTruth> ground_truth_{nullptr};
98+
std::shared_ptr<osi3::SensorView> sensor_view_{nullptr};
99+
std::shared_ptr<osi3::SensorData> sensor_data_{nullptr};
100+
};
101+
102+
} // namespace cloe_osi
103+
104+
#endif // CLOE_COMPONENT_OSI_SENSOR_HPP_

optional/vtd/src/osi_ground_truth.hpp renamed to optional/osi/include/osi/utility/osi_ground_truth.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
#include <cloe/simulator.hpp> // for ModelError
3131

32-
#include "osi_utils.hpp" // for osi_require, ..
32+
#include "osi/utility/osi_utils.hpp" // for osi_require, ..
3333

3434
namespace osii {
3535

@@ -47,7 +47,7 @@ class OsiGroundTruth {
4747
* Store address of the GroundTruth object belonging to the OSI message
4848
* that is to be processed.
4949
*/
50-
void set(const osi3::GroundTruth& osi_gt) { gt_ptr_ = &osi_gt; }
50+
void set(const osi3::GroundTruth& osi_gt);
5151

5252
const osi3::GroundTruth& get_gt() const {
5353
if (!gt_ptr_) error();

0 commit comments

Comments
 (0)