Apollo  6.0
Open source self driving car software
motion_service.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 #pragma once
17 
18 #include <list>
19 #include <memory>
20 #include <mutex>
21 #include <string>
22 #include <vector>
23 
24 #include "Eigen/Core"
25 
27 #include "modules/drivers/proto/sensor_image.pb.h"
28 #include "modules/localization/proto/localization.pb.h"
32 #include "modules/perception/onboard/proto/motion_service.pb.h"
33 #include "modules/perception/proto/motion_service.pb.h"
34 
35 namespace apollo {
36 namespace perception {
37 namespace camera {
38 
39 typedef std::shared_ptr<apollo::drivers::Image> ImageMsgType;
40 typedef std::shared_ptr<localization::LocalizationEstimate> LocalizationMsgType;
41 
43  public:
44  MotionService() = default;
45  virtual ~MotionService() { delete vehicle_planemotion_; }
46 
47  bool Init() override;
48  bool GetMotionInformation(double timestamp, base::VehicleStatus *vs);
50  double GetLatestTimestamp();
51 
52  private:
53  void OnLocalization(const LocalizationMsgType &localization);
54  void OnReceiveImage(const ImageMsgType &message,
55  const std::string &camera_name);
56  void PublishEvent(const double timestamp);
57  void ConvertVehicleMotionToMsgOut(
58  base::VehicleStatus vs, apollo::perception::VehicleStatus *v_status_msg);
59 
60  PlaneMotion *vehicle_planemotion_ = nullptr;
61  std::string device_id_;
62  double pre_azimuth = 0; // a invalid value
63  double pre_timestamp_ = 0;
64  double pre_camera_timestamp_ = 0;
65  double camera_timestamp_ = 0;
66  bool start_flag_ = false;
67  const int motion_buffer_size_ = 100;
68  double timestamp_offset_ = 0.0;
69 
70  std::vector<std::string> camera_names_; // camera sensor names
71  std::vector<std::string> input_camera_channel_names_;
72  std::mutex mutex_;
73  // std::mutex image_mutex_;
74  std::mutex motion_mutex_;
75  std::shared_ptr<apollo::cyber::Writer<apollo::perception::Motion_Service>>
76  writer_;
77  DISALLOW_COPY_AND_ASSIGN(MotionService);
78 };
79 
81 
82 } // namespace camera
83 } // namespace perception
84 } // namespace apollo
std::shared_ptr< localization::LocalizationEstimate > LocalizationMsgType
Definition: motion_service.h:40
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Definition: plane_motion.h:34
bool GetMotionInformation(double timestamp, base::VehicleStatus *vs)
Definition: object_supplement.h:189
Definition: motion_service.h:42
CYBER_REGISTER_COMPONENT(MotionService)
virtual ~MotionService()
Definition: motion_service.h:45
std::shared_ptr< apollo::drivers::Image > ImageMsgType
Definition: motion_service.h:39
The Component can process up to four channels of messages. The message type is specified when the com...
Definition: component.h:58
boost::circular_buffer< VehicleStatus > MotionBuffer
Definition: object_supplement.h:202