Apollo  6.0
Open source self driving car software
teleop.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 <boost/thread/locks.hpp>
20 #include <boost/thread/shared_mutex.hpp>
21 
22 #include "cyber/cyber.h"
23 #include "nlohmann/json.hpp"
24 
25 #if WITH_TELEOP == 1
26 #include "modules/planning/proto/pad_msg.pb.h"
27 #include "modules/planning/proto/planning.pb.h"
28 #include "modules/teleop/daemon/proto/daemon_cmd.pb.h"
29 #include "modules/teleop/daemon/proto/daemon_rpt.pb.h"
30 #include "modules/teleop/modem/proto/modem_info.pb.h"
31 #endif
32 
34 
35 namespace apollo {
36 namespace dreamview {
37 
39  public:
40  TeleopService(WebSocketHandler *websocket);
41 
42  void Start();
43 
44  private:
45  void RegisterMessageHandlers();
46  void SendStatus(WebSocketHandler::Connection *conn);
47 
48 #if WITH_TELEOP == 1
49  // send a command to the remote daemon to start or stop
50  // video encoders and voip encoders
51  void SendAudioStreamCmd(bool start_stop);
52  void SendMicStreamCmd(bool start_stop);
53  void SendVideoStreamCmd(bool start_stop);
54  // planner commands
55  void SendEstopCmd();
56  void SendPullOverCmd();
57  void SendResumeCruiseCmd();
58 
59  void UpdateModemInfo(
60  const std::shared_ptr<modules::teleop::modem::ModemInfo> &modem_info);
61 #endif
62 
63  std::unique_ptr<cyber::Node> node_;
64 
65  WebSocketHandler *websocket_;
66 
67 #if WITH_TELEOP == 1
68  // modem info readers and callback
69  std::shared_ptr<cyber::Reader<modules::teleop::modem::ModemInfo>>
70  modem0_info_reader_;
71  std::shared_ptr<cyber::Reader<modules::teleop::modem::ModemInfo>>
72  modem1_info_reader_;
73  std::shared_ptr<cyber::Reader<modules::teleop::modem::ModemInfo>>
74  modem2_info_reader_;
75  // modem info callback
76  void UpdateModem(
77  const std::string &modem_id,
78  const std::shared_ptr<modules::teleop::modem::ModemInfo> &modem_info);
79  // planning message reader
80  std::shared_ptr<cyber::Reader<apollo::planning::ADCTrajectory>>
81  planning_reader_;
82 
83  // daemon report readers and callback
84  void UpdateCarDaemonRpt(
85  const std::shared_ptr<modules::teleop::daemon::DaemonRpt> &rpt);
86  void UpdateOperatorDaemonRpt(
87  const std::shared_ptr<modules::teleop::daemon::DaemonRpt> &rpt);
88  std::shared_ptr<cyber::Reader<modules::teleop::daemon::DaemonRpt>>
89  remote_daemon_rpt_reader_;
90  std::shared_ptr<cyber::Reader<modules::teleop::daemon::DaemonRpt>>
91  local_daemon_rpt_reader_;
92  // daemon commands writers
93  std::shared_ptr<cyber::Writer<modules::teleop::daemon::DaemonCmd>>
94  remote_daemon_cmd_writer_;
95  std::shared_ptr<cyber::Writer<modules::teleop::daemon::DaemonCmd>>
96  local_daemon_cmd_writer_;
97 
98  // planning driving actions and feedback
99  std::shared_ptr<cyber::Writer<apollo::planning::PadMessage>>
100  pad_message_writer_;
101  void UpdatePlanning(
102  const std::shared_ptr<apollo::planning::ADCTrajectory> &msg);
103 #endif
104 
105  // Store teleop status
106  nlohmann::json teleop_status_;
107 
108  // Mutex to protect concurrent access to teleop_status_.
109  // NOTE: Use boost until we upgrade to std version with rwlock support.
110  boost::shared_mutex mutex_;
111 };
112 
113 } // namespace dreamview
114 } // namespace apollo
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
struct mg_connection Connection
Definition: websocket_handler.h:54
Definition: teleop.h:38
The WebSocketHandler, built on top of CivetWebSocketHandler, is a websocket handler that handles diff...
Definition: websocket_handler.h:46
TeleopService(WebSocketHandler *websocket)