Skip to content

Commit d153144

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/modular-osmp-framework!5
2 parents e6a407f + 46c0c23 commit d153144

18 files changed

+1016
-14
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+
*.sh
9+
*.bat

Diff for: .gitmodules

-9
Original file line numberDiff line numberDiff line change
@@ -4,15 +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/transformation-functions.git
10-
[submodule "src/model/strategies/csv-output-gtobjects-strategy"]
11-
path = src/model/strategies/csv-output-gtobjects-strategy
12-
url = https://gitlab.com/tuda-fzd/perception-sensor-modeling/output-strategies/csv-output-gtobjects-strategy.git
13-
[submodule "src/model/strategies/ros-output-gtobjects-strategy"]
14-
path = src/model/strategies/ros-output-gtobjects-strategy
15-
url = https://gitlab.com/tuda-fzd/perception-sensor-modeling/output-strategies/ros-output-gtobjects-strategy.git
167
[submodule "lib/fmi2"]
178
path = lib/fmi2
189
url = https://github.com/modelica/fmi-standard.git

Diff for: lib/open-simulation-interface

Diff for: src/model/strategies/csv-output-gtobjects-strategy

-1
This file was deleted.
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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 = "GTObjects.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_gtobjects = path_string + "\\" + filename;
23+
#else
24+
mkdir(path_string.c_str(), 0777);
25+
file_path_gtobjects = path_string + "/" + filename;
26+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
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 "csvoutputgtobjects/CsvOutputGTObjects.hpp"
23+
#include "../../transformation-functions/TransformationFunctions.hpp"
24+
#include <fstream>
25+
#include <iostream>
26+
#include <vector>
27+
#include <ctime>
28+
29+
#ifdef _WIN32
30+
#include <math.h>
31+
#include <direct.h>
32+
#else
33+
#include <cmath>
34+
#include <sys/stat.h>
35+
#endif
36+
37+
using namespace model;
38+
using namespace osi3;
39+
40+
static bool first_call = true;
41+
42+
void model::CsvOutputGTObjects::apply(SensorData &sensor_data) {
43+
log("Starting .csv output for GT objects");
44+
45+
if (sensor_data.sensor_view_size() == 0) {
46+
log("No sensor view received for .csv output");
47+
return;
48+
}
49+
50+
TF::EgoData ego_data;
51+
if (!TF::get_ego_info(ego_data, sensor_data.sensor_view(0))) {
52+
log("Ego vehicle has no base, no id, or is not contained in GT moving objects.");
53+
return;
54+
}
55+
56+
auto time_nanos = sensor_data.sensor_view(0).global_ground_truth().timestamp().nanos();
57+
auto time_seconds = sensor_data.sensor_view(0).global_ground_truth().timestamp().seconds();
58+
double timestamp = (double)time_seconds + (double) time_nanos / 1000000000;
59+
60+
if (!sensor_data.sensor_view(0).has_global_ground_truth()) {
61+
log("No GT for .csv output at timestamp " + std::to_string(timestamp));
62+
return;
63+
}
64+
65+
if ((sensor_data.sensor_view(0).global_ground_truth().moving_object_size() == 0) &&
66+
(sensor_data.sensor_view(0).global_ground_truth().stationary_object_size() == 0)) {
67+
log("No objects in GT for .csv output at timestamp " + std::to_string(timestamp));
68+
return;
69+
}
70+
71+
/// Write header line of .csv on first call
72+
if (first_call) {
73+
#include <csvoutputgtobjects/set_csv_file_path_gtobjects.cpp>
74+
write_first_line_to_CSV(file_path_gtobjects);
75+
first_call = false;
76+
}
77+
78+
auto no_of_moving_objects = sensor_data.sensor_view(0).global_ground_truth().moving_object_size();
79+
auto no_of_stationary_objects = sensor_data.sensor_view(0).global_ground_truth().stationary_object_size();
80+
81+
/// Start a vector for gt_objects with (gt_id, x, y, z, roll, pitch, yaw, width, length, height, is_moving)
82+
std::vector<GT_object> gt_objects;
83+
gt_objects.reserve(no_of_moving_objects + no_of_stationary_objects);
84+
85+
/// Collect moving objects
86+
for (const auto &gt_moving_object : sensor_data.sensor_view(0).global_ground_truth().moving_object()) {
87+
if (gt_moving_object.id().value() == sensor_data.sensor_view(0).global_ground_truth().host_vehicle_id().value())
88+
continue;
89+
90+
Vector3d relative_position_ego_coordinate_system = TF::transform_position_from_world_to_ego_coordinates(gt_moving_object.base().position(), ego_data);
91+
Orientation3d relative_orientation = TF::calc_relative_orientation_to_local(gt_moving_object.base().orientation(), ego_data.ego_base.orientation());
92+
GT_object actual_gt_object;
93+
actual_gt_object.id = gt_moving_object.id().value();
94+
actual_gt_object.x = std::round(float(relative_position_ego_coordinate_system.x()) * 1000) / 1000;
95+
actual_gt_object.y = std::round(float(relative_position_ego_coordinate_system.y()) * 1000) / 1000;
96+
actual_gt_object.z = std::round(float(relative_position_ego_coordinate_system.z()) * 1000) / 1000;
97+
actual_gt_object.roll = (float)std::round(float(relative_orientation.roll()) * 180 / M_PI * 1000) / 1000;
98+
actual_gt_object.pitch = (float)std::round(float(relative_orientation.pitch()) * 180 / M_PI * 1000) / 1000;
99+
actual_gt_object.yaw = (float)std::round(float(relative_orientation.yaw()) * 180 / M_PI * 1000) / 1000;
100+
actual_gt_object.width = float(gt_moving_object.base().dimension().width());
101+
actual_gt_object.length = float(gt_moving_object.base().dimension().length());
102+
actual_gt_object.height = float(gt_moving_object.base().dimension().height());
103+
actual_gt_object.is_moving = true;
104+
gt_objects.emplace_back(actual_gt_object);
105+
}
106+
107+
/// Collect stationary objects
108+
for (const auto &gt_stationary_object : sensor_data.sensor_view(0).global_ground_truth().stationary_object()) {
109+
Vector3d relative_position_ego_coordinate_system = TF::transform_position_from_world_to_ego_coordinates(
110+
gt_stationary_object.base().position(), ego_data);
111+
Orientation3d relative_orientation = TF::calc_relative_orientation_to_local(
112+
gt_stationary_object.base().orientation(),
113+
ego_data.ego_base.orientation());
114+
GT_object actual_gt_object;
115+
actual_gt_object.id = gt_stationary_object.id().value();
116+
actual_gt_object.x = std::round(float(relative_position_ego_coordinate_system.x()) * 1000) / 1000;
117+
actual_gt_object.y = std::round(float(relative_position_ego_coordinate_system.y()) * 1000) / 1000;
118+
actual_gt_object.z = std::round(float(relative_position_ego_coordinate_system.z()) * 1000) / 1000;
119+
actual_gt_object.roll = (float)std::round(float(relative_orientation.roll()) * 180 / M_PI * 1000) / 1000;
120+
actual_gt_object.pitch = (float)std::round(float(relative_orientation.pitch()) * 180 / M_PI * 1000) / 1000;
121+
actual_gt_object.yaw = (float)std::round(float(relative_orientation.yaw()) * 180 / M_PI * 1000) / 1000;
122+
actual_gt_object.width = float(gt_stationary_object.base().dimension().width());
123+
actual_gt_object.length = float(gt_stationary_object.base().dimension().length());
124+
actual_gt_object.height = float(gt_stationary_object.base().dimension().height());
125+
actual_gt_object.is_moving = false;
126+
gt_objects.emplace_back(actual_gt_object);
127+
}
128+
129+
for (const auto &gt_object : gt_objects) {
130+
auto gt_id = gt_object.id;
131+
132+
auto roll = std::round(gt_object.roll* 180 / M_PI * 1000) / 1000;
133+
auto pitch = std::round(gt_object.pitch * 180 / M_PI * 1000) / 1000;
134+
auto yaw = std::round(gt_object.yaw * 180 / M_PI * 1000) / 1000;
135+
136+
write_data_to_CSV(file_path_gtobjects, timestamp, gt_id, gt_object.x, gt_object.y, gt_object.z, gt_object.roll, gt_object.pitch, gt_object.yaw,
137+
gt_object.width, gt_object.length, gt_object.height, gt_object.is_moving);
138+
}
139+
}
140+
141+
void CsvOutputGTObjects::write_first_line_to_CSV(const std::string &path) {
142+
std::fstream my_file;
143+
my_file.open(path, std::ios::app);
144+
my_file
145+
<< "timestamp_in_s, gt_object_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"
146+
<< std::endl;
147+
my_file.close();
148+
}
149+
150+
void CsvOutputGTObjects::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) {
151+
std::fstream my_file;
152+
my_file.open(path, std::ios::app);
153+
my_file << timestamp << ", " << object_idx << ", " << x << ", " << y << ", " << z << ", " << roll << ", " << pitch
154+
<< ", " << yaw << ", " << width << ", " << length << ", " << height << ", "
155+
<< (is_moving ? "true" : "false") << std::endl;
156+
my_file.close();
157+
}

