Apollo 10.0
自动驾驶开放平台
sim_perfect_control.h
浏览该文件的文档.
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
25#include "gtest/gtest_prod.h"
26
27#include "modules/common_msgs/localization_msgs/localization.pb.h"
28#include "modules/common_msgs/planning_msgs/navigation.pb.h"
29#include "modules/common_msgs/planning_msgs/planning.pb.h"
30#include "modules/common_msgs/planning_msgs/planning_command.pb.h"
31#include "modules/common_msgs/prediction_msgs/prediction_obstacle.pb.h"
32#include "modules/common_msgs/routing_msgs/routing.pb.h"
33
34#include "cyber/cyber.h"
38
43namespace apollo {
44namespace dreamview {
45
52class SimPerfectControl final : public SimControlBase {
53 public:
58 explicit SimPerfectControl(const MapService *map_service);
59
64 void Init(bool set_start_point, nlohmann::json start_point_attr,
65 bool use_start_point_position = false) override;
66
71 void Start() override;
72
76 void Stop() override;
77
81 void ReSetPoinstion(double x, double y, double heading) override;
82
86 void Reset() override;
87
88 void RunOnce() override;
89
90 private:
91 void OnPlanning(
92 const std::shared_ptr<apollo::planning::ADCTrajectory> &trajectory);
93 void OnPlanningCommand(
94 const std::shared_ptr<apollo::planning::PlanningCommand>
95 &planning_command);
96 void OnReceiveNavigationInfo(
97 const std::shared_ptr<apollo::relative_map::NavigationInfo>
98 &navigation_info);
99 void OnPredictionObstacles(
100 const std::shared_ptr<apollo::prediction::PredictionObstacles>
101 &obstacles);
102
106 bool PerfectControlModel(
109
110 void PublishChassis(double cur_speed,
112
113 void PublishLocalization(const apollo::common::TrajectoryPoint &point);
114
115 void PublishDummyPrediction();
116
117 void InitTimerAndIO();
118
123 void Start(double x, double y, double v = 0.0, double a = 0.0) override;
124
125 void InitStartPoint(double start_velocity, double start_acceleration);
126
127 // use scenario start point to init start point under the simulation
128 // condition.
129 void InitStartPoint(double x, double y, double start_velocity,
130 double start_acceleration);
131
132 // Reset the start point, which can be a dummy point on the map, a current
133 // localization pose, or a start position received from the routing module.
134 void SetStartPoint(const apollo::common::TrajectoryPoint &point);
135
136 void Freeze();
137
138 void ClearPlanning();
139
140 void InternalReset();
141
142 const MapService *map_service_ = nullptr;
143
144 std::unique_ptr<cyber::Node> node_;
145
146 std::shared_ptr<cyber::Reader<apollo::localization::LocalizationEstimate>>
147 localization_reader_;
148 std::shared_ptr<cyber::Reader<apollo::planning::ADCTrajectory>>
149 planning_reader_;
150 std::shared_ptr<cyber::Reader<apollo::relative_map::NavigationInfo>>
151 navigation_reader_;
152 std::shared_ptr<cyber::Reader<apollo::prediction::PredictionObstacles>>
153 prediction_reader_;
154 std::shared_ptr<cyber::Reader<apollo::planning::PlanningCommand>>
155 planning_command_reader_;
156 std::shared_ptr<cyber::Writer<apollo::localization::LocalizationEstimate>>
157 localization_writer_;
158 std::shared_ptr<cyber::Writer<apollo::canbus::Chassis>> chassis_writer_;
159 std::shared_ptr<cyber::Writer<apollo::prediction::PredictionObstacles>>
160 prediction_writer_;
161
162 // The timer to publish simulated localization and chassis messages.
163 std::unique_ptr<cyber::Timer> sim_control_timer_;
164
165 // The timer to publish dummy prediction
166 std::unique_ptr<cyber::Timer> sim_prediction_timer_;
167
168 // Time interval of the timer, in milliseconds.
169 static constexpr double kSimControlIntervalMs = 10;
170 static constexpr double kSimPredictionIntervalMs = 100;
171
172 // The latest received planning trajectory.
173 std::shared_ptr<apollo::planning::ADCTrajectory> current_trajectory_;
174 // The index of the previous and next point with regard to the
175 // current_trajectory.
176 int prev_point_index_ = 0;
177 int next_point_index_ = 0;
178
179 // Whether there's a planning received after the most recent routing.
180 bool received_planning_ = false;
181
182 // Whether start point is initialized from actual localization data
183 bool start_point_from_localization_ = false;
184
185 // Whether to send dummy predictions
186 bool send_dummy_prediction_ = true;
187
188 // The header of the routing planning is following.
189 apollo::common::Header current_routing_header_;
190
193
194 common::PathPoint adc_position_;
195
196 // Linearize reader/timer callbacks and external operations.
197 std::mutex mutex_;
198 // Locks related to timer.
199 std::mutex timer_mutex_;
200
201 FRIEND_TEST(SimControlTest, Test);
202 FRIEND_TEST(SimControlTest, TestDummyPrediction);
203};
204
205} // namespace dreamview
206} // namespace apollo
Interface of simulated control algorithm
A module that simulates a 'perfect control' algorithm, which assumes an ideal world where the car can...
void Reset() override
Resets the internal state.
void ReSetPoinstion(double x, double y, double heading) override
Set vehicle position.
void Start() override
Starts the timer to publish simulated localization and chassis messages.
void Stop() override
Stops the timer.
void RunOnce() override
Main logic of the simulated control algorithm.
void Init(bool set_start_point, nlohmann::json start_point_attr, bool use_start_point_position=false) override
setup callbacks and timer
class register implement
Definition arena_queue.h:37