Skip to content
Snippets Groups Projects
Commit 8eadb734 authored by Reinhard Biegel's avatar Reinhard Biegel
Browse files

mod(Observation_Log): Restructure of observation data flow

- Implementation of BasicDataStore
- Usage if Publisher interface instead of Observations->Inserts
- Observations are parameterizable now
parent 67543b4d
No related branches found
No related tags found
No related merge requests found
Showing
with 550 additions and 350 deletions
BasedOnStyle: llvm
Language: Cpp
ColumnLimit: 0
IndentWidth: 4
AccessModifierOffset: -4
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<(gtest|gmock)/)'
Priority: -1
- Regex: '^<[^Q]'
Priority: 1
- Regex: '^<Q'
Priority: 2
AlignTrailingComments: true
BreakConstructorInitializers: AfterColon
ConstructorInitializerAllOnOneLineOrOnePerLine: true
AllowShortFunctionsOnASingleLine: None
KeepEmptyLinesAtTheStartOfBlocks: false
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH, forever, Q_FOREVER, QBENCHMARK, QBENCHMARK_ONCE ]
\ No newline at end of file
...@@ -35,6 +35,21 @@ Then the AgentType with the components and channels is build by the DynamicAgent ...@@ -35,6 +35,21 @@ Then the AgentType with the components and channels is build by the DynamicAgent
![AgentBlueprintProviderSequenceDiagram](AgentBlueprintProviderSequence.svg) ![AgentBlueprintProviderSequenceDiagram](AgentBlueprintProviderSequence.svg)
\section dev_framework_modules_datastore DataStore
The DataStore accepts arbitrary values from different components (from framework as well as agents).
The stored values if cyclic and acyclic type are associated with an timestamp, entity id and a key (topic).
Static values are only associated with a key.
Typically, Observers are using the DataStore to retrieve information about the simulation.
This can happen during the simulation run and/or at the end of a run.
For the keys, a generic datatype is used (strings).
For the values, a set of predefined datatypes is used (bool, char, int, size_t, float, double, string).
A value can also hold a vector of one of the mentioned datatypes.
For information about the usage, please refer to the implementation's inline documentation.
\section dev_framework_modules_eventdetectors EventDetectors \section dev_framework_modules_eventdetectors EventDetectors
[//]: <> "Please refer to each section!" [//]: <> "Please refer to each section!"
......
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2017, 2018, 2019 in-tech GmbH * Copyright (c) 2017, 2018, 2019, 2020 in-tech GmbH
* *
* This program and the accompanying materials are made * This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0 * available under the terms of the Eclipse Public License 2.0
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#pragma once #pragma once
#include <vector>
#include "Interfaces/eventInterface.h" #include "Interfaces/eventInterface.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -30,115 +32,125 @@ ...@@ -30,115 +32,125 @@
class BasicEvent : public EventInterface class BasicEvent : public EventInterface
{ {
public: public:
BasicEvent(int time, BasicEvent(int time, std::string eventName, std::string source,
std::string eventName, const std::vector<int> triggeringAgents, const std::vector<int> actingAgents) :
std::string source):
time(time), time(time),
name(eventName), name(eventName),
source(source) source(source),
{} triggeringAgents(triggeringAgents),
BasicEvent(const BasicEvent&) = delete; actingAgents(actingAgents)
BasicEvent(BasicEvent&&) = delete; {
BasicEvent& operator=(const BasicEvent&) = delete; }
BasicEvent& operator=(BasicEvent&&) = delete;
BasicEvent(int time, std::string eventName, std::string source) :
time(time),
name(eventName),
source(source),
triggeringAgents{},
actingAgents{}
{
}
virtual ~BasicEvent() override = default; virtual ~BasicEvent() override = default;
/*!
* \brief Sets the Id of the event.
*
* @param[in] Id of the event.
*/
virtual void SetId(const int eventId) override virtual void SetId(const int eventId) override
{ {
this->eventId = eventId; this->eventId = eventId;
} }
/*!
* \brief Returns the Id of the event.
*
* @return Id.
*/
virtual int GetId() const override virtual int GetId() const override
{ {
return eventId; return eventId;
} }
/*!
* \brief Returns the time of the event.
*
* @return Time in milliseconds.
*/
virtual int GetEventTime() const override virtual int GetEventTime() const override
{ {
return time; return time;
} }
/*!
* \brief Returns the category of the event.
*
* @return EventCategory.
*/
virtual EventDefinitions::EventCategory GetCategory() const override virtual EventDefinitions::EventCategory GetCategory() const override
{ {
return EventDefinitions::EventCategory::Basic; return EventDefinitions::EventCategory::Basic;
} }
/*!
* \brief Sets the Id of the event which triggered this event.
*
* @param[in] Event Id.
*/
virtual void SetTriggeringEventId(const int triggeringEventId) override virtual void SetTriggeringEventId(const int triggeringEventId) override
{ {
this->triggeringEventId = triggeringEventId; this->triggeringEventId = triggeringEventId;
} }
/*!
* \brief Returns the Id of the event which triggered this event.
*
* @return Event Id.
*/
virtual int GetTriggeringEventId() const override virtual int GetTriggeringEventId() const override
{ {
return triggeringEventId; return triggeringEventId;
} }
/*!
* \brief Returns the name of the event.
*
* @return Name of the event as string.
*/
virtual std::string GetName() const override virtual std::string GetName() const override
{ {
return name; return name;
} }
/*!
* \brief Returns the name of the source component.
*
* @return Name of source component as string.
*/
virtual std::string GetSource() const override virtual std::string GetSource() const override
{ {
return source; return source;
} }
/*! virtual const std::vector<int> GetTriggeringAgents() const override
* \brief Returns all parameters of the event as string list. {
* \details Returns all parameters of the event as a generic string list. return triggeringAgents;
* The parameter name and the value are returned as string. }
*
* @return List of string pairs of the event parameters. virtual const std::vector<int> GetActingAgents() const override
*/ {
return actingAgents;
}
virtual EventParameters GetParametersAsString() override virtual EventParameters GetParametersAsString() override
{ {
return {}; EventParameters eventParameters;
std::string triggeringAgentsAsString{};
for (auto &triggeringAgentId : triggeringAgents)
{
triggeringAgentsAsString += std::to_string(triggeringAgentId) + ",";
}
std::string actingAgentsAsString;
for (auto &actingAgentId : actingAgents)
{
actingAgentsAsString += std::to_string(actingAgentId) + ",";
}
if (!triggeringAgentsAsString.empty())
{
triggeringAgentsAsString.pop_back();
eventParameters.push_back({"TriggeringAgentIds", triggeringAgentsAsString});
}
if (!actingAgentsAsString.empty())
{
actingAgentsAsString.pop_back();
eventParameters.push_back({"ActingAgentIds", actingAgentsAsString});
}
return eventParameters;
}
const openpass::type::FlatParameter &GetParameter() const noexcept override
{
return parameter;
} }
private: private:
int eventId;
const int time; const int time;
int triggeringEventId {-1};
const std::string name; const std::string name;
const std::string source; const std::string source;
int eventId{};
int triggeringEventId{-1};
public:
const std::vector<int> triggeringAgents;
const std::vector<int> actingAgents;
protected:
openpass::type::FlatParameter parameter{};
}; };
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
* *
* This class contains all functionality of the module. */ * This class contains all functionality of the module. */
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#pragma once #pragma once
#include "basicEvent.h" #include "basicEvent.h"
...@@ -27,54 +26,32 @@ ...@@ -27,54 +26,32 @@
class CollisionEvent : public BasicEvent class CollisionEvent : public BasicEvent
{ {
public: public:
CollisionEvent(int time, CollisionEvent(int time, std::string source, bool collisionWithAgent, int collisionAgentId, int collisionOpponentId) :
std::string source, BasicEvent{time, "Collision", source, {collisionAgentId, collisionOpponentId}, {}},
bool collisionWithAgent, collisionWithAgent{collisionWithAgent},
int collisionAgentId, collisionAgentId{collisionAgentId},
int collisionOpponentId): collisionOpponentId{collisionOpponentId}
BasicEvent(time,
"Collision",
source),
collisionWithAgent(collisionWithAgent),
collisionAgentId(collisionAgentId),
collisionOpponentId(collisionOpponentId)
{}
CollisionEvent(const CollisionEvent&) = delete;
CollisionEvent(CollisionEvent&&) = delete;
CollisionEvent& operator=(const CollisionEvent&) = delete;
CollisionEvent& operator=(CollisionEvent&&) = delete;
virtual ~CollisionEvent() override = default;
/*!
* \brief Returns the category of the event.
*
* @return EventCategory.
*/
virtual EventDefinitions::EventCategory GetCategory() const override
{ {
return EventDefinitions::EventCategory::Collision; parameter.emplace("CollisionWithAgent", collisionWithAgent);
} }
/*! ~CollisionEvent() override = default;
* \brief Returns all parameters of the event as string list.
* \details Returns the CollisionWithAgent flag and both worldobject ids as string list. EventDefinitions::EventCategory GetCategory() const override
*
* @return List of string pairs of the event parameters.
*/
virtual EventParameters GetParametersAsString() override
{ {
EventParameters eventParameters; return EventDefinitions::EventCategory::OpenPASS;
}
EventParameters GetParametersAsString() override
{
EventParameters eventParameters = BasicEvent::GetParametersAsString();
eventParameters.push_back({"CollisionWithAgent", collisionWithAgent ? "true" : "false"}); eventParameters.push_back({"CollisionWithAgent", collisionWithAgent ? "true" : "false"});
eventParameters.push_back({"CollisionAgentId", std::to_string(collisionAgentId)}); eventParameters.push_back({"CollisionAgentId", std::to_string(collisionAgentId)});
eventParameters.push_back({"CollisionOpponentId", std::to_string(collisionOpponentId)}); eventParameters.push_back({"CollisionOpponentId", std::to_string(collisionOpponentId)});
return eventParameters; return eventParameters;
} }
[[deprecated("Will be replaced by BasicEvent::parameter")]] bool collisionWithAgent;
bool collisionWithAgent; [[deprecated("Will be replaced by BasicEvent::parameter")]] int collisionAgentId;
int collisionAgentId; [[deprecated("Will be replaced by BasicEvent::parameter")]] int collisionOpponentId;
int collisionOpponentId;
}; };
...@@ -17,10 +17,11 @@ ...@@ -17,10 +17,11 @@
#define _USE_MATH_DEFINES #define _USE_MATH_DEFINES
#endif #endif
#include <cmath> #include <cmath>
#include <map> #include <map>
#include <unordered_map> #include <unordered_map>
#include <boost/algorithm/string/trim.hpp>
#include "globalDefinitions.h" #include "globalDefinitions.h"
#include "vector2d.h" #include "vector2d.h"
...@@ -318,6 +319,27 @@ public: ...@@ -318,6 +319,27 @@ public:
} }
}; };
namespace helper::vector {
/// \brief convenience function to convert a vector into a string using a constom delimiter
/// \remark Please refer to the standard, how decimals are converted
/// \param values vector of strings
/// \param delimiter string in between the individual values
/// \return delimiter seperated list as string
template <typename T>
std::string to_string(const std::vector<T>& values, const std::string& delimiter = ",")
{
if (values.empty())
{
return "";
}
std::ostringstream oss;
std::copy(values.begin(), values.end(), std::ostream_iterator<T>(oss, delimiter.c_str()));
return {oss.str(), 0, oss.str().length() - delimiter.size()};
}
} // namespace helper::vector
namespace helper::map { namespace helper::map {
/// @brief queries a map for a given key and returns the value if available /// @brief queries a map for a given key and returns the value if available
......
...@@ -33,44 +33,43 @@ ...@@ -33,44 +33,43 @@
class ComponentChangeEvent : public ConditionalEvent class ComponentChangeEvent : public ConditionalEvent
{ {
public: public:
ComponentChangeEvent(int time, ComponentChangeEvent(int time, const std::string &eventName, const std::string &source,
const std::string& eventName, std::vector<int> triggeringAgents, std::vector<int> actingAgents,
const std::string& source, const std::string &componentName, const std::string &goalStateName) :
std::vector<int> triggeringAgents, ConditionalEvent{time, eventName, source, triggeringAgents, actingAgents},
std::vector<int> actingAgents, componentName{componentName},
const std::string& componentName, goalStateName{goalStateName}
const std::string& goalStateName):
ConditionalEvent(time,
eventName,
source,
triggeringAgents,
actingAgents),
componentName(componentName),
goalStateName(goalStateName)
{ {
goalState = ComponentStateMapping.at(goalStateName); goalState = ComponentStateMapping.at(goalStateName);
parameter.emplace("ComponentName", componentName);
parameter.emplace("GoalStateName", goalStateName);
} }
ComponentChangeEvent(const ComponentChangeEvent&) = delete;
ComponentChangeEvent(ComponentChangeEvent&&) = delete;
ComponentChangeEvent& operator=(const ComponentChangeEvent&) = delete;
ComponentChangeEvent& operator=(ComponentChangeEvent&&) = delete;
virtual ~ComponentChangeEvent() override = default;
/*! ~ComponentChangeEvent() override = default;
* \brief Returns the category of the event.
* EventDefinitions::EventCategory GetCategory() const override
* @return EventCategory.
*/
virtual EventDefinitions::EventCategory GetCategory() const override
{ {
return EventDefinitions::EventCategory::ComponentStateChange; return EventDefinitions::EventCategory::ComponentStateChange;
} }
EventParameters GetParametersAsString() override
{
EventParameters eventParameters = ConditionalEvent::GetParametersAsString();
eventParameters.push_back({"ComponentName", componentName});
eventParameters.push_back({"State", goalStateName});
return eventParameters;
}
/*! /*!
* \brief Returns the component name for which the event is targeted * \brief Returns the component name for which the event is targeted
* @return Component Name * @return Component Name
*/ */
std::string GetComponentName() const { std::string GetComponentName() const
{
return componentName; return componentName;
} }
...@@ -78,7 +77,8 @@ public: ...@@ -78,7 +77,8 @@ public:
* \brief Returns the goal state name for which the event is targeted * \brief Returns the goal state name for which the event is targeted
* @return State Name * @return State Name
*/ */
std::string GetGoalStateName() const { std::string GetGoalStateName() const
{
return goalStateName; return goalStateName;
} }
...@@ -86,24 +86,9 @@ public: ...@@ -86,24 +86,9 @@ public:
* \brief Returns the goal state as a result of the event * \brief Returns the goal state as a result of the event
* @return State * @return State
*/ */
ComponentState GetGoalState() const { ComponentState GetGoalState() const
return goalState;
}
/*!
* \brief Returns all parameters of the event as string list.
* \details Returns the agentId as string list.
*
* @return List of string pairs of the event parameters.
*/
virtual EventParameters GetParametersAsString() override
{ {
EventParameters eventParameters = ConditionalEvent::GetParametersAsString(); return goalState;
eventParameters.push_back({"ComponentName", componentName});
eventParameters.push_back({"State", goalStateName});
return eventParameters;
} }
private: private:
......
/*******************************************************************************
* Copyright (c) 2019 in-tech GmbH
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
#pragma once
#include "vehicleComponentEvent.h"
#include "Interfaces/signalInterface.h"
/*!
* ----------------------------------------------------------------------------
* \brief The ComponentWarningEvent class contains all information related to
* an event emitted in response to a Component Warning.
* ----------------------------------------------------------------------------
*/
class ComponentWarningEvent : public VehicleComponentEvent
{
public:
ComponentWarningEvent(const int time,
const std::string& source,
const int agentId,
const std::string& componentName,
const ComponentWarningInformation& warning):
VehicleComponentEvent(time,
"",
source,
agentId),
componentName(componentName),
warning(warning)
{}
ComponentWarningEvent(const ComponentWarningEvent&) = delete;
ComponentWarningEvent(ComponentWarningEvent&&) = delete;
ComponentWarningEvent& operator=(const ComponentWarningEvent&) = delete;
ComponentWarningEvent& operator=(ComponentWarningEvent&&) = delete;
virtual ~ComponentWarningEvent() override = default;
/*!
* \brief Returns the component name for which the event is targeted
* @return Component Name
*/
std::string GetComponentName() const
{
return componentName;
}
/*!
* \brief GetComponentWarningInformation gets the information regarding the warning from the event
* \return Component warning information
*/
ComponentWarningInformation GetComponentWarningInformation() const
{
return warning;
}
/*!
* \brief Returns all parameters of the event as string list.
* \details Returns the agentId as string list.
*
* @return List of string pairs of the event parameters.
*/
virtual EventParameters GetParametersAsString() override
{
auto eventParameters = VehicleComponentEvent::GetParametersAsString();
eventParameters.push_back({"ComponentName", componentName});
eventParameters.push_back({"Activity", warning.activity ? "true" : "false"});
eventParameters.push_back({"Level", ComponentWarningLevelMapping.at(warning.level)});
eventParameters.push_back({"Type", ComponentWarningTypeMapping.at(warning.type)});
eventParameters.push_back({"Intensity", ComponentWarningIntensityMapping.at(warning.intensity)});
return eventParameters;
}
private:
const std::string componentName; //!< The name of the component that has a warning
const ComponentWarningInformation warning; //!< The collected information regarding the warning
};
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2017, 2018, 2019 in-tech GmbH * Copyright (c) 2017, 2018, 2019, 2020 in-tech GmbH
* *
* This program and the accompanying materials are made * This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0 * available under the terms of the Eclipse Public License 2.0
...@@ -8,13 +8,6 @@ ...@@ -8,13 +8,6 @@
* SPDX-License-Identifier: EPL-2.0 * SPDX-License-Identifier: EPL-2.0
*******************************************************************************/ *******************************************************************************/
//-----------------------------------------------------------------------------
/** @file AgentBasedEvent.h
* @brief This file contains all functions for agent based events.
*
* This class contains all functionality of the module. */
//-----------------------------------------------------------------------------
#pragma once #pragma once
#include <vector> #include <vector>
...@@ -22,71 +15,23 @@ ...@@ -22,71 +15,23 @@
#include "basicEvent.h" #include "basicEvent.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/** This class implements all functionality of the AgentBasedEvent. /** This class implements all functionality of the ConditionalEvent.
* *
* \ingroup Event */ * \ingroup Event */
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class ConditionalEvent : public BasicEvent class ConditionalEvent : public BasicEvent
{ {
public: public:
ConditionalEvent(int time, ConditionalEvent(int time, std::string eventName, std::string source,
std::string eventName, std::vector<int> triggeringAgents, std::vector<int> actingAgents) :
std::string source, BasicEvent{time, eventName, source, triggeringAgents, actingAgents}
std::vector<int> triggeringAgents,
std::vector<int> actingAgents):
BasicEvent(time,
eventName,
source),
triggeringAgents(triggeringAgents),
actingAgents(actingAgents)
{}
~ConditionalEvent() override = default;
/*!
* \brief Returns the category of the event.
*
* @return EventCategory.
*/
virtual EventDefinitions::EventCategory GetCategory() const override
{ {
return EventDefinitions::EventCategory::Conditional;
} }
/*! ~ConditionalEvent() override = default;
* \brief Returns all parameters of the event as string list.
* \details Returns the agentId as string list.
*
* @return List of string pairs of the event parameters.
*/
EventParameters GetParametersAsString() override
{
EventParameters eventParameters;
std::string triggeringAgentsAsString{};
for (auto &triggeringAgentId : triggeringAgents) {
triggeringAgentsAsString += std::to_string(triggeringAgentId) + ",";
}
std::string actingAgentsAsString;
for (auto &actingAgentId : actingAgents) {
actingAgentsAsString += std::to_string(actingAgentId) + ",";
}
if(triggeringAgentsAsString.size() > 0)
{
triggeringAgentsAsString.pop_back();
eventParameters.push_back({"TriggeringAgentIds", triggeringAgentsAsString});
}
if(actingAgentsAsString.size() > 0)
{
actingAgentsAsString.pop_back();
eventParameters.push_back({"ActingAgentIds", actingAgentsAsString});
}
return eventParameters; EventDefinitions::EventCategory GetCategory() const override
{
return EventDefinitions::EventCategory::OpenSCENARIO;
} }
const std::vector<int> triggeringAgents;
const std::vector<int> actingAgents;
}; };
...@@ -266,10 +266,13 @@ using Condition = std::variant<ReachPositionRoadCondition, ...@@ -266,10 +266,13 @@ using Condition = std::variant<ReachPositionRoadCondition,
TimeHeadwayCondition>; TimeHeadwayCondition>;
using ConditionCollection = std::vector<Condition>; using ConditionCollection = std::vector<Condition>;
///
/// \brief Event specific information collected from an openSCENARIO story
///
struct ConditionalEventDetectorInformation struct ConditionalEventDetectorInformation
{ {
ActorInformation actorInformation{}; ActorInformation actorInformation{};
int numberOfExecutions{}; int numberOfExecutions{}; ///< Specifies number of executions. Use -1 for "unrestricted"
std::string eventName{}; std::string eventName{};
ConditionCollection conditions{}; ConditionCollection conditions{};
}; };
......
...@@ -14,20 +14,83 @@ ...@@ -14,20 +14,83 @@
#include <map> #include <map>
#include <string> #include <string>
namespace EventDefinitions #include "Common/openPassTypes.h"
#include "Interfaces/dataStoreInterface.h" // TODO: RP: make datastore types (Acyclic, TriggeringEntites,...) explicitly available
namespace openpass::narrator {
class EventBase
{ {
public:
EventBase() = default;
EventBase(std::string name) :
name{std::move(name)}
{
}
EventBase(std::string name, TriggeringEntities triggeringEntities, AffectedEntities affectedEntities) :
name{std::move(name)},
triggeringEntities{std::move(triggeringEntities)},
affectedEntities{std::move(affectedEntities)}
{
}
std::string name;
TriggeringEntities triggeringEntities;
AffectedEntities affectedEntities;
virtual explicit operator Acyclic() const = 0;
// We do not allow copy to force move semantics
EventBase(const EventBase &) = delete;
EventBase &operator=(const EventBase &) = delete;
// Explicitly allow move
EventBase(EventBase &&) = default;
EventBase &operator=(EventBase &&) = default;
// Neccesary evil
virtual ~EventBase() = default;
};
}
namespace EventDefinitions {
enum struct EventCategory enum struct EventCategory
{ {
Basic = 0, Basic, // deprecated
Conditional, Conditional, // deprecated
Collision, Collision, // deprecated
ComponentStateChange, ComponentStateChange, // deprecated
LaneChange, LaneChange, // deprecated
CustomLaneChange, CustomLaneChange, // deprecated ?
SetTrajectory, SetTrajectory, // deprecated ?
SetGazeFollower, SetGazeFollower, // deprecated ?
VehicleComponent VehicleComponent, // deprecated
OpenPASS,
OpenSCENARIO
}; };
}//namespace EventDefinitions namespace helper {
static constexpr std::array<const char *, 11> EventCategoryMapping{
"Basic",
"Conditional",
"Collision",
"ComponentStateChange",
"LaneChange",
"CustomLaneChange",
"SetTrajectory",
"SetGazeFollower",
"VehicleComponent",
"OpenPASS",
"OpenSCENARIO"};
constexpr auto GetAsString(EventCategory category)
{
return EventCategoryMapping[static_cast<size_t>(category)];
}
} // namespace helper
} //namespace EventDefinitions
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2017, 2018, 2019 in-tech GmbH * Copyright (c) 2017, 2018, 2019, 2020 in-tech GmbH
* 2018, 2019 AMFD GmbH * 2018, 2019 AMFD GmbH
* 2016, 2017, 2018, 2019 ITK Engineering GmbH * 2016, 2017, 2018, 2019 ITK Engineering GmbH
* *
...@@ -15,8 +15,7 @@ ...@@ -15,8 +15,7 @@
//! @brief This file contains several classes for global purposes //! @brief This file contains several classes for global purposes
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#ifndef GLOBALDEFINITIONS #pragma once
#define GLOBALDEFINITIONS
#include <list> #include <list>
#include <map> #include <map>
...@@ -103,20 +102,19 @@ inline AgentVehicleType GetAgentVehicleType(const std::string &strVehicleType) ...@@ -103,20 +102,19 @@ inline AgentVehicleType GetAgentVehicleType(const std::string &strVehicleType)
// convert a AgentVehicleType to VehicleType string // convert a AgentVehicleType to VehicleType string
inline std::string GetAgentVehicleTypeStr(const AgentVehicleType &vehicleType) inline std::string GetAgentVehicleTypeStr(const AgentVehicleType &vehicleType)
{ {
return (vehicleType == AgentVehicleType::Car) ? "Car" : return (vehicleType == AgentVehicleType::Car) ? "Car" : (vehicleType == AgentVehicleType::Pedestrian) ? "Pedestrian" : (vehicleType == AgentVehicleType::Motorbike) ? "Motorbike" : (vehicleType == AgentVehicleType::Bicycle) ? "Bicycle" : (vehicleType == AgentVehicleType::Truck) ? "Truck" : "unknown type";
(vehicleType == AgentVehicleType::Pedestrian) ? "Pedestrian" :
(vehicleType == AgentVehicleType::Motorbike) ? "Motorbike" :
(vehicleType == AgentVehicleType::Bicycle) ? "Bicycle" :
(vehicleType == AgentVehicleType::Truck) ? "Truck" : "unknown type";
} }
// convert a string of type code to VehicleType string // convert a string of type code to VehicleType string
inline std::string GetAgentVehicleTypeStr(const std::string &vehicleTypeCode) inline std::string GetAgentVehicleTypeStr(const std::string &vehicleTypeCode)
{ {
try{ try
{
AgentVehicleType vehicleType = static_cast<AgentVehicleType>(std::stoi(vehicleTypeCode)); AgentVehicleType vehicleType = static_cast<AgentVehicleType>(std::stoi(vehicleTypeCode));
return GetAgentVehicleTypeStr(vehicleType); return GetAgentVehicleTypeStr(vehicleType);
} catch(...) { }
catch (...)
{
return "unknown type"; return "unknown type";
} }
} }
...@@ -139,23 +137,26 @@ enum class IndicatorState ...@@ -139,23 +137,26 @@ enum class IndicatorState
struct Position struct Position
{ {
Position() {} Position()
{
}
Position(double x, Position(double x,
double y, double y,
double yaw, double yaw,
double curvature): double curvature) :
xPos(x), xPos(x),
yPos(y), yPos(y),
yawAngle(yaw), yawAngle(yaw),
curvature(curvature) {} curvature(curvature)
{
}
double xPos {0}; double xPos{0};
double yPos {0}; double yPos{0};
double yawAngle {0}; double yawAngle{0};
double curvature {0}; double curvature{0};
}; };
//! Enum of potential types of marks. //! Enum of potential types of marks.
enum class MarkType enum class MarkType
{ {
...@@ -178,10 +179,10 @@ enum class ObjectType ...@@ -178,10 +179,10 @@ enum class ObjectType
enum ObjectTypeOSI : int enum ObjectTypeOSI : int
{ {
None = 0x00, // default at initialization None = 0x00, // default at initialization
Vehicle = 0x01, Vehicle = 0x01,
Object = 0x02, Object = 0x02,
Any = Vehicle | Object Any = Vehicle | Object
}; };
using CollisionPartner = std::pair<ObjectTypeOSI, int>; using CollisionPartner = std::pair<ObjectTypeOSI, int>;
...@@ -301,10 +302,9 @@ enum class AdasType ...@@ -301,10 +302,9 @@ enum class AdasType
Undefined Undefined
}; };
const std::map<AdasType, std::string> adasTypeToString = { { AdasType::Safety, "Safety" }, const std::map<AdasType, std::string> adasTypeToString = {{AdasType::Safety, "Safety"},
{ AdasType::Comfort, "Comfort" }, {AdasType::Comfort, "Comfort"},
{ AdasType::Undefined, "Undefined" } {AdasType::Undefined, "Undefined"}};
};
enum class ComponentType enum class ComponentType
{ {
...@@ -330,7 +330,8 @@ public: ...@@ -330,7 +330,8 @@ public:
weekday(weekday), weekday(weekday),
timeOfDay(timeOfDay), timeOfDay(timeOfDay),
libraryName(libraryName) libraryName(libraryName)
{} {
}
WorldParameter(const WorldParameter &) = delete; WorldParameter(const WorldParameter &) = delete;
WorldParameter(WorldParameter &&) = delete; WorldParameter(WorldParameter &&) = delete;
WorldParameter &operator=(const WorldParameter &) = delete; WorldParameter &operator=(const WorldParameter &) = delete;
...@@ -367,7 +368,8 @@ public: ...@@ -367,7 +368,8 @@ public:
AgentSpawnItem(int id, int reference) : AgentSpawnItem(int id, int reference) :
id(id), id(id),
reference(reference) reference(reference)
{} {
}
AgentSpawnItem(const AgentSpawnItem &) = delete; AgentSpawnItem(const AgentSpawnItem &) = delete;
AgentSpawnItem(AgentSpawnItem &&) = delete; AgentSpawnItem(AgentSpawnItem &&) = delete;
AgentSpawnItem &operator=(const AgentSpawnItem &) = delete; AgentSpawnItem &operator=(const AgentSpawnItem &) = delete;
...@@ -538,6 +540,3 @@ private: ...@@ -538,6 +540,3 @@ private:
double accelerationY; double accelerationY;
double yawAngle; double yawAngle;
}; };
#endif // GLOBALDEFINITIONS
/*******************************************************************************
* Copyright (c) 2020 in-tech GmbH
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
#pragma once
namespace openpass::type {
template <typename T, typename Tag>
struct NamedType
{
T value;
NamedType(T value) :
value(value)
{
}
operator T() const
{
return value;
}
};
} // namespace openpass::type
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "parameter.h" #include "parameter.h"
#include "Interfaces/dataStoreInterface.h"
/** /**
* @brief Wrapper for building an ObservationInstance * @brief Wrapper for building an ObservationInstance
......
...@@ -14,17 +14,74 @@ ...@@ -14,17 +14,74 @@
#define OBSERVATION_LOG_VALUE_UNDEFINED "" #define OBSERVATION_LOG_VALUE_UNDEFINED ""
#include <string> #include <string>
#include <unordered_map>
#include <vector>
enum class LoggingGroup //! Defines the cyclic coloumn names associated with each logging group
const std::unordered_map<std::string, std::vector<std::string>> LOGGINGGROUP_DEFINITIONS
{ {
Trace, { "RoadPosition", {
Visualization, "AgentInFront",
RoadPosition, "Lane",
RoadPositionExtended, "PositionRoute",
Vehicle, "Road",
Sensor, "TCoordinate"
SensorExtended, }
Driver },
{ "RoadPositionExtended", {
"SecondaryLanes"
}
},
{ "Trace", {
"XPosition",
"YPosition",
"YawAngle"
}
},
{ "Sensor", {
}
},
{ "SensorExtended", {
"Sensor0_DetectedAgents",
"Sensor1_DetectedAgents",
"Sensor2_DetectedAgents",
"Sensor3_DetectedAgents",
"Sensor4_DetectedAgents",
"Sensor5_DetectedAgents",
"Sensor6_DetectedAgents",
"Sensor7_DetectedAgents",
"Sensor8_DetectedAgents",
"Sensor9_DetectedAgents",
"Sensor0_VisibleAgents",
"Sensor1_VisibleAgents",
"Sensor2_VisibleAgents",
"Sensor3_VisibleAgents",
"Sensor4_VisibleAgents",
"Sensor5_VisibleAgents",
"Sensor6_VisibleAgents",
"Sensor7_VisibleAgents",
"Sensor8_VisibleAgents",
"Sensor9_VisibleAgents"
}
},
{ "Vehicle", {
"AccelerationPedalPosition",
"BrakePedalPosition",
"EngineMoment",
"Gear",
"SteeringAngle",
"TotalDistanceTraveled",
"YawRate",
}
},
{ "Visualization", {
"AccelerationEgo",
"BrakeLight",
"IndicatorState",
"LightStatus",
"VelocityEgo"
}
}
}; };
const std::string AgentCategoryStrings[] = const std::string AgentCategoryStrings[] =
......
/*******************************************************************************
* Copyright (c) 2020 in-tech GmbH
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
#pragma once
#include <functional>
#include <string>
#include <variant>
#include "namedType.h"
namespace openpass::type {
// TODO: MOVE TO CORE ONLY!
static constexpr int CoreId = 67798269; // ASCII: C O R E
using AgentId = int;
using EntityId = NamedType<AgentId, struct EntityIdType>;
using Timestamp = NamedType<int, struct TimestampType>;
using EntityIds = std::vector<EntityId>;
using FlatParameterKey = std::string;
using FlatParameterValue = std::variant<
bool, std::vector<bool>,
char, std::vector<char>,
int, std::vector<int>,
size_t, std::vector<size_t>,
float, std::vector<float>,
double, std::vector<double>,
std::string, std::vector<std::string>>;
using FlatParameter = std::unordered_map<FlatParameterKey, FlatParameterValue>;
} // namespace openpass::type
/*******************************************************************************
* Copyright (c) 2020 in-tech GmbH
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
#pragma once
#include <functional>
#include <iterator>
#include <sstream>
#include <string>
#include <vector>
template <class... Ts>
struct overload : Ts...
{
using Ts::operator()...;
};
template <class... Ts>
overload(Ts...)->overload<Ts...>;
namespace openpass::utils {
namespace vector {
/// \brief convenience function to convert a vector into a string using a constom delimiter
/// \remark Please refer to the standard, how decimals are converted
/// \param values vector of strings
/// \param delimiter string in between the individual values
/// \return delimiter seperated list as string
template <typename T>
std::string to_string(const std::vector<T> &values, const std::string &delimiter = ",")
{
if (values.empty())
{
return "";
}
std::ostringstream oss;
std::copy(values.begin(), values.end(), std::ostream_iterator<T>(oss, delimiter.c_str()));
return {oss.str(), 0, oss.str().length() - delimiter.size()};
}
} // namespace vector
namespace FlatParameter {
/// \brief visitor for parameter values of events
/// Converts the visitor values into strings and forwards the result to writer callable
/// Values in vectors are converted and seperated by a delimiter.
/// If value is 12.34 => writer("12.34");
/// If value is {12.34, 23.45} => writer("12.34,23.45");
/// \see openpass::type::FlatParameterValue
/// \see openpass::utils::vector::to_string
/// \param[in] writer callable collecting the converted value
/// \param[in] delimiter used for vector type (default = ",")
[[maybe_unused]] static auto to_string(std::function<void(std::string)> writer, const std::string &delimiter = ",")
{
return overload{
//[&](std::string &value) { writer(value); },
[&](const std::string &value) { writer(value); },
[&](auto &value) {
if constexpr (std::is_arithmetic_v<std::decay_t<decltype(value)>>)
{
writer(std::to_string(value));
}
else // path for std::vector types
{
if (!value.empty())
{
writer(vector::to_string(value, delimiter));
}
}
},
};
}
} // namespace FlatParameter
} // namespace openpass::utils
...@@ -56,7 +56,7 @@ struct StochasticAttribute ...@@ -56,7 +56,7 @@ struct StochasticAttribute
struct ActorInformation struct ActorInformation
{ {
std::optional<bool> triggeringAgentsAsActors{}; bool actorIsTriggeringEntity{false};
std::optional<std::vector<std::string>> actors{}; std::optional<std::vector<std::string>> actors{};
}; };
......
...@@ -9,9 +9,11 @@ ...@@ -9,9 +9,11 @@
*******************************************************************************/ *******************************************************************************/
#pragma once #pragma once
#include <optional>
#include <string>
#include <utility>
#include <variant> #include <variant>
#include <vector> #include <vector>
#include <optional>
#include "Common/stochasticDefinitions.h" #include "Common/stochasticDefinitions.h"
......
...@@ -32,12 +32,18 @@ public: ...@@ -32,12 +32,18 @@ public:
VehicleComponentEvent(int time, VehicleComponentEvent(int time,
const std::string &eventName, const std::string &eventName,
std::string source, std::string source,
int agentId): int agentId) :
BasicEvent(time, BasicEvent(time,
eventName, eventName,
source), source,
{agentId},
{}),
agentId(agentId) agentId(agentId)
{} {
parameter.emplace("Source", source);
parameter.emplace("State", eventName);
}
VehicleComponentEvent(const VehicleComponentEvent&) = delete; VehicleComponentEvent(const VehicleComponentEvent&) = delete;
VehicleComponentEvent(VehicleComponentEvent&&) = delete; VehicleComponentEvent(VehicleComponentEvent&&) = delete;
VehicleComponentEvent& operator=(const VehicleComponentEvent&) = delete; VehicleComponentEvent& operator=(const VehicleComponentEvent&) = delete;
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#pragma once #pragma once
#include <limits>
#include "globalDefinitions.h" #include "globalDefinitions.h"
#include <set> #include <set>
#include "boost/graph/adjacency_list.hpp" #include "boost/graph/adjacency_list.hpp"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment