$darkmode
osi_sensor_component.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  */
23 #pragma once
24 
25 #include <memory> // for shared_ptr<>, unique_ptr<>
26 #include <string> // for string, to_string
27 
28 #include <Eigen/Geometry> // for Isometry3d, Vector3d
29 
30 #include <cloe/component/object.hpp> // for Object
31 #include <cloe/utility/geometry.hpp> // for quaternion_from_rpy
32 
33 #include "osi_omni_sensor.hpp" // for OsiOmniSensor
34 #include "osi_transceiver.hpp" // for OsiTransceiver
35 
36 #include "vtd_conf.hpp" // for VtdSensorConfig
37 #include "vtd_sensor_data.hpp" // for VtdSensorData
38 
39 namespace vtd {
40 
49  public:
50  virtual ~VtdOsiSensor() = default;
51 
52  VtdOsiSensor(std::unique_ptr<osii::OsiTransceiver>&& osi_transceiver, uint64_t owner_id)
53  : OsiOmniSensor(std::move(osi_transceiver), owner_id), VtdSensorData("osi_sensor") {
54  ego_object_ = std::make_shared<cloe::Object>(); // NOLINT
55  }
56 
57  void configure(const VtdSensorConfig& cfg);
58 
59  void step(const cloe::Sync& s) override {
60  this->clear_cache();
61  OsiOmniSensor::step(s, restart_, simulation_time_);
62  }
63 
64  void store_object(std::shared_ptr<cloe::Object> obj) override { world_objects_.push_back(obj); }
65 
66  void store_lane_boundary(const cloe::LaneBoundary& lb) override { lanes_[lb.id] = lb; }
67 
68  void store_ego_object(std::shared_ptr<cloe::Object> ego_obj) override { ego_object_ = ego_obj; }
69 
70  void store_sensor_meta_data(const Eigen::Vector3d& bbcenter_to_veh_origin,
71  const Eigen::Vector3d& ego_dimensions) override {
73  Eigen::Vector3d translation = osi_sensor_pose_.translation();
74  // Correct for the difference in reference frame z-location.
75  translation(2) = translation(2) + (0.5 * ego_dimensions(2) + bbcenter_to_veh_origin(2));
76  mount_.translation() = translation;
77  }
78 
83  Eigen::Isometry3d get_static_mounting_position(const Eigen::Vector3d& bbcenter_to_veh_origin,
84  const Eigen::Vector3d& ego_dimensions) override {
85  // VTD2.2: rotation order: "dhDeg (z-axis), dpDeg (y*-axis) and drDeg
86  // (x**-axis). Each rotation is performed in the system resulting from the
87  // previous rotation."
88  // OSI3 rotation order: "yaw first (around the z-axis), pitch second (around
89  // the new y-axis) and roll third (around the new x-axis)"
90  Eigen::Quaterniond quaternion = cloe::utility::quaternion_from_rpy(
91  vtd_mnt_ori_drpy_(0), vtd_mnt_ori_drpy_(1), vtd_mnt_ori_drpy_(2));
92  Eigen::Vector3d translation = vtd_mnt_pos_dxyz_;
93  // Correct for the difference in reference frame z-location:
94  // VTD: ground level; OSI: rear axle center.
95  translation(2) = translation(2) - (0.5 * ego_dimensions(2) + bbcenter_to_veh_origin(2));
96  return cloe::utility::pose_from_rotation_translation(quaternion, translation);
97  }
98 
102  void set_mock_conf(std::shared_ptr<const osii::SensorMockConf> mock) override {
103  this->mock_ = mock;
104  }
105 
106  // As defined in `cloe/component.hpp`
107  void reset() override {
108  clear_cache();
109  this->set_reset_state();
110  }
111 
112  friend void to_json(cloe::Json& j, const VtdOsiSensor& s) {
113  to_json(j, static_cast<const VtdSensorData&>(s));
114  j = cloe::Json{
115  {"osi_connection", s.osi_comm_},
116  };
117  }
118 
119  protected:
121  Eigen::Vector3d vtd_mnt_pos_dxyz_; // [m]
122  Eigen::Vector3d vtd_mnt_ori_drpy_; // [rad]
123 };
124 
125 } // namespace vtd
Definition: lane_boundary.hpp:36
Definition: sync.hpp:34
Definition: osi_omni_sensor.hpp:166
std::unique_ptr< OsiTransceiver > osi_comm_
Definition: osi_omni_sensor.hpp:293
Eigen::Isometry3d osi_sensor_pose_
Store sensor pose relative to the ego frame (rear axle center, not ground level).
Definition: osi_omni_sensor.hpp:305
std::shared_ptr< const SensorMockConf > mock_
Use alternative source for required data or overwrite incoming data, if requested.
Definition: osi_omni_sensor.hpp:311
Definition: osi_sensor_component.hpp:48
void store_object(std::shared_ptr< cloe::Object > obj) override
Definition: osi_sensor_component.hpp:64
Eigen::Isometry3d get_static_mounting_position(const Eigen::Vector3d &bbcenter_to_veh_origin, const Eigen::Vector3d &ego_dimensions) override
Definition: osi_sensor_component.hpp:83
void store_sensor_meta_data(const Eigen::Vector3d &bbcenter_to_veh_origin, const Eigen::Vector3d &ego_dimensions) override
Definition: osi_sensor_component.hpp:70
void set_mock_conf(std::shared_ptr< const osii::SensorMockConf > mock) override
Definition: osi_sensor_component.hpp:102
Eigen::Vector3d vtd_mnt_pos_dxyz_
Sensor mounting position obtained from config (in VTD vehicle coordinate frame).
Definition: osi_sensor_component.hpp:121
void reset() override
Definition: osi_sensor_component.hpp:107
void store_ego_object(std::shared_ptr< cloe::Object > ego_obj) override
Definition: osi_sensor_component.hpp:68
void store_lane_boundary(const cloe::LaneBoundary &lb) override
Definition: osi_sensor_component.hpp:66
void step(const cloe::Sync &s) override
Definition: osi_sensor_component.hpp:59
Definition: vtd_sensor_data.hpp:39
Eigen::Isometry3d mount_
Sensor mounting position and orientation.
Definition: vtd_sensor_data.hpp:121
std::shared_ptr< cloe::Object > ego_object_
ego object information from last processed frame.
Definition: vtd_sensor_data.hpp:130
bool restart_
Indicates whether reset has been requested.
Definition: vtd_sensor_data.hpp:115
virtual void set_reset_state()
Definition: vtd_sensor_data.hpp:79
cloe::Duration simulation_time_
Simulation time from last processed sensor message.
Definition: vtd_sensor_data.hpp:118
cloe::Objects world_objects_
World objects from last processed frame.
Definition: vtd_sensor_data.hpp:127
cloe::LaneBoundaries lanes_
Lane id-to-boundary-map.
Definition: vtd_sensor_data.hpp:136