Apollo 10.0
自动驾驶开放平台
vehicle_config_helper.cc
浏览该文件的文档.
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
18
19#include <algorithm>
20#include <cmath>
21
22#include "cyber/common/file.h"
24
25namespace apollo {
26namespace common {
27
28VehicleConfig VehicleConfigHelper::vehicle_config_;
29bool VehicleConfigHelper::is_init_ = false;
30
31VehicleConfigHelper::VehicleConfigHelper() {}
32
33void VehicleConfigHelper::Init() { Init(FLAGS_vehicle_config_path); }
34
35void VehicleConfigHelper::Init(const std::string &config_file) {
36 VehicleConfig params;
37 ACHECK(cyber::common::GetProtoFromFile(config_file, &params))
38 << "Unable to parse vehicle config file " << config_file;
39 Init(params);
40}
41
42void VehicleConfigHelper::Init(const VehicleConfig &vehicle_params) {
43 vehicle_config_ = vehicle_params;
44 is_init_ = true;
45}
46
48 if (!is_init_) {
49 Init();
50 }
51 return vehicle_config_;
52}
53
55 const auto &param = vehicle_config_.vehicle_param();
56 double lat_edge_to_center =
57 std::max(param.left_edge_to_center(), param.right_edge_to_center());
58 double lon_edge_to_center =
59 std::max(param.front_edge_to_center(), param.back_edge_to_center());
60 return std::sqrt((lat_edge_to_center + param.min_turn_radius()) *
61 (lat_edge_to_center + param.min_turn_radius()) +
62 lon_edge_to_center * lon_edge_to_center);
63}
64
66 const common::PathPoint &path_point) {
67 const auto &vehicle_param = vehicle_config_.vehicle_param();
68 math::Vec2d point(path_point.x(), path_point.y());
70 point, path_point.theta(), vehicle_param.front_edge_to_center(),
71 vehicle_param.back_edge_to_center(), vehicle_param.width());
72}
73
74} // namespace common
75} // namespace apollo
static double MinSafeTurnRadius()
Get the safe turning radius when the vehicle is turning with maximum steering angle.
static void Init()
Initialize vehicle configurations with default configuration file pointed by gflags FLAGS_vehicle_con...
static common::math::Box2d GetBoundingBox(const common::PathPoint &path_point)
Get the box (four corners: ABCD) of the vehicle.
static const VehicleConfig & GetConfig()
Get the current vehicle configuration.
Rectangular (undirected) bounding box in 2-D.
Definition box2d.h:52
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
#define ACHECK(cond)
Definition log.h:80
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
Definition file.cc:132
class register implement
Definition arena_queue.h:37
optional VehicleParam vehicle_param