Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/time to collision condition #1258

Draft
wants to merge 39 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1abe1bd
Add new struct `TimeToCollisionCondition`
yamacir-kit May 21, 2024
3a6c2b9
Add new struct `TimeToCollisionConditionTarget`
yamacir-kit May 21, 2024
5447363
Add new structs `RelativeSpeedCondition` and `DirectionalDimension`
yamacir-kit May 21, 2024
b09ca1f
Add static member function `ConditionEvaluation::evaluateRelativeSpeed`
yamacir-kit May 21, 2024
d270cdc
Move entity existence check into `distance` from speceialized `distance`
yamacir-kit May 22, 2024
3be8459
Update `RelativeDistanceCondition::distance` to static member function
yamacir-kit May 22, 2024
a7c5b23
Merge remote-tracking branch 'origin/master' into feature/time-to-col…
yamacir-kit May 30, 2024
cdcfc37
Merge branch 'master' into feature/time-to-collision-condition
yamacir-kit May 30, 2024
6535eeb
Add new static member function `RelativeSpeedCondition::evaluate`
yamacir-kit Jun 3, 2024
a55bcae
Merge remote-tracking branch 'origin/master' into feature/time-to-col…
yamacir-kit Jun 18, 2024
ee02017
Merge branch 'master' into feature/time-to-collision-condition
yamacir-kit Jun 26, 2024
be16d09
Remove data member `DistanceCondition::consider_z`
yamacir-kit Jun 26, 2024
77a1b31
Add `const Position &` to the argument of `DistanceCondition::distance`
yamacir-kit Jun 26, 2024
9b13ccd
Update member function `CoordinateSystem::distance` to be static member
yamacir-kit Jun 26, 2024
f95eccb
Rename `(Relative)?DistanceCondition::distance` to `evaluate`
yamacir-kit Jun 27, 2024
d005100
Merge branch 'master' into feature/time-to-collision-condition
yamacir-kit Jul 3, 2024
138ed19
Merge branch 'master' into feature/time-to-collision-condition
yamacir-kit Jul 5, 2024
26e5a41
Add support for `DirectionalDimension` to `SpeedCondition`
yamacir-kit Jul 5, 2024
cddc3a5
Move function `hypot` into new header `cmath/hypot.hpp`
yamacir-kit Jul 5, 2024
5018106
Update `unordered_map` of the `Entities` base class to private
yamacir-kit Jul 5, 2024
fdae8b4
Add new static member function `TimeToCollisionCondition::evaluate`
yamacir-kit Jul 8, 2024
27749e1
Merge branch 'master' into feature/time-to-collision-condition
yamacir-kit Jul 16, 2024
c28fc48
Merge branch 'master' into feature/time-to-collision-condition
yamacir-kit Jul 22, 2024
79a9ac8
Merge remote-tracking branch 'origin/master' into feature/time-to-col…
yamacir-kit Jul 31, 2024
6deadb0
Merge branch 'master' into feature/time-to-collision-condition
yamacir-kit Aug 1, 2024
3206624
Merge branch 'master' into feature/time-to-collision-condition
yamacir-kit Aug 8, 2024
fc5345e
Merge remote-tracking branch 'origin/master' into feature/time-to-col…
yamacir-kit Aug 28, 2024
19b6242
Merge branch 'master' into feature/time-to-collision-condition
yamacir-kit Sep 3, 2024
023154e
Merge branch 'master' into feature/time-to-collision-condition
yamacir-kit Sep 10, 2024
01259ea
Merge branch 'master' into feature/time-to-collision-condition
yamacir-kit Sep 12, 2024
6da0744
Merge branch 'master' into feature/time-to-collision-condition
yamacir-kit Sep 18, 2024
79ec36a
Merge branch 'master' into feature/time-to-collision-condition
yamacir-kit Sep 25, 2024
4fee870
Merge branch 'master' into feature/time-to-collision-condition
yamacir-kit Sep 27, 2024
98683d1
Merge branch 'master' into feature/time-to-collision-condition
yamacir-kit Oct 7, 2024
edadb22
Merge branch 'master' into feature/time-to-collision-condition
yamacir-kit Oct 11, 2024
95d173e
Merge branch 'master' into feature/time-to-collision-condition
yamacir-kit Oct 25, 2024
2be427e
Merge branch 'master' into feature/time-to-collision-condition
yamacir-kit Nov 5, 2024
9ba4dfa
Merge branch 'master' into feature/time-to-collision-condition
yamacir-kit Nov 8, 2024
7d28d80
Merge branch 'master' into feature/time-to-collision-condition
yamacir-kit Nov 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/math/geometry/include/geometry/vector3/norm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#ifndef GEOMETRY__VECTOR3__NORM_HPP_
#define GEOMETRY__VECTOR3__NORM_HPP_

