Apollo  6.0
Open source self driving car software
perception_camera_updater.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2019 The Apollo Authors. All Rights Reserved.
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 
17 #pragma once
18 
19 #include <deque>
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 #include "Eigen/Dense"
25 
26 #include "cyber/cyber.h"
28 #include "modules/dreamview/proto/camera_update.pb.h"
29 #include "modules/drivers/proto/sensor_image.pb.h"
30 #include "modules/localization/proto/localization.pb.h"
31 #include "modules/localization/proto/pose.pb.h"
33 #include "modules/transform/proto/transform.pb.h"
34 
35 namespace apollo {
36 namespace dreamview {
37 
39  public:
47  explicit PerceptionCameraUpdater(WebSocketHandler *websocket);
48 
49  void Start();
50  void Stop();
51 
52  bool IsEnabled() const { return enabled_; }
53 
54  void GetUpdate(std::string *camera_update);
55 
56  private:
57  static constexpr double kImageScale = 0.6;
58 
59  void InitReaders();
60  void OnImage(const std::shared_ptr<apollo::drivers::CompressedImage> &image);
61  void OnLocalization(
62  const std::shared_ptr<apollo::localization::LocalizationEstimate> &loc);
63 
69  void GetImageLocalization(std::vector<double> *localization);
70 
72  bool QueryStaticTF(const std::string &frame_id,
73  const std::string &child_frame_id,
74  Eigen::Matrix4d *matrix);
75  void GetLocalization2CameraTF(std::vector<double> *localization2camera_tf);
76 
77  WebSocketHandler *websocket_;
78  CameraUpdate camera_update_;
79 
80  bool enabled_ = false;
81  double current_image_timestamp_;
82 
83  std::unique_ptr<cyber::Node> node_;
84 
85  std::deque<std::shared_ptr<apollo::localization::LocalizationEstimate>>
86  localization_queue_;
87  std::vector<uint8_t> image_buffer_;
88  std::vector<double> tf_static_;
89 
90  std::mutex image_mutex_;
91  std::mutex localization_mutex_;
92 };
93 
94 } // namespace dreamview
95 } // namespace apollo
bool IsEnabled() const
Definition: perception_camera_updater.h:52
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Eigen::Matrix4d Matrix4d
Definition: base_map_fwd.h:32
PerceptionCameraUpdater(WebSocketHandler *websocket)
Definition: perception_camera_updater.h:38
Definition: buffer.h:33
The WebSocketHandler, built on top of CivetWebSocketHandler, is a websocket handler that handles diff...
Definition: websocket_handler.h:46
void GetUpdate(std::string *camera_update)