$darkmode
minimator.hpp
1 /*
2  * Copyright 2023 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  */
18 
19 #include <cloe/core/fable.hpp> // for Confable, Schema, ...
20 
21 namespace minimator {
22 
23 struct ObjectPosition : public cloe::Confable {
24  double x{0.0};
25  double y{0.0};
26  double z{0.0};
27 
28  public:
29  CONFABLE_SCHEMA(ObjectPosition) {
30  return cloe::Schema{
31  {"x", cloe::Schema(&x, "Object position x axis")},
32  {"y", cloe::Schema(&y, "Object position y axis")},
33  {"z", cloe::Schema(&z, "Object position z axis")},
34  };
35  }
36 };
37 
38 struct ObjectConfig : public cloe::Confable {
39  double velocity{0.0};
40  ObjectPosition position;
41 
42  public:
43  CONFABLE_SCHEMA(ObjectConfig) {
44  return cloe::Schema{
45  {"velocity", cloe::Schema(&velocity, "Object longitudinal velocity")},
46  {"position", cloe::Schema(&position, "Object position coordinates (x,y,z)")},
47  };
48  }
49 };
50 
52  std::vector<ObjectConfig> objects;
53 
54  public:
55  CONFABLE_SCHEMA(ObjectSensorConfig) {
56  // clang-format off
57  return cloe::Schema{
58  {"objects", cloe::Schema(&objects, "Array of object configuration relative to ego vehicle")},
59  };
60  // clang-format on
61  }
62 };
63 
65  ObjectConfig ego_object;
66 
67  public:
68  CONFABLE_SCHEMA(EgoSensorConfig) {
69  return cloe::Schema{
70  {"ego_object", cloe::Schema(&ego_object, "Ego object configuration in world coordinates")},
71  };
72  }
73 };
74 
76  EgoSensorConfig ego_sensor_mockup;
77  ObjectSensorConfig object_sensor_mockup;
78 
79  public:
80  CONFABLE_SCHEMA(SensorMockupConfig) {
81  // clang-format off
82  return cloe::Schema{
83  {"ego_sensor_mockup", cloe::Schema(&ego_sensor_mockup, "Ego sensor mockup configuration")},
84  {"object_sensor_mockup", cloe::Schema(&object_sensor_mockup, "Object sensor mockup configuration")},
85  };
86  // clang-format on
87  }
88 };
89 
121  std::map<std::string, SensorMockupConfig> vehicles;
122  // The `CONFABLE_SCHEMA` is simple enough and is the recommended way to
123  // augment a class that inherits from `Confable` to expose `from_conf`,
124  // `from_json`, and `to_json` methods. The `Schema` type is a sort of
125  // polymorphic type that automatically derives a JSON schema from a set of
126  // pointers. This schema is used to provide serialization and deserialization.
127  //
128  // \see fable/confable.hpp
129  // \see fable/schema.hpp
130  //
131  public:
132  CONFABLE_SCHEMA(MinimatorConfiguration) {
133  // For us, each `Schema` describing a `Confable` will start with an
134  // initializer list of pairs: this describes a JSON object. Each property in
135  // this object may be another object or another primitive JSON type.
136  // In this configuration, we want to deserialize into a vector of strings.
137  //
138  // `Schema` contains some magic to make it "easy" for you to use.
139  // The following eventually boils down to:
140  //
141  // fable::schema::Struct{
142  // {
143  // "vehicles",
144  // fable::schema::map<std::string, minimator::SensorMockupConfig>(
145  // &vehicles,
146  // "list of vehicle names to make available"
147  // )
148  // }
149  // }
150  //
151  // You can hopefully see why `Schema` contains the magic it contains.
152  return cloe::Schema{
153  {"vehicles", cloe::Schema(&vehicles, "list of vehicle names to make available")},
154  };
155  }
156 };
157 
158 }
Definition: confable.hpp:98
Definition: schema.hpp:173
Definition: minimator.hpp:64
Definition: minimator.hpp:120
Definition: minimator.hpp:38
Definition: minimator.hpp:23
Definition: minimator.hpp:51
Definition: minimator.hpp:75