#include <cmath>
#include <geometry/vector3/is_like_vector3.hpp>

namespace math
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2015 TIER IV, Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef OPENSCENARIO_INTERPRETER__CMATH__HYPOT_HPP_
#define OPENSCENARIO_INTERPRETER__CMATH__HYPOT_HPP_

#include <cmath>
#include <rclcpp/rclcpp.hpp>

namespace openscenario_interpreter
{
inline namespace cmath
{
/*
@todo: after checking all the scenario work well with
consider_pose_by_road_slope = true, remove this function and use
std::hypot(x, y, z)
*/
template <typename T>
auto hypot(T x, T y, T z)
{
static const auto consider_pose_by_road_slope = []() {
auto node = rclcpp::Node("get_parameter", "simulation");
node.declare_parameter("consider_pose_by_road_slope", false);
return node.get_parameter("consider_pose_by_road_slope").as_bool();
}();

return consider_pose_by_road_slope ? std::hypot(x, y, z) : std::hypot(x, y);
}
} // namespace cmath
} // namespace openscenario_interpreter

#endif // OPENSCENARIO_INTERPRETER__CMATH__HYPOT_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define OPENSCENARIO_INTERPRETER__SIMULATOR_CORE_HPP_

#include <geometry/quaternion/quaternion_to_euler.hpp>
#include <geometry/vector3/operator.hpp>
#include <openscenario_interpreter/error.hpp>
#include <openscenario_interpreter/syntax/boolean.hpp>
#include <openscenario_interpreter/syntax/double.hpp>
Expand Down Expand Up @@ -533,7 +534,6 @@ class SimulatorCore
return core->checkCollision(std::forward<decltype(xs)>(xs)...);
}

template <typename... Ts>
static auto evaluateBoundingBoxEuclideanDistance(
const std::string & from_entity_name,
const std::string & to_entity_name) // for RelativeDistanceCondition
Expand All @@ -551,6 +551,13 @@ class SimulatorCore
return std::numeric_limits<double>::quiet_NaN();
}

template <typename T, typename U>
static auto evaluateRelativeSpeed(const T & x, const U & y)
{
using math::geometry::operator-;
return core->getCurrentTwist(x).linear - core->getCurrentTwist(y).linear;
}

template <typename... Ts>
static auto evaluateSimulationTime(Ts &&... xs) -> double
{
Expand All @@ -564,7 +571,7 @@ class SimulatorCore
template <typename... Ts>
static auto evaluateSpeed(Ts &&... xs)
{
return core->getCurrentTwist(std::forward<decltype(xs)>(xs)...).linear.x;
return core->getCurrentTwist(std::forward<decltype(xs)>(xs)...).linear;
}

template <typename... Ts>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Copyright 2015 TIER IV, Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef OPENSCENARIO_INTERPRETER__SYNTAX__DIRECTIONAL_DIMENSION_HPP_
#define OPENSCENARIO_INTERPRETER__SYNTAX__DIRECTIONAL_DIMENSION_HPP_

namespace openscenario_interpreter
{
inline namespace syntax
{
/*
DirectionalDimension (OpenSCENARIO XML 1.3)

Defines the directions in the entity coordinate system.

<xsd:simpleType name="DirectionalDimension">
<xsd:union>
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="longitudinal"/>
<xsd:enumeration value="lateral"/>
<xsd:enumeration value="vertical"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType>
<xsd:restriction base="parameter"/>
</xsd:simpleType>
</xsd:union>
</xsd:simpleType>
*/
struct DirectionalDimension
{
enum value_type {
/*
Longitudinal direction (along the x-axis).
*/
longitudinal, // NOTE: DEFAULT VALUE

/*
Lateral direction (along the y-axis).
*/
lateral,

/*
Vertical direction (along the z-axis).
*/
vertical,
};

value_type value;

DirectionalDimension() = default;

constexpr DirectionalDimension(value_type value) : value(value) {}

constexpr operator value_type() const noexcept { return value; }

friend auto operator>>(std::istream & istream, DirectionalDimension & datum) -> std::istream &
{
if (auto token = std::string(); istream >> token) {
if (token == "longitudinal") {
datum.value = DirectionalDimension::longitudinal;
return istream;
} else if (token == "lateral") {
datum.value = DirectionalDimension::lateral;
return istream;
} else if (token == "vertical") {
datum.value = DirectionalDimension::vertical;
return istream;
} else {
throw UNEXPECTED_ENUMERATION_VALUE_SPECIFIED(DirectionalDimension, token);
}
} else {
datum.value = DirectionalDimension::value_type();
return istream;
}
}

friend auto operator<<(std::ostream & ostream, const DirectionalDimension & datum)
-> std::ostream &
{
switch (datum) {
case DirectionalDimension::longitudinal:
return ostream << "longitudinal";
case DirectionalDimension::lateral:
return ostream << "lateral";
case DirectionalDimension::vertical:
return ostream << "vertical";
default:
throw UNEXPECTED_ENUMERATION_VALUE_ASSIGNED(DirectionalDimension, datum);
}
}
};
} // namespace syntax
} // namespace openscenario_interpreter

#endif // OPENSCENARIO_INTERPRETER__SYNTAX__DIRECTIONAL_DIMENSION_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -108,43 +108,43 @@ struct DistanceCondition : private Scope, private SimulatorCore::ConditionEvalua

std::vector<std::valarray<double>> results; // for description

const bool consider_z;

explicit DistanceCondition(const pugi::xml_node &, Scope &, const TriggeringEntities &);

auto description() const -> std::string;

auto distance(const EntityRef &) const -> double;

template <
CoordinateSystem::value_type, RelativeDistanceType::value_type, RoutingAlgorithm::value_type,
Boolean::value_type>
auto distance(const EntityRef &) const -> double
static auto distance(const EntityRef &, const Position &) -> double
{
throw SyntaxError(__FILE__, ":", __LINE__);
}

static auto evaluate(
const Entities *, const EntityRef &, const Position &, CoordinateSystem, RelativeDistanceType,
RoutingAlgorithm, Boolean) -> double;

auto evaluate() -> Object;
};

