Skip to content

Commit 0dc297c

Browse files
author
Clemens Linnhoff
committed
Merge branch 'OSI-update_and_submodule_reduction' into 'master'
Osi update and submodule reduction See merge request tuda-fzd/perception-sensor-modeling/object-based-generic-perception-object-model!5
2 parents 3b40c14 + e9f9fd4 commit 0dc297c

File tree

27 files changed

+1521
-6
lines changed

27 files changed

+1521
-6
lines changed

Diff for: .gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ build*
44
.editorconfig
55
out/
66
.idea/
7-
.vs/
7+
.vs/
8+
*.bat
9+
*.sh

Diff for: .gitmodules

-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
[submodule "lib/open-simulation-interface"]
55
path = lib/open-simulation-interface
66
url = https://github.com/OpenSimulationInterface/open-simulation-interface.git
7-
[submodule "src/model/strategies/transformation-functions"]
8-
path = src/model/strategies/transformation-functions
9-
url = https://gitlab.com/tuda-fzd/perception-sensor-modeling/utils/transformation-functions.git
107
[submodule "lib/fmi2"]
118
path = lib/fmi2
129
url = https://github.com/modelica/fmi-standard.git

Diff for: lib/open-simulation-interface

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
project(CsvOutputDetectedObjects)
3+
4+
set(CSV_DETECTEDOBJECTS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
5+
set(CSV_DETECTEDOBJECTS_TARGET_DIR ${CMAKE_CURRENT_BINARY_DIR}/src)
6+
if (WIN32)
7+
set(CSV_PATH C:/TEMP)
8+
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
9+
set(CSV_PATH /tmp)
10+
endif()
11+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/csvoutputdetectedobjects/set_csv_file_path_detectedobjects.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/include/csvoutputdetectedobjects/set_csv_file_path_detectedobjects.cpp)
12+
13+
# TODO MODIFY THE FOLLOWING THREE LINES AS NEEDED
14+
set(STRATEGY_ENTRY_POINT CsvOutputDetectedObjects)
15+
set(STRATEGY_SOURCES ${CSV_DETECTEDOBJECTS_SOURCE_DIR}/CsvOutputDetectedObjects.cpp)
16+
set(STRATEGY_EXTRA_PUBLIC_LIBS_OR_TARGETS "")
17+
set(STRATEGY_EXTRA_PRIVATE_LIBS_OR_TARGETS "")
18+
set(STRATEGY_EXTRA_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/include)
19+
#set(STRATEGY_PROFILE_EXTENSION ${PROFILES})
20+
21+
# no need to modify commands below this line
22+
set(CMAKE_CXX_STANDARD 17)
23+
24+
if(NOT COMMAND add_fmu_csv_output_strategy)
25+
message(FATAL_ERROR "This project directory has to be included by OSI FMU platform, it can't be build out of that context!")
26+
endif()
27+
28+
add_fmu_csv_output_strategy(${PROJECT_NAME} ${STRATEGY_ENTRY_POINT})
29+
if(STRATEGY_PROFILE_EXTENSION)
30+
add_profile_part(${STRATEGY_PROFILE_EXTENSION})
31+
endif()
32+
33+
add_library(${PROJECT_NAME} STATIC ${STRATEGY_SOURCES})
34+
target_link_libraries(${PROJECT_NAME} PRIVATE ${STRATEGY_EXTRA_PRIVATE_LIBS_OR_TARGETS} PUBLIC model::strategy open_simulation_interface_obj ${STRATEGY_EXTRA_PUBLIC_LIBS_OR_TARGETS})
35+
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${STRATEGY_EXTRA_INCLUDE_DIRECTORIES})
36+
set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON)
37+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# CSV Output Strategy for Detected Objects
2+
3+
This strategy writes OSI3::DetectedMovingObjects in a csv file.
4+
Path for the file is set via CMakeLists.
5+
6+
## Usage
7+
You need to add the name of the strategy in a new line in the *csv_output_sequence.conf* file in the *src/model/strategies/* folder.
8+
9+
In order for the strategy to be called during simulation, the FMI parameter *switch_for_csv_output* needs to be set to *1* and be passed to the framework or model fmu.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//
2+
// Copyright Institute of Automotive Engineering
3+
// of Technical University of Darmstadt 2020.
4+
// Licensed under the EUPL-1.2-or-later
5+
//
6+
// This work covered by the EUPL can be used/merged and distributed
7+
// in other works covered by GPL-2.0, GPL-3.0, LGPL, AGPL, CeCILL,
8+
// OSL, EPL, MPL and other licences listed as compatible in the EUPL
9+
// Appendix. This applies to the other (combined) work, while the
10+
// original project stays covered by the EUPL without re-licensing.
11+
//
12+
// Alternatively, the contents of this file may be used under the
13+
// terms of the Mozilla Public License, v. 2.0. If a copy of the MPL
14+
// was not distributed with this file, you can obtain one at
15+
// http://mozilla.org/MPL/2.0/.
16+
//
17+
18+
#ifndef CSV_OUTPUT_DETECTEDOBJECTS_STRATEGY_HPP
19+
#define CSV_OUTPUT_DETECTEDOBJECTS_STRATEGY_HPP
20+
21+
#include <model/include/strategy.hpp>
22+
#include <string>
23+
24+
using namespace osi3;
25+
26+
namespace model {
27+
28+
class CsvOutputDetectedObjects : public Strategy {
29+
30+
using Strategy::Strategy;
31+
32+
void apply(SensorData &) override;
33+
34+
std::string file_path_detectedobjects;
35+
bool first_call = true;
36+
37+
public:
38+
39+
private:
40+
static void write_first_line_to_CSV(const std::string& path);
41+
static void write_data_to_CSV(const std::string &path, double timestamp, size_t tracking_id, double x, double y, double z, double roll, double pitch, double yaw, double width, double length,
42+
double height, bool is_moving, double existence_probability);
43+
};
44+
45+
}
46+
47+
#endif //CSV_OUTPUT_DETECTEDOBJECTS_STRATEGY_HPP
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
time_t curr_time;
2+
struct tm *detl;
3+
char buf[80];
4+
time( &curr_time );
5+
detl = localtime( &curr_time );
6+
// strftime(buf, 20, "%x - %I:%M%p", detl);
7+
strftime(buf, 20, "%Y-%m-%d_%H-%M-%S", detl);
8+
9+
std::string start_time = std::string(buf);
10+
11+
std::string path_string = "@CSV_PATH@/";
12+
size_t pos;
13+
14+
path_string = path_string + "@MODEL_NAME@" + "_" + start_time;
15+
std::string filename = "DetectedObjects.csv";
16+
17+
#if defined(_WIN32)
18+
while ((pos = path_string.find("/")) != std::string::npos) {
19+
path_string.replace(pos, 1, "\\");
20+
}
21+
_mkdir(path_string.c_str());
22+
file_path_detectedobjects = path_string + "\\" + filename;
23+
#else
24+
mkdir(path_string.c_str(), 0777);
25+
file_path_detectedobjects = path_string + "/" + filename;
26+
#endif
27+
28+
29+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
//
2+
// Copyright Institute of Automotive Engineering
3+
// of Technical University of Darmstadt 2020.
4+
// Licensed under the EUPL-1.2-or-later
5+
//
6+
// This work covered by the EUPL can be used/merged and distributed
7+
// in other works covered by GPL-2.0, GPL-3.0, LGPL, AGPL, CeCILL,
8+
// OSL, EPL, MPL and other licences listed as compatible in the EUPL
9+
// Appendix. This applies to the other (combined) work, while the
10+
// original project stays covered by the EUPL without re-licensing.
11+
//
12+
// Alternatively, the contents of this file may be used under the
13+
// terms of the Mozilla Public License, v. 2.0. If a copy of the MPL
14+
// was not distributed with this file, you can obtain one at
15+
// http://mozilla.org/MPL/2.0/.
16+
//
17+
18+
#ifndef _USE_MATH_DEFINES
19+
#define _USE_MATH_DEFINES
20+
#endif
21+
22+
#include "csvoutputdetectedobjects/CsvOutputDetectedObjects.hpp"
23+
#include <fstream>
24+
#include <iostream>
25+
#include <ctime>
26+
27+
#ifdef _WIN32
28+
#include <math.h>
29+
#include <direct.h>
30+
#else
31+
#include <cmath>
32+
#include <sys/stat.h>
33+
#endif
34+
35+
using namespace model;
36+
using namespace osi3;
37+
38+
void model::CsvOutputDetectedObjects::apply(SensorData &sensor_data) {
39+
log("Starting .csv output for detected objects");
40+
41+
if ((sensor_data.sensor_view_size()==0) || (!sensor_data.sensor_view(0).has_global_ground_truth())) {
42+
log("No sensor view or global ground truth");
43+
return;
44+
}
45+
46+
const auto &ground_truth = sensor_data.sensor_view(0).global_ground_truth();
47+
48+
auto time_nanos = ground_truth.timestamp().nanos();
49+
auto time_seconds = ground_truth.timestamp().seconds();
50+
double timestamp = (double) time_seconds + (double) time_nanos / 1000000000;
51+
52+
auto no_of_moving_objects = sensor_data.moving_object_size();
53+
auto no_of_stationary_objects = sensor_data.stationary_object_size();
54+
auto no_of_objects = no_of_moving_objects + no_of_stationary_objects;
55+
56+
/// Add tracking_id, x, y, z, roll, pitch, yaw, width, length, height, is_moving, existence_probability to csv
57+
if (no_of_objects > 0) {
58+
59+
/// Write header line of .csv on first call
60+
if (first_call){
61+
#include <csvoutputdetectedobjects/set_csv_file_path_detectedobjects.cpp>
62+
write_first_line_to_CSV(file_path_detectedobjects);
63+
first_call = false;
64+
}
65+
66+
for (const auto &moving_object : sensor_data.moving_object()) {
67+
write_data_to_CSV(file_path_detectedobjects,
68+
timestamp,
69+
moving_object.header().tracking_id().value(),
70+
std::round(moving_object.base().position().x() * 1000) / 1000,
71+
std::round(moving_object.base().position().y() * 1000) / 1000,
72+
std::round(moving_object.base().position().z() * 1000) / 1000,
73+
std::round(moving_object.base().orientation().roll() * 1000) / 1000,
74+
std::round(moving_object.base().orientation().pitch() * 1000) / 1000,
75+
std::round(moving_object.base().orientation().yaw() * 1000) / 1000,
76+
std::round(moving_object.base().dimension().width() * 1000) / 1000,
77+
std::round(moving_object.base().dimension().length() * 1000) / 1000,
78+
std::round(moving_object.base().dimension().height() * 1000) / 1000,
79+
true,
80+
std::round(moving_object.header().existence_probability() * 1000) / 1000);
81+
}
82+
for (const auto &stationary_object : sensor_data.stationary_object()) {
83+
write_data_to_CSV(file_path_detectedobjects,
84+
timestamp,
85+
stationary_object.header().tracking_id().value(),
86+
std::round(stationary_object.base().position().x() * 1000) / 1000,
87+
std::round(stationary_object.base().position().y() * 1000) / 1000,
88+
std::round(stationary_object.base().position().z() * 1000) / 1000,
89+
std::round(stationary_object.base().orientation().roll() * 1000) / 1000,
90+
std::round(stationary_object.base().orientation().pitch() * 1000) / 1000,
91+
std::round(stationary_object.base().orientation().yaw() * 1000) / 1000,
92+
std::round(stationary_object.base().dimension().width() * 1000) / 1000,
93+
std::round(stationary_object.base().dimension().length() * 1000) / 1000,
94+
std::round(stationary_object.base().dimension().height() * 1000) / 1000,
95+
false,
96+
std::round(stationary_object.header().existence_probability() * 1000) / 1000);
97+
}
98+
} else {
99+
log("No detected objects for .csv output at timestamp " + std::to_string(timestamp));
100+
return;
101+
}
102+
}
103+
104+
void CsvOutputDetectedObjects::write_first_line_to_CSV(const std::string& path) {
105+
std::fstream my_file;
106+
my_file.open(path, std::ios::app);
107+
my_file << "timestamp_in_s, tracking_id, x_in_m, y_in_m, z_in_m, roll_in_deg, pitch_in_deg, yaw_in_deg, width_in_m, length_in_m, height_in_m, is_moving, existence_probability" << std::endl;
108+
my_file.close();
109+
}
110+
111+
void
112+
CsvOutputDetectedObjects::write_data_to_CSV(const std::string &path, double timestamp, size_t tracking_id, double x, double y, double z, double roll, double pitch, double yaw, double width, double length,
113+
double height, bool is_moving, double existence_probability) {
114+
std::fstream my_file;
115+
my_file.open(path, std::ios::app);
116+
my_file << timestamp << ", " << tracking_id << ", " << x << ", " << y << ", " << z << ", " << roll << ", " << pitch << ", " << yaw << ", " << width << ", " << length << ", " << height << ", " << (is_moving ? "true": "false") << ", " << existence_probability << std::endl;
117+
my_file.close();
118+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
project(CsvOutputGTObjects)
3+
4+
set(CSV_GTOBJECTS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
5+
set(CSV_GTOBJECTS_TARGET_DIR ${CMAKE_CURRENT_BINARY_DIR}/src)
6+
if (WIN32)
7+
set(CSV_PATH C:/TEMP)
8+
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
9+
set(CSV_PATH /tmp)
10+
endif()
11+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/csvoutputgtobjects/set_csv_file_path_gtobjects.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/include/csvoutputgtobjects/set_csv_file_path_gtobjects.cpp)
12+
13+
# TODO MODIFY THE FOLLOWING THREE LINES AS NEEDED
14+
set(STRATEGY_ENTRY_POINT CsvOutputGTObjects)
15+
set(STRATEGY_SOURCES ${CSV_GTOBJECTS_SOURCE_DIR}/CsvOutputGTObjects.cpp ../transformation-functions/TransformationFunctions.cpp)
16+
set(STRATEGY_EXTRA_PUBLIC_LIBS_OR_TARGETS "")
17+
set(STRATEGY_EXTRA_PRIVATE_LIBS_OR_TARGETS "")
18+
set(STRATEGY_EXTRA_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/include)
19+
#set(STRATEGY_PROFILE_EXTENSION ${PROFILES})
20+
21+
# no need to modify commands below this line
22+
set(CMAKE_CXX_STANDARD 17)
23+
24+
if(NOT COMMAND add_fmu_csv_output_strategy)
25+
message(FATAL_ERROR "This project directory has to be included by OSI FMU platform, it can't be build out of that context!")
26+
endif()
27+
28+
add_fmu_csv_output_strategy(${PROJECT_NAME} ${STRATEGY_ENTRY_POINT})
29+
if(STRATEGY_PROFILE_EXTENSION)
30+
add_profile_part(${STRATEGY_PROFILE_EXTENSION})
31+
endif()
32+
33+
34+
add_library(${PROJECT_NAME} STATIC ${STRATEGY_SOURCES})
35+
target_link_libraries(${PROJECT_NAME} PRIVATE ${STRATEGY_EXTRA_PRIVATE_LIBS_OR_TARGETS} PUBLIC model::strategy open_simulation_interface_obj ${STRATEGY_EXTRA_PUBLIC_LIBS_OR_TARGETS})
36+
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${STRATEGY_EXTRA_INCLUDE_DIRECTORIES})
37+
set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON)
38+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Ground Truth Objects to .csv Output Strategy
2+
3+
This strategy writes ground truth objects in a csv file.
4+
Path for the file is set via CMakeLists.
5+
6+
## Usage
7+
You need to add the name of the strategy in a new line in the *csv_output_sequence.conf* file in the *src/model/strategies/* folder.
8+
9+
In order for the strategy to be called during simulation, the FMI parameter *switch_for_csv_output* needs to be set to *1* and be passed to the framework or model fmu.
10+
11+
NOTE:
12+
This strategy needs transformation-functions from ../transformation-functions.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//
2+
// Copyright Institute of Automotive Engineering
3+
// of Technical University of Darmstadt 2020.
4+
// Licensed under the EUPL-1.2-or-later
5+
//
6+
// This work covered by the EUPL can be used/merged and distributed
7+
// in other works covered by GPL-2.0, GPL-3.0, LGPL, AGPL, CeCILL,
8+
// OSL, EPL, MPL and other licences listed as compatible in the EUPL
9+
// Appendix. This applies to the other (combined) work, while the
10+
// original project stays covered by the EUPL without re-licensing.
11+
//
12+
// Alternatively, the contents of this file may be used under the
13+
// terms of the Mozilla Public License, v. 2.0. If a copy of the MPL
14+
// was not distributed with this file, you can obtain one at
15+
// http://mozilla.org/MPL/2.0/.
16+
//
17+
18+
#ifndef CSV_OUTPUT_GTOBJECTS_STRATEGY_HPP
19+
#define CSV_OUTPUT_GTOBJECTS_STRATEGY_HPP
20+
21+
#include <model/include/strategy.hpp>
22+
#include <string>
23+
24+
using namespace osi3;
25+
26+
namespace model {
27+
28+
class CsvOutputGTObjects : public Strategy {
29+
30+
using Strategy::Strategy;
31+
32+
void apply(SensorData &) override;
33+
34+
std::string file_path_gtobjects;
35+
bool first_call = true;
36+
37+
public:
38+
39+
private:
40+
41+
struct GT_object {
42+
size_t id = 0;
43+
float x = 0.0;
44+
float y = 0.0;
45+
float z = 0.0;
46+
float roll = 0.0;
47+
float pitch = 0.0;
48+
float yaw = 0.0;
49+
float width = 0.0;
50+
float length = 0.0;
51+
float height = 0.0;
52+
bool is_moving = false;
53+
};
54+
55+
static void write_first_line_to_CSV(const std::string& path);
56+
static void write_data_to_CSV(const std::string& path, double timestamp, size_t object_idx, float x, float y, float z, float roll, float pitch, float yaw, float width, float length, float height, bool is_moving);
57+
};
58+
59+
}
60+
61+
#endif //CSV_OUTPUT_GTOBJECTS_STRATEGY_HPP

0 commit comments

Comments
 (0)