From 09e14fdaeb49a0ec23b52525a2576525f59afed1 Mon Sep 17 00:00:00 2001 From: Matthias Schleicher Date: Wed, 5 Oct 2022 13:59:59 +0200 Subject: [PATCH] models: Add brake, steering, wheel, and powertrain sensors This just extends the package with extra components and is therefore backwards compatible --- .../include/cloe/component/brake_sensor.hpp | 70 ++++++++++++ .../cloe/component/powertrain_sensor.hpp | 90 ++++++++++++++++ .../cloe/component/steering_sensor.hpp | 69 ++++++++++++ models/include/cloe/component/wheel.hpp | 51 +++++++++ .../include/cloe/component/wheel_sensor.hpp | 100 ++++++++++++++++++ models/include/cloe/models.hpp | 16 +++ 6 files changed, 396 insertions(+) create mode 100644 models/include/cloe/component/brake_sensor.hpp create mode 100644 models/include/cloe/component/powertrain_sensor.hpp create mode 100644 models/include/cloe/component/steering_sensor.hpp create mode 100644 models/include/cloe/component/wheel.hpp create mode 100644 models/include/cloe/component/wheel_sensor.hpp diff --git a/models/include/cloe/component/brake_sensor.hpp b/models/include/cloe/component/brake_sensor.hpp new file mode 100644 index 000000000..e285284a7 --- /dev/null +++ b/models/include/cloe/component/brake_sensor.hpp @@ -0,0 +1,70 @@ +/* + * Copyright 2022 Robert Bosch GmbH + * + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +/** + * \file cloe/component/brake_sensor.hpp + */ + +#pragma once +#ifndef CLOE_COMPONENT_BRAKE_SENSOR_HPP_ +#define CLOE_COMPONENT_BRAKE_SENSOR_HPP_ + +#include // for Component, Json + +namespace cloe { + +class BrakeSensor : public Component { + public: + using Component::Component; + BrakeSensor() : Component("brake_sensor") {} + virtual ~BrakeSensor() noexcept = default; + + /** + * Return the position of the brake pedal with no unit. + * + * The range goes from 0 (unpressed) to 1 (fully pressed). + */ + virtual double pedal_position_brake() const = 0; + + /** + * Return sensor state as JSON. + */ + Json active_state() const override { + return Json{{"pedal_position_brake", pedal_position_brake()}}; + } +}; + +/** + * NopBrakeSensor is an example no-op implementation of BrakeSensor. + */ +class NopBrakeSensor : public BrakeSensor { + public: + using BrakeSensor::BrakeSensor; + NopBrakeSensor() : BrakeSensor("nop_brake_sensor") {} + virtual ~NopBrakeSensor() noexcept {}; + + double pedal_position_brake() const override { return pedal_position_brake_; } + + void reset() override { pedal_position_brake_ = 0.0; } + + protected: + double pedal_position_brake_{0.0}; +}; + +} // namespace cloe + +#endif // CLOE_COMPONENT_BRAKE_SENSOR_HPP_ diff --git a/models/include/cloe/component/powertrain_sensor.hpp b/models/include/cloe/component/powertrain_sensor.hpp new file mode 100644 index 000000000..56b446e6e --- /dev/null +++ b/models/include/cloe/component/powertrain_sensor.hpp @@ -0,0 +1,90 @@ +/* + * Copyright 2022 Robert Bosch GmbH + * + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +/** + * \file cloe/component/powertrain_sensor.hpp + */ + +#pragma once +#ifndef CLOE_COMPONENT_POWERTRAIN_SENSOR_HPP_ +#define CLOE_COMPONENT_POWERTRAIN_SENSOR_HPP_ + +#include // for Component, Json + +namespace cloe { + +class PowertrainSensor : public Component { + public: + using Component::Component; + PowertrainSensor() : Component("powertrain_sensor") {} + virtual ~PowertrainSensor() noexcept = default; + + /** + * Return the position of the acceleration pedal with no unit. + * + * The range goes from 0 (unpressed) to 1 (fully pressed). + */ + virtual double pedal_position_acceleration() const = 0; + + /** + * Return the gear transmission. + * + * The sign of this field is linked to the mode of the gear + * - positive: driving forward (e.g. a value of 3 means the third gear in driving forward mode) + * - 0: means that the gear lever is in neutral position + * - negative: reverse mode (e.g. a value of -1 means the first gear in reverse mode) + * - int max: means that the transmission is in parking position (can be accessed via std::numeric_limits::max()) + */ + virtual int gear_transmission() const = 0; + + /** + * Return sensor state as JSON. + */ + Json active_state() const override { + return Json{ + {"pedal_position_acceleration", pedal_position_acceleration()}, + {"gear_transmission", gear_transmission()}, + }; + } +}; + +/** + * NopPowertrainSensor is an example no-op implementation of PowertrainSensor. + */ +class NopPowertrainSensor : public PowertrainSensor { + public: + using PowertrainSensor::PowertrainSensor; + NopPowertrainSensor() : PowertrainSensor("nop_powertrain_sensor") {} + virtual ~NopPowertrainSensor() noexcept {}; + + double pedal_position_acceleration() const override { return pedal_position_acceleration_; } + + int gear_transmission() const override { return gear_transmission_; } + + void reset() override { + pedal_position_acceleration_ = 0.0; + gear_transmission_ = 0; + } + + protected: + double pedal_position_acceleration_{0.0}; + int gear_transmission_{0}; +}; + +} // namespace cloe + +#endif // CLOE_COMPONENT_POWERTRAIN_SENSOR_HPP_ diff --git a/models/include/cloe/component/steering_sensor.hpp b/models/include/cloe/component/steering_sensor.hpp new file mode 100644 index 000000000..d2249117d --- /dev/null +++ b/models/include/cloe/component/steering_sensor.hpp @@ -0,0 +1,69 @@ +/* + * Copyright 2022 Robert Bosch GmbH + * + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +/** + * \file cloe/component/steering_sensor.hpp + */ + +#pragma once +#ifndef CLOE_COMPONENT_STEERING_SENSOR_HPP_ +#define CLOE_COMPONENT_STEERING_SENSOR_HPP_ + +#include // for Component, Json + +namespace cloe { + +class SteeringSensor : public Component { + public: + using Component::Component; + SteeringSensor() : Component("steering_sensor") {} + virtual ~SteeringSensor() noexcept = default; + + /** + * Return curvature of ego vehicle track in [1/m]. + */ + virtual double curvature() const = 0; + + /** + * Return sensor state as JSON. + */ + Json active_state() const override { + return Json{ + {"curvature", curvature()}, + }; + } +}; + +/** + * NopSteeringSensor is an example no-op implementation of SteeringSensor. + */ +class NopSteeringSensor : public SteeringSensor { + public: + using SteeringSensor::SteeringSensor; + NopSteeringSensor() : SteeringSensor("nop_steering_sensor") {} + virtual ~NopSteeringSensor() noexcept {}; + + double curvature() const override { return curvature_; } + void reset() override { curvature_ = 0.0; } + + protected: + double curvature_{0.0}; +}; + +} // namespace cloe + +#endif // CLOE_COMPONENT_STEERING_SENSOR_HPP_ diff --git a/models/include/cloe/component/wheel.hpp b/models/include/cloe/component/wheel.hpp new file mode 100644 index 000000000..a290d6d86 --- /dev/null +++ b/models/include/cloe/component/wheel.hpp @@ -0,0 +1,51 @@ +/* + * Copyright 2022 Robert Bosch GmbH + * + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +/** + * \file cloe/component/wheel.hpp + */ + +#pragma once +#ifndef CLOE_COMPONENT_WHEEL_HPP_ +#define CLOE_COMPONENT_WHEEL_HPP_ + +#include // for to_json + +namespace cloe { + +struct Wheel { + /// Rotational angle of wheel around y-axis in [rad]. + double rotation{0.0}; + + /// Translative velocity of the wheel in [m/s]. + double velocity{0.0}; + + /// Compression of the spring in [m]. + double spring_compression{0.0}; + + friend void to_json(Json& j, const Wheel& w) { + j = Json{ + {"rotation", w.rotation}, + {"velocity", w.velocity}, + {"spring_compression", w.spring_compression}, + }; + } +}; + +} // namespace cloe + +#endif // CLOE_COMPONENT_WHEEL_HPP_ diff --git a/models/include/cloe/component/wheel_sensor.hpp b/models/include/cloe/component/wheel_sensor.hpp new file mode 100644 index 000000000..df8fbf030 --- /dev/null +++ b/models/include/cloe/component/wheel_sensor.hpp @@ -0,0 +1,100 @@ +/* + * Copyright 2022 Robert Bosch GmbH + * + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +/** + * \file cloe/component/wheel_sensor.hpp + */ + +#pragma once +#ifndef CLOE_COMPONENT_WHEEL_SENSOR_HPP_ +#define CLOE_COMPONENT_WHEEL_SENSOR_HPP_ + +#include // for Component, Json +#include // for Wheel + +namespace cloe { + +class WheelSensor : public Component { + public: + using Component::Component; + WheelSensor() : Component("wheel_sensor") {} + virtual ~WheelSensor() noexcept = default; + + /** + * Return front left wheel. + */ + virtual Wheel wheel_fl() const = 0; + + /** + * Return front right wheel. + */ + virtual Wheel wheel_fr() const = 0; + + /** + * Return rear left wheel. + */ + virtual Wheel wheel_rl() const = 0; + + /** + * Return rear right wheel. + */ + virtual Wheel wheel_rr() const = 0; + + /** + * Return sensor state as JSON. + */ + Json active_state() const override { + return Json{ + {"wheel_fl", wheel_fl()}, + {"wheel_fr", wheel_fr()}, + {"wheel_rl", wheel_rl()}, + {"wheel_rr", wheel_rr()}, + }; + } +}; + +/** + * NopWheelSensor is an example no-op implementation of WheelSensor. + */ +class NopWheelSensor : public WheelSensor { + public: + using WheelSensor::WheelSensor; + NopWheelSensor() : WheelSensor("nop_wheel_sensor") {} + virtual ~NopWheelSensor() noexcept {}; + + Wheel wheel_fl() const override { return wheel_fl_; }; + Wheel wheel_fr() const override { return wheel_fr_; }; + Wheel wheel_rl() const override { return wheel_rl_; }; + Wheel wheel_rr() const override { return wheel_rr_; }; + + void reset() override { + wheel_fl_ = Wheel(); + wheel_fr_ = Wheel(); + wheel_rl_ = Wheel(); + wheel_rr_ = Wheel(); + } + + protected: + Wheel wheel_fl_{}; + Wheel wheel_fr_{}; + Wheel wheel_rl_{}; + Wheel wheel_rr_{}; +}; + +} // namespace cloe + +#endif // CLOE_COMPONENT_WHEEL_SENSOR_HPP_ diff --git a/models/include/cloe/models.hpp b/models/include/cloe/models.hpp index 173de2f10..720345aff 100644 --- a/models/include/cloe/models.hpp +++ b/models/include/cloe/models.hpp @@ -32,12 +32,20 @@ namespace cloe { enum class CloeComponent { // Groundtruth sensors should never be modified/replaced. GROUNDTRUTH_EGO_SENSOR, + GROUNDTRUTH_POWERTRAIN_SENSOR, + GROUNDTRUTH_BRAKE_SENSOR, + GROUNDTRUTH_WHEEL_SENSOR, + GROUNDTRUTH_STEERING_SENSOR, GROUNDTRUTH_WORLD_SENSOR, GROUNDTRUTH_LANE_SENSOR, GROUNDTRUTH_TRAFFIC_SIGN_SENSOR, // Default sensors are initially the same as the ground truth sensors DEFAULT_EGO_SENSOR, + DEFAULT_POWERTRAIN_SENSOR, + DEFAULT_BRAKE_SENSOR, + DEFAULT_WHEEL_SENSOR, + DEFAULT_STEERING_SENSOR, DEFAULT_WORLD_SENSOR, DEFAULT_LANE_SENSOR, DEFAULT_TRAFFIC_SIGN_SENSOR, @@ -57,11 +65,19 @@ enum class CloeComponent { ENUM_SERIALIZATION(CloeComponent, ({ // Groundtruth sensors {CloeComponent::GROUNDTRUTH_EGO_SENSOR, "cloe::gndtruth_ego_sensor"}, + {CloeComponent::GROUNDTRUTH_POWERTRAIN_SENSOR, "cloe::gndtruth_powertrain_sensor"}, + {CloeComponent::GROUNDTRUTH_BRAKE_SENSOR, "cloe::gndtruth_brake_sensor"}, + {CloeComponent::GROUNDTRUTH_WHEEL_SENSOR, "cloe::gndtruth_wheel_sensor"}, + {CloeComponent::GROUNDTRUTH_STEERING_SENSOR, "cloe::gndtruth_steering_sensor"}, {CloeComponent::GROUNDTRUTH_WORLD_SENSOR, "cloe::gndtruth_world_sensor"}, {CloeComponent::GROUNDTRUTH_LANE_SENSOR, "cloe::gndtruth_lane_sensor"}, // Default sensors {CloeComponent::DEFAULT_EGO_SENSOR, "cloe::default_ego_sensor"}, + {CloeComponent::DEFAULT_POWERTRAIN_SENSOR, "cloe::default_powertrain_sensor"}, + {CloeComponent::DEFAULT_BRAKE_SENSOR, "cloe::default_brake_sensor"}, + {CloeComponent::DEFAULT_WHEEL_SENSOR, "cloe::default_wheel_sensor"}, + {CloeComponent::DEFAULT_STEERING_SENSOR, "cloe::default_steering_sensor"}, {CloeComponent::DEFAULT_WORLD_SENSOR, "cloe::default_world_sensor"}, {CloeComponent::DEFAULT_LANE_SENSOR, "cloe::default_lane_sensor"},