|
| 1 | +/* |
| 2 | + * Copyright 2024 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 | + * \file external_printer.cpp |
| 20 | + */ |
| 21 | + |
| 22 | +#include <cassert> // for assert |
| 23 | + |
| 24 | +#include <cloe/component/object_sensor.hpp> // for ObjectSensor |
| 25 | +#include <cloe/controller.hpp> // for Controller, ControllerFactory, ... |
| 26 | +#include <cloe/models.hpp> // for CloeComponent |
| 27 | +#include <cloe/plugin.hpp> // for EXPORT_CLOE_PLUGIN |
| 28 | +#include <cloe/sync.hpp> // for Sync |
| 29 | +#include <cloe/vehicle.hpp> // for Vehicle |
| 30 | + |
| 31 | +namespace external { |
| 32 | + |
| 33 | +struct ExternalPrinterConf : public cloe::Confable { |
| 34 | + CONFABLE_FRIENDS(ExternalPrinterConf) |
| 35 | +}; |
| 36 | + |
| 37 | +class ExternalPrinter : public cloe::Controller { |
| 38 | + public: |
| 39 | + using Controller::Controller; |
| 40 | + |
| 41 | + void reset() override { |
| 42 | + // Nothing to do here. |
| 43 | + } |
| 44 | + |
| 45 | + void abort() override { |
| 46 | + // Nothing to do here. |
| 47 | + } |
| 48 | + |
| 49 | + cloe::Duration process(const cloe::Sync& sync) override { |
| 50 | + assert(veh_ != nullptr); |
| 51 | + auto log = this->logger(); |
| 52 | + log->info("External Step {} @ {}", sync.step(), sync.time().count()); |
| 53 | + if (veh_->has(cloe::CloeComponent::DEFAULT_WORLD_SENSOR)) { |
| 54 | + auto sensor = veh_->get<cloe::ObjectSensor>(cloe::CloeComponent::DEFAULT_WORLD_SENSOR); |
| 55 | + auto& objs = sensor->sensed_objects(); |
| 56 | + log->info(" {} Objects", objs.size()); |
| 57 | + for (auto o : objs) { |
| 58 | + log->info(" id={} pos=({:3f}, {:3f}, {:3f})", o->id, o->pose.translation()(0), |
| 59 | + o->pose.translation()(1), o->pose.translation()(2)); |
| 60 | + } |
| 61 | + } |
| 62 | + return sync.time(); |
| 63 | + } |
| 64 | +}; |
| 65 | + |
| 66 | +DEFINE_CONTROLLER_FACTORY(ExternalPrinterFactory, ExternalPrinterConf, "external_printer", |
| 67 | + "print a lot of information") |
| 68 | + |
| 69 | +std::unique_ptr<cloe::Controller> ExternalPrinterFactory::make(const cloe::Conf&) const { |
| 70 | + return std::make_unique<ExternalPrinter>(this->name()); |
| 71 | +} |
| 72 | + |
| 73 | +} // namespace external |
| 74 | + |
| 75 | +// Register factory as plugin entrypoint |
| 76 | +EXPORT_CLOE_PLUGIN(external::ExternalPrinterFactory) |
0 commit comments