Apollo  6.0
Open source self driving car software
simulation_world_updater.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2017 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 
21 #pragma once
22 
23 #include <memory>
24 #include <string>
25 
26 #include <boost/thread/locks.hpp>
27 #include <boost/thread/shared_mutex.hpp>
28 
29 #include "absl/strings/str_cat.h"
30 
31 #include "modules/routing/proto/default_routing.pb.h"
32 #include "modules/routing/proto/poi.pb.h"
33 #include "modules/task_manager/proto/task_manager.pb.h"
34 
35 #include "cyber/common/log.h"
36 #include "cyber/cyber.h"
42 
47 namespace apollo {
48 namespace dreamview {
49 
57  public:
68  WebSocketHandler *camera_ws, SimControl *sim_control,
69  const MapService *map_service,
70  PerceptionCameraUpdater *perception_camera_updater,
71  bool routing_from_file = false);
72 
76  void Start();
77 
78  // Time interval, in milliseconds, between pushing SimulationWorld to
79  // frontend.
80  static constexpr double kSimWorldTimeIntervalMs = 100;
81 
82  double LastAdcTimestampSec() { return last_pushed_adc_timestamp_sec_; }
83 
84  private:
89  void OnTimer();
90 
97  bool ConstructRoutingRequest(
98  const nlohmann::json &json,
99  apollo::routing::RoutingRequest *routing_request);
100 
101  bool ValidateCoordinate(const nlohmann::json &json);
102 
108  nlohmann::json CheckRoutingPoint(const nlohmann::json &json);
109 
116  bool LoadPOI();
117 
123  bool LoadDefaultRoutings();
124 
131  bool AddDefaultRouting(const nlohmann::json &json);
132 
133  void RegisterMessageHandlers();
134 
135  SimulationWorldService sim_world_service_;
136  const MapService *map_service_ = nullptr;
137  WebSocketHandler *websocket_ = nullptr;
138  WebSocketHandler *map_ws_ = nullptr;
139  WebSocketHandler *camera_ws_ = nullptr;
140  SimControl *sim_control_ = nullptr;
141  PerceptionCameraUpdater *perception_camera_updater_ = nullptr;
142 
143  // End point for requesting default route
144  apollo::routing::POI poi_;
145 
146  // default routings
147  apollo::routing::DefaultRoutings default_routings_;
148  apollo::routing::DefaultRouting *default_routing_;
149 
150  // The simulation_world in wire format to be pushed to frontend, which is
151  // updated by timer.
152  std::string simulation_world_;
153  std::string simulation_world_with_planning_data_;
154 
155  // Received relative map data in wire format.
156  std::string relative_map_string_;
157 
158  // Mutex to protect concurrent access to simulation_world_json_.
159  // NOTE: Use boost until we have std version of rwlock support.
160  boost::shared_mutex mutex_;
161 
162  std::unique_ptr<cyber::Timer> timer_;
163 
164  volatile double last_pushed_adc_timestamp_sec_ = 0.0f;
165 };
166 
167 } // namespace dreamview
168 } // namespace apollo
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
static constexpr double kSimWorldTimeIntervalMs
Definition: simulation_world_updater.h:80
A wrapper around SimulationWorldService and WebSocketHandler to keep pushing SimulationWorld to front...
Definition: simulation_world_updater.h:56
Definition: map_service.h:40
This is a major component of the Simulation backend, which maintains a SimulationWorld object and kee...
Definition: simulation_world_service.h:72
A module that simulates a &#39;perfect control&#39; algorithm, which assumes an ideal world where the car can...
Definition: sim_control.h:51
void Start()
Starts to push simulation_world to frontend.
Definition: perception_camera_updater.h:38
double LastAdcTimestampSec()
Definition: simulation_world_updater.h:82
SimulationWorldUpdater(WebSocketHandler *websocket, WebSocketHandler *map_ws, WebSocketHandler *camera_ws, SimControl *sim_control, const MapService *map_service, PerceptionCameraUpdater *perception_camera_updater, bool routing_from_file=false)
Constructor with the websocket handler.
The WebSocketHandler, built on top of CivetWebSocketHandler, is a websocket handler that handles diff...
Definition: websocket_handler.h:46