// Ignore spell miss due to OpenSCENARIO standard.
// cspell: ignore euclidian

// clang-format off
template <> auto DistanceCondition::distance<CoordinateSystem::entity, RelativeDistanceType::euclidianDistance, RoutingAlgorithm::undefined, false>(const EntityRef &) const -> double;
template <> auto DistanceCondition::distance<CoordinateSystem::entity, RelativeDistanceType::euclidianDistance, RoutingAlgorithm::undefined, true >(const EntityRef &) const -> double;
template <> auto DistanceCondition::distance<CoordinateSystem::entity, RelativeDistanceType::lateral, RoutingAlgorithm::undefined, false>(const EntityRef &) const -> double;
template <> auto DistanceCondition::distance<CoordinateSystem::entity, RelativeDistanceType::lateral, RoutingAlgorithm::undefined, true >(const EntityRef &) const -> double;
template <> auto DistanceCondition::distance<CoordinateSystem::entity, RelativeDistanceType::longitudinal, RoutingAlgorithm::undefined, false>(const EntityRef &) const -> double;
template <> auto DistanceCondition::distance<CoordinateSystem::entity, RelativeDistanceType::longitudinal, RoutingAlgorithm::undefined, true >(const EntityRef &) const -> double;
template <> auto DistanceCondition::distance<CoordinateSystem::lane, RelativeDistanceType::lateral, RoutingAlgorithm::undefined, false>(const EntityRef &) const -> double;
template <> auto DistanceCondition::distance<CoordinateSystem::lane, RelativeDistanceType::lateral, RoutingAlgorithm::undefined, true >(const EntityRef &) const -> double;
template <> auto DistanceCondition::distance<CoordinateSystem::lane, RelativeDistanceType::longitudinal, RoutingAlgorithm::undefined, false>(const EntityRef &) const -> double;
template <> auto DistanceCondition::distance<CoordinateSystem::lane, RelativeDistanceType::longitudinal, RoutingAlgorithm::undefined, true >(const EntityRef &) const -> double;
template <> auto DistanceCondition::distance<CoordinateSystem::lane, RelativeDistanceType::lateral, RoutingAlgorithm::shortest, false>(const EntityRef &) const -> double;
template <> auto DistanceCondition::distance<CoordinateSystem::lane, RelativeDistanceType::lateral, RoutingAlgorithm::shortest, true >(const EntityRef &) const -> double;
template <> auto DistanceCondition::distance<CoordinateSystem::lane, RelativeDistanceType::longitudinal, RoutingAlgorithm::shortest, false>(const EntityRef &) const -> double;
template <> auto DistanceCondition::distance<CoordinateSystem::lane, RelativeDistanceType::longitudinal, RoutingAlgorithm::shortest, true >(const EntityRef &) const -> double;
template <> auto DistanceCondition::distance<CoordinateSystem::entity, RelativeDistanceType::euclidianDistance, RoutingAlgorithm::undefined, false>(const EntityRef &, const Position &) -> double;
template <> auto DistanceCondition::distance<CoordinateSystem::entity, RelativeDistanceType::euclidianDistance, RoutingAlgorithm::undefined, true >(const EntityRef &, const Position &) -> double;
template <> auto DistanceCondition::distance<CoordinateSystem::entity, RelativeDistanceType::lateral, RoutingAlgorithm::undefined, false>(const EntityRef &, const Position &) -> double;
template <> auto DistanceCondition::distance<CoordinateSystem::entity, RelativeDistanceType::lateral, RoutingAlgorithm::undefined, true >(const EntityRef &, const Position &) -> double;
template <> auto DistanceCondition::distance<CoordinateSystem::entity, RelativeDistanceType::longitudinal, RoutingAlgorithm::undefined, false>(const EntityRef &, const Position &) -> double;
template <> auto DistanceCondition::distance<CoordinateSystem::entity, RelativeDistanceType::longitudinal, RoutingAlgorithm::undefined, true >(const EntityRef &, const Position &) -> double;
template <> auto DistanceCondition::distance<CoordinateSystem::lane, RelativeDistanceType::lateral, RoutingAlgorithm::undefined, false>(const EntityRef &, const Position &) -> double;
template <> auto DistanceCondition::distance<CoordinateSystem::lane, RelativeDistanceType::lateral, RoutingAlgorithm::undefined, true >(const EntityRef &, const Position &) -> double;
template <> auto DistanceCondition::distance<CoordinateSystem::lane, RelativeDistanceType::longitudinal, RoutingAlgorithm::undefined, false>(const EntityRef &, const Position &) -> double;
template <> auto DistanceCondition::distance<CoordinateSystem::lane, RelativeDistanceType::longitudinal, RoutingAlgorithm::undefined, true >(const EntityRef &, const Position &) -> double;
template <> auto DistanceCondition::distance<CoordinateSystem::lane, RelativeDistanceType::lateral, RoutingAlgorithm::shortest, false>(const EntityRef &, const Position &) -> double;
template <> auto DistanceCondition::distance<CoordinateSystem::lane, RelativeDistanceType::lateral, RoutingAlgorithm::shortest, true >(const EntityRef &, const Position &) -> double;
template <> auto DistanceCondition::distance<CoordinateSystem::lane, RelativeDistanceType::longitudinal, RoutingAlgorithm::shortest, false>(const EntityRef &, const Position &) -> double;
template <> auto DistanceCondition::distance<CoordinateSystem::lane, RelativeDistanceType::longitudinal, RoutingAlgorithm::shortest, true >(const EntityRef &, const Position &) -> double;
// clang-format on
} // namespace syntax
} // namespace openscenario_interpreter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,24 @@ namespace openscenario_interpreter
{
inline namespace syntax
{
/* ---- Entities ---------------------------------------------------------------
*
* <xsd:complexType name="Entities">
* <xsd:sequence>
* <xsd:element name="ScenarioObject" minOccurs="0" maxOccurs="unbounded" type="ScenarioObject"/>
* <xsd:element name="EntitySelection" minOccurs="0" maxOccurs="unbounded" type="EntitySelection"/>
* </xsd:sequence>
* </xsd:complexType>
*
* -------------------------------------------------------------------------- */
struct Entities : public std::unordered_map<std::string, Object> // TODO to be data member
/*
Entities (OpenSCENARIO XML 1.3)

Definition of entities (scenario objects or entity selections) in
a scenario.

<xsd:complexType name="Entities">
<xsd:sequence>
<xsd:element name="ScenarioObject" type="ScenarioObject" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="EntitySelection" type="EntitySelection" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
*/
struct Entities : private std::unordered_map<std::string, Object>
{
using std::unordered_map<std::string, Object>::begin;
using std::unordered_map<std::string, Object>::end;

explicit Entities(const pugi::xml_node &, Scope &);

auto isAdded(const Entity &) const -> bool;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ struct ReachPositionCondition : private SimulatorCore::CoordinateSystemConversio

std::vector<std::valarray<double>> results; // for description

const bool consider_z;

explicit ReachPositionCondition(const pugi::xml_node &, Scope &, const TriggeringEntities &);

auto description() const -> String;
Expand Down
Loading
Loading