Diff for: src/model/strategies/ros-output-gtobjects-strategy

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
project(ros_gt_objects)
3+
4+
# TODO MODIFY THE FOLLOWING LINES AS NEEDED
5+
set(STRATEGY_ENTRY_POINT ros_gt_objects)
6+
set(STRATEGY_SOURCES src/ros_gt_objects.cpp)
7+
set(STRATEGY_EXTRA_PUBLIC_LIBS_OR_TARGETS ${PCL_COMMON_LIBRARIES} ${catkin_LIBRARIES})
8+
set(STRATEGY_EXTRA_PRIVATE_LIBS_OR_TARGETS "")
9+
set(STRATEGY_EXTRA_INCLUDE_DIRECTORIES ${catkin_INCLUDE_DIRS} ${PCL_INCLUDE_DIRS})
10+
set(STRATEGY_EXTRA_DEPENDENCIES ${catkin_EXPORTED_TARGETS})
11+
#set(STRATEGY_PROFILE_EXTENSION ${PROFILES})
12+
13+
# no need to modify commands below this line
14+
set(CMAKE_CXX_STANDARD 17)
15+
16+
if(NOT COMMAND add_fmu_ros_output_strategy)
17+
message(FATAL_ERROR "This project directory has to be included by OSI FMU platform, it can't be build out of that context!")
18+
endif()
19+
20+
add_fmu_ros_output_strategy(${PROJECT_NAME} ${STRATEGY_ENTRY_POINT})
21+
if(STRATEGY_PROFILE_EXTENSION)
22+
add_profile_part(${STRATEGY_PROFILE_EXTENSION})
23+
endif()
24+
25+
add_library(${PROJECT_NAME} STATIC ${STRATEGY_SOURCES})
26+
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})
27+
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${STRATEGY_EXTRA_INCLUDE_DIRECTORIES})
28+
set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON)
29+
add_dependencies(${PROJECT_NAME} ${STRATEGY_EXTRA_DEPENDENCIES})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# OSI Ground Truth Objects to ROS Output Strategy
2+
3+
This strategy outputs OSI global_ground_truth.moving_objects and global_ground_truth.stationary_objects as ROS Marker messages.
4+
Using the ROS tool rviz is a convenient way to visualize OSI sensor view input and sensor data output.
5+
6+
## Usage
7+
You need to add the name of the strategy in a new line in the *ros_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_ros_output* needs to be set to *1* and be passed to the framework or model fmu.
10+
11+
## ROS Distributions
12+
This strategy needs a full install of either ROS noetic or ROS melodic. The ROS distribution needs to be located in /opt/ros/.

0 commit comments

Comments
 (0)