$darkmode
object.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020 Robert Bosch GmbH
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * SPDX-License-Identifier: Apache-2.0
17  */
22 #pragma once
23 
24 #include <memory> // for shared_ptr<>
25 #include <vector> // for vector<>
26 
27 #include <sol/sol.hpp> // for Lua related aspects
28 
29 #include <Eigen/Geometry> // for Isometry3d, Vector3d
30 #include <fable/enum.hpp> // for ENUM_SERIALIZATION
31 #include <fable/json.hpp> // for Json
32 #include <fable/utility/eigen.hpp> // for to_json
33 
34 namespace cloe {
35 
51 struct Object {
52  enum class Type { Unknown, Static, Dynamic };
53 
54  enum class Class { Unknown, Pedestrian, Bike, Motorbike, Car, Truck, Trailer };
55 
57  int id{-1};
58 
60  double exist_prob{1.0};
61 
63  Type type{Type::Unknown};
64 
66  Class classification{Class::Unknown};
67 
69  Eigen::Isometry3d pose{Eigen::Isometry3d()};
70 
72  Eigen::Vector3d dimensions{Eigen::Vector3d::Zero()};
73 
75  Eigen::Vector3d cog_offset{Eigen::Vector3d::Zero()};
76 
78  Eigen::Vector3d velocity{Eigen::Vector3d::Zero()};
79 
81  Eigen::Vector3d acceleration{Eigen::Vector3d::Zero()};
82 
84  Eigen::Vector3d angular_velocity{Eigen::Vector3d::Zero()};
85 
86  Object() = default;
87 
88  friend void to_json(fable::Json& j, const Object& o) {
89  j = fable::Json{
90  {"id", o.id},
91  {"exist_prob", o.exist_prob},
92  {"type", o.type},
93  {"class", o.classification},
94  {"pose", o.pose},
95  {"dimensions", o.dimensions},
96  {"cog_offset", o.cog_offset},
97  {"velocity", o.velocity},
98  {"velocity_norm", static_cast<double>(o.velocity.norm())},
99  {"acceleration", o.acceleration},
100  {"angular_velocity", o.angular_velocity},
101  };
102  }
103  friend void to_lua(sol::state_view view, Object* /* value */) {
104  sol::usertype<Object> usertype_table = view.new_usertype<Object>("Object");
105  usertype_table["id"] = &Object::id;
106  usertype_table["exist_prob"] = &Object::exist_prob;
107  usertype_table["type"] = &Object::type;
108  usertype_table["classification"] = &Object::classification;
109  usertype_table["pose"] = &Object::pose;
110  usertype_table["dimensions"] = &Object::dimensions;
111  usertype_table["cog_offset"] = &Object::cog_offset;
112  usertype_table["velocity"] = &Object::velocity;
113  usertype_table["acceleration"] = &Object::acceleration;
114  usertype_table["angular_velocity"] = &Object::angular_velocity;
115  usertype_table["ego_position"] = +[](const Object &self, const Eigen::Isometry3d &sensorMountPose) {
116  Eigen::Vector3d pos = sensorMountPose * self.pose * self.cog_offset;
117  return pos;
118  };
119  }
120 };
121 
128 using Objects = std::vector<std::shared_ptr<Object>>;
129 
130 inline void to_json(fable::Json& j, const Objects& os) {
131  j = fable::Json::array();
132  for (const auto& o : os) {
133  assert(o != nullptr);
134  j.push_back(*o);
135  }
136 }
137 
138 // clang-format off
139 ENUM_SERIALIZATION(Object::Type, ({
140  {Object::Type::Static, "static"},
141  {Object::Type::Dynamic, "dynamic"},
142  {Object::Type::Unknown, "unknown"},
143 }))
144 
145 ENUM_SERIALIZATION(Object::Class, ({
146  {Object::Class::Unknown, "unknown"},
147  {Object::Class::Pedestrian, "pedestrian"},
148  {Object::Class::Bike, "bicycle"},
149  {Object::Class::Motorbike, "motorcycle"},
150  {Object::Class::Car, "car"},
151  {Object::Class::Truck, "truck"},
152  {Object::Class::Trailer, "trailer"},
153 }))
154 // clang-format on
155 
156 } // namespace cloe
#define ENUM_SERIALIZATION(xType, xMap)
Definition: enum.hpp:51
nlohmann::json Json
Definition: fable_fwd.hpp:35
std::vector< std::shared_ptr< Object > > Objects
Definition: object.hpp:128
Definition: object.hpp:51
Eigen::Vector3d dimensions
Dimensions in [m].
Definition: object.hpp:72
Eigen::Vector3d acceleration
Absolute acceleration in [m/(s*s)].
Definition: object.hpp:81
double exist_prob
Object existence probability.
Definition: object.hpp:60
Type type
Type of object.
Definition: object.hpp:63
Eigen::Vector3d angular_velocity
Angular velocity in [rad/s].
Definition: object.hpp:84
Eigen::Vector3d cog_offset
Center of geometry offset in [m].
Definition: object.hpp:75
Class classification
Classification of object.
Definition: object.hpp:66
Eigen::Isometry3d pose
Pose in [m] and [rad].
Definition: object.hpp:69
int id
ID of object, should be unique.
Definition: object.hpp:57
Eigen::Vector3d velocity
Absolute velocity in [m/s].
Definition: object.hpp:78