predictor.h 3.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
/******************************************************************************
 * Copyright 2018 The Apollo Authors. All Rights Reserved.
 *
 * 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.
 *****************************************************************************/

/**
 * @file predictor.h
 * @brief The class of Predictor.
 */

#ifndef MODULES_LOCALIZATION_LMD_COMMON_PREDICTOR_PREDICTOR_H_
#define MODULES_LOCALIZATION_LMD_COMMON_PREDICTOR_PREDICTOR_H_

#include <map>
#include <string>
#include <utility>

#include "modules/common/log.h"
#include "modules/common/status/status.h"
#include "modules/localization/lmd/common/pose_list.h"

/**
 * @namespace apollo::localization
 * @brief apollo::localization
 */
namespace apollo {
namespace localization {

constexpr char kPredictorPrintErrorName[] = "print_error";
constexpr char kPredictorOutputName[] = "output";
constexpr char kPredictorImuName[] = "imu";
constexpr char kPredictorGpsName[] = "gps";

/**
 * @class Predictor
 *
 * @brief  Interface for implementing predictor.
 */
class Predictor {
 public:
  explicit Predictor(double memory_cycle_sec_)
      : predicted_(memory_cycle_sec_) {}

  virtual ~Predictor() {}

  /**
   * @brief Get name of the predictor.
   * @return A name.
   */
  const std::string& Name() const { return name_; }

  /**
   * @brief Get names of the deps.
   * @return Predicteds of deps.
   */
  const std::map<std::string, PoseList>& DepPredicteds() const {
    return dep_predicteds_;
  }

  /**
   * @brief Update predicted list of deps.
   */
  void UpdateDepPredicted(const std::string& name, const PoseList& predicted) {
    UpdateDepPredicted(name, PoseList(predicted));
  }

  void UpdateDepPredicted(const std::string& name, PoseList&& predicted) {
    auto it = dep_predicteds_.find(name);
    CHECK(it != dep_predicteds_.end());
    it->second = std::move(predicted);
  }

  /**
   * @brief Get predicted list.
   * @return Predicted list.
   */
  const PoseList& Predicted() const { return predicted_; }

  /**
   * @brief Is predicted running on adapter's thread.
   * @return True if yes; no otherwise.
   */
  bool UpdatingOnAdapterThread() const { return on_adapter_thread_; }

  /**
   * @brief Is predicted list updateable.
   * @return True if yes; no otherwise.
   */
  virtual bool Updateable() const = 0;

  /**
   * @brief Predict a new pose and add it to predicted list.
   * @return Status::OK() if success; error otherwise.
   */
  virtual apollo::common::Status Update() = 0;

 protected:
  std::string name_;

  std::map<std::string, PoseList> dep_predicteds_;
  PoseList predicted_;
  bool on_adapter_thread_ = false;
};

}  // namespace localization
}  // namespace apollo

#endif  // MODULES_LOCALIZATION_LMD_COMMON_PREDICTOR_PREDICTOR_H_