提交 ddb317e2 编写于 作者: D Dong Li 提交者: Jiangtao Hu

migrated curve1d to apollo planning

上级 191f3b72
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
// @todo: complete this using gmock & gtest, capture logging contents and do
// checks.
#include "apollo/platform/log.h"
using namespace apollo::platform::log;
int main() {
LogModule m1 = {"test", 5, 10, platform_log_printf};
m1.set_log_lvl(7);
PLATFORM_LOG(&m1, 3, "test");
return 0;
}
......@@ -33,5 +33,6 @@ DEFINE_double(replanning_threshold, 2.0,
"The threshold of position deviation "
"that triggers the planner replanning");
DEFINE_double(trajectory_resolution, 0.01, "The time resolution of "
DEFINE_double(trajectory_resolution, 0.01,
"The time resolution of "
"output trajectory.");
load("//tools:cpplint.bzl", "cpplint")
package(default_visibility = ["//visibility:public"])
cc_library(
name = "curve1d",
hdrs = [
"curve1d.h",
],
deps = [
],
)
cc_library(
name = "polynomial_curve1d",
hdrs = [
"polynomial_curve1d.h",
],
deps = [
":curve1d",
],
)
cc_library(
name = "quartic_polynomial_curve1d",
srcs = [
"quartic_polynomial_curve1d.cc",
],
hdrs = [
"quartic_polynomial_curve1d.h",
],
deps = [
"polynomial_curve1d",
"@glog//:glog",
],
)
cc_library(
name = "quintic_polynomial_curve1d",
srcs = [
"quintic_polynomial_curve1d.cc",
],
hdrs = [
"quintic_polynomial_curve1d.h",
],
deps = [
"polynomial_curve1d",
"@glog//:glog",
],
)
cpplint()
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
/**
* @file curve1d.h
**/
#ifndef MODULES_PLANNING_MATH_CURVE1D_CURVE1D_H_
#define MODULES_PLANNING_MATH_CURVE1D_CURVE1D_H_
#include <string>
namespace apollo {
namespace planning {
// Base type for various types of 1-dimensional curves
class Curve1d {
public:
Curve1d() = default;
virtual ~Curve1d() = default;
virtual double evaluate(const std::size_t order,
const double param) const = 0;
virtual double param_length() const = 0;
virtual std::string to_string() const = 0;
};
} // namespace planning
} // namespace apollo
#endif /* MODULES_PLANNING_MATH_CURVE1D_CURVE1D_H_ */
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
/**
* @file polynomial_curve1d.h
**/
#ifndef MODULES_PLANNING_MATH_CURVE1D_POLYNOMIAL_CURVE1D_H_
#define MODULES_PLANNING_MATH_CURVE1D_POLYNOMIAL_CURVE1D_H_
#include "modules/planning/math/curve1d/curve1d.h"
namespace apollo {
namespace planning {
class PolynomialCurve1d : public Curve1d {
public:
PolynomialCurve1d() = default;
virtual ~PolynomialCurve1d() = default;
};
} // namespace planning
} // namespace apollo
#endif /* MODULES_PLANNING_MATH_CURVE1D_POLYNOMIAL_CURVE1D_H_ */
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
/**
* @file quartic_polynomial_curve1d.cc
**/
#include "modules/planning/math/curve1d/quartic_polynomial_curve1d.h"
#include <string>
#include "glog/logging.h"
namespace apollo {
namespace planning {
QuarticPolynomialCurve1d::QuarticPolynomialCurve1d(
const std::array<double, 3>& start, const std::array<double, 2>& end,
const double param)
: QuarticPolynomialCurve1d(start[0], start[1], start[2], end[0], end[1],
param) {}
QuarticPolynomialCurve1d::QuarticPolynomialCurve1d(
const double x0, const double dx0, const double ddx0, const double dx1,
const double ddx1, const double param) {
compute_coefficients(x0, dx0, ddx0, dx1, ddx1, param);
start_condition_[0] = x0;
start_condition_[1] = dx0;
start_condition_[2] = ddx0;
end_condition_[0] = dx1;
end_condition_[1] = ddx1;
}
QuarticPolynomialCurve1d::QuarticPolynomialCurve1d(
const QuarticPolynomialCurve1d& other) {
param_ = other.param_;
coef_ = other.coef_;
}
double QuarticPolynomialCurve1d::evaluate(const std::size_t order,
const double p) const {
switch (order) {
case 0: {
return (((coef_[0] * p + coef_[1]) * p + coef_[2]) * p + coef_[3]) * p +
coef_[4];
}
case 1: {
return ((4.0 * coef_[0] * p + 3.0 * coef_[1]) * p + 2.0 * coef_[2]) * p +
coef_[3];
}
case 2: {
return (12.0 * coef_[0] * p + 6.0 * coef_[1]) * p + 2.0 * coef_[2];
}
case 3: {
return 24.0 * coef_[0] * p + 6.0 * coef_[1];
}
case 4: {
return 24.0 * coef_[0];
}
default:
return 0.0;
}
}
double QuarticPolynomialCurve1d::param_length() const { return param_; }
void QuarticPolynomialCurve1d::compute_coefficients(
const double x0, const double dx0, const double ddx0, const double dx1,
const double ddx1, const double p) {
CHECK(p > 0.0);
param_ = p;
coef_[4] = x0;
coef_[3] = dx0;
coef_[2] = 0.5 * ddx0;
double b0 = dx1 - ddx0 * p - dx0;
double b1 = ddx1 - ddx0;
double p2 = p * p;
double p3 = p2 * p;
coef_[0] = -0.5 / p3 * b0 + 0.25 / p2 * b1;
coef_[1] = b0 / p2 - b1 / 3.0 / p;
}
std::string QuarticPolynomialCurve1d::to_string() const {
std::string s = "";
for (size_t i = 0; i < coef_.size(); ++i) {
s += std::to_string(coef_[i]) + "\t";
}
s += std::to_string(param_);
s += "\n";
return s;
}
} // namespace planning
} // namespace apollo
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
/**
* @file quartic_polynomial_curve1d.h
**/
#ifndef MODULES_PLANNING_MATH_CURVE1D_QUARTIC_POLYNOMIAL_CURVE1D_H_
#define MODULES_PLANNING_MATH_CURVE1D_QUARTIC_POLYNOMIAL_CURVE1D_H_
#include <array>
#include <string>
#include "modules/planning/math/curve1d/polynomial_curve1d.h"
namespace apollo {
namespace planning {
// 1D quartic polynomial curve: (x0, dx0, ddx0) -- [0, param] --> (dx1, ddx1)
class QuarticPolynomialCurve1d : public PolynomialCurve1d {
public:
QuarticPolynomialCurve1d() = default;
QuarticPolynomialCurve1d(const std::array<double, 3>& start,
const std::array<double, 2>& end,
const double param);
QuarticPolynomialCurve1d(const double x0, const double dx0, const double ddx0,
const double dx1, const double ddx1,
const double param);
QuarticPolynomialCurve1d(const QuarticPolynomialCurve1d& other);
virtual ~QuarticPolynomialCurve1d() = default;
double evaluate(const std::size_t order, const double p) const override;
double param_length() const override;
std::string to_string() const override;
private:
void compute_coefficients(const double x0, const double dx0,
const double ddx0, const double dx1,
const double ddx1, const double param);
double param_ = 0.0;
std::array<double, 5> coef_{{0.0, 0.0, 0.0, 0.0, 0.0}};
std::array<double, 3> start_condition_{{0.0, 0.0, 0.0}};
std::array<double, 2> end_condition_{{0.0, 0.0}};
};
} // namespace planning
} // namespace apollo
#endif /* MODULES_PLANNING_MATH_CURVE1D_QUARTIC_POLYNOMIAL_CURVE1D_H_ */
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
/**
* @file quintic_polynomial_curve1d.cc
**/
#include "modules/planning/math/curve1d/quintic_polynomial_curve1d.h"
#include "glog/logging.h"
namespace apollo {
namespace planning {
QuinticPolynomialCurve1d::QuinticPolynomialCurve1d(
const std::array<double, 3>& start, const std::array<double, 3>& end,
const double param)
: QuinticPolynomialCurve1d(start[0], start[1], start[2], end[0], end[1],
end[2], param) {}
QuinticPolynomialCurve1d::QuinticPolynomialCurve1d(
const double x0, const double dx0, const double ddx0, const double x1,
const double dx1, const double ddx1, const double param)
: param_(param) {
compute_coefficients(x0, dx0, ddx0, x1, dx1, ddx1, param);
start_condition_[0] = x0;
start_condition_[1] = dx0;
start_condition_[2] = ddx0;
end_condition_[0] = x1;
end_condition_[1] = dx1;
end_condition_[2] = ddx1;
}
QuinticPolynomialCurve1d::QuinticPolynomialCurve1d(
const QuinticPolynomialCurve1d& other) {
param_ = other.param_;
coef_ = other.coef_;
return;
}
double QuinticPolynomialCurve1d::evaluate(const size_t order,
const double p) const {
switch (order) {
case 0: {
return ((((coef_[0] * p + coef_[1]) * p + coef_[2]) * p + coef_[3]) * p +
coef_[4]) *
p +
coef_[5];
}
case 1: {
return (((5.0 * coef_[0] * p + 4.0 * coef_[1]) * p + 3.0 * coef_[2]) * p +
2.0 * coef_[3]) *
p +
coef_[4];
}
case 2: {
return (((20.0 * coef_[0] * p + 12.0 * coef_[1]) * p) + 6.0 * coef_[2]) *
p +
2.0 * coef_[3];
}
case 3: {
return (60.0 * coef_[0] * p + 24.0 * coef_[1]) * p + 6.0 * coef_[2];
}
case 4: {
return 120.0 * coef_[0] * p + 24.0 * coef_[1];
}
case 5: {
return 120.0 * coef_[0];
}
default:
return 0.0;
}
}
void QuinticPolynomialCurve1d::compute_coefficients(
const double x0, const double dx0, const double ddx0, const double x1,
const double dx1, const double ddx1, const double p) {
CHECK(p > 0.0);
coef_[5] = x0;
coef_[4] = dx0;
coef_[3] = ddx0 / 2.0;
double p2 = p * p;
double p3 = p * p2;
// the direct analytical method is at least 6 times faster than using matrix
// inversion.
double c0 = (x1 - 0.5 * p2 * ddx0 - dx0 * p - x0) / p3;
double c1 = (dx1 - ddx0 * p - dx0) / p2;
double c2 = (ddx1 - ddx0) / p;
coef_[0] = (6.0 * c0 - 3.0 * c1 + 0.5 * c2) / p2;
coef_[1] = (-15.0 * c0 + 7.0 * c1 - c2) / p;
coef_[2] = 0.5 * (20.0 * c0 - 8.0 * c1 + c2);
return;
}
double QuinticPolynomialCurve1d::param_length() const { return param_; }
std::string QuinticPolynomialCurve1d::to_string() const {
std::string s = "";
for (size_t i = 0; i < coef_.size(); ++i) {
s += std::to_string(coef_[i]) + "\t";
}
s += std::to_string(param_);
s += "\n";
return s;
}
} // namespace planning
} // namespace apollo
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
/**
* @file quintic_polynomial_curve1d.h
**/
#ifndef MODULES_PLANNING_MATH_CURVE1D_QUINTIC_POLYNOMIAL_CURVE1D_H_
#define MODULES_PLANNING_MATH_CURVE1D_QUINTIC_POLYNOMIAL_CURVE1D_H_
#include <array>
#include <string>
#include "modules/planning/math/curve1d/polynomial_curve1d.h"
namespace apollo {
namespace planning {
// 1D quintic polynomial curve: (x0, dx0, ddx0) -- [0, param] --> (x1, dx1,
// ddx1)
class QuinticPolynomialCurve1d : public PolynomialCurve1d {
public:
QuinticPolynomialCurve1d() = default;
QuinticPolynomialCurve1d(const std::array<double, 3>& start,
const std::array<double, 3>& end,
const double param);
QuinticPolynomialCurve1d(const double x0, const double dx0, const double ddx0,
const double x1, const double dx1, const double ddx1,
const double param);
QuinticPolynomialCurve1d(const QuinticPolynomialCurve1d& other);
virtual ~QuinticPolynomialCurve1d() = default;
double evaluate(const std::size_t order, const double p) const override;
double param_length() const override;
std::string to_string() const override;
private:
void compute_coefficients(const double x0, const double dx0,
const double ddx0, const double x1,
const double dx1, const double ddx1,
const double param);
double param_ = 0.0;
std::array<double, 6> coef_{{0.0, 0.0, 0.0, 0.0, 0.0, 0.0}};
std::array<double, 3> start_condition_{{0.0, 0.0, 0.0}};
std::array<double, 3> end_condition_{{0.0, 0.0, 0.0}};
};
} // namespace planning
} // namespace apollo
#endif /* MODULES_PLANNING_MATH_CURVE1D_QUINTIC_POLYNOMIAL_CURVE1D_H_ */
......@@ -35,7 +35,6 @@ RTKReplayPlanner::RTKReplayPlanner() {
bool RTKReplayPlanner::Plan(
const TrajectoryPoint& start_point,
std::vector<TrajectoryPoint>* ptr_discretized_trajectory) {
if (complete_rtk_trajectory_.empty() || complete_rtk_trajectory_.size() < 2) {
AERROR << "RTKReplayPlanner doesn't have a recorded trajectory or "
"the recorded trajectory doesn't have enough valid trajectory "
......@@ -68,8 +67,8 @@ bool RTKReplayPlanner::Plan(
while (ptr_discretized_trajectory->size() < FLAGS_rtk_trajectory_forward) {
ptr_discretized_trajectory->push_back(ptr_discretized_trajectory->back());
auto& last_point = ptr_discretized_trajectory->back();
last_point.set_relative_time(
last_point.relative_time() + FLAGS_trajectory_resolution);
last_point.set_relative_time(last_point.relative_time() +
FLAGS_trajectory_resolution);
}
return true;
}
......@@ -97,7 +96,8 @@ void RTKReplayPlanner::ReadTrajectoryFile(const std::string& filename) {
auto tokens = apollo::common::util::StringTokenizer::Split(line, "\t ");
if (tokens.size() < 11) {
AERROR << "RTKReplayPlanner parse line failed; the data dimension does not match.";
AERROR << "RTKReplayPlanner parse line failed; the data dimension does "
"not match.";
AERROR << line;
continue;
}
......@@ -137,8 +137,8 @@ std::size_t RTKReplayPlanner::QueryPositionMatchedPoint(
start_point.y());
std::size_t index_min = 0;
for (std::size_t i = 1; i < trajectory.size(); ++i) {
double d_temp = func_distance_square(trajectory[i], start_point.x(),
start_point.y());
double d_temp =
func_distance_square(trajectory[i], start_point.x(), start_point.y());
if (d_temp < d_min) {
d_min = d_temp;
index_min = i;
......
......@@ -26,8 +26,7 @@ using apollo::common::TrajectoryPoint;
namespace apollo {
namespace planning {
class RTKReplayPlannerTest : public ::testing::Test {
};
class RTKReplayPlannerTest : public ::testing::Test {};
TEST_F(RTKReplayPlannerTest, ComputeTrajectory) {
FLAGS_rtk_trajectory_filename = "modules/planning/testdata/garage.csv";
......@@ -54,7 +53,8 @@ TEST_F(RTKReplayPlannerTest, ComputeTrajectory) {
}
TEST_F(RTKReplayPlannerTest, ErrorTest) {
FLAGS_rtk_trajectory_filename = "modules/planning/testdata/garage_no_file.csv";
FLAGS_rtk_trajectory_filename =
"modules/planning/testdata/garage_no_file.csv";
RTKReplayPlanner planner;
FLAGS_rtk_trajectory_filename = "modules/planning/testdata/garage_error.csv";
RTKReplayPlanner planner_with_error_csv;
......
......@@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/planning/planning.h"
#include "modules/common/adapters/adapter_manager.h"
#include "modules/common/time/time.h"
#include "modules/planning/common/planning_gflags.h"
#include "modules/planning/planner_factory.h"
#include "modules/planning/planning.h"
namespace apollo {
namespace planning {
......@@ -134,8 +134,8 @@ TrajectoryPoint Planning::ComputeStartingPointFromVehicleState(
point.set_kappa(0.0);
const double speed_threshold = 0.1;
if (point.v() > speed_threshold) {
point.set_kappa(
vehicle_state.angular_velocity() / vehicle_state.linear_velocity());
point.set_kappa(vehicle_state.angular_velocity() /
vehicle_state.linear_velocity());
}
point.set_dkappa(0.0);
point.set_s(0.0);
......
......@@ -86,10 +86,12 @@ void PlanningNode::RunOnce() {
planning_cycle_time;
std::vector<TrajectoryPoint> planning_trajectory;
bool res_planning = planning_.Plan(vehicle_state, is_on_auto_mode,
execution_start_time, &planning_trajectory);
bool res_planning =
planning_.Plan(vehicle_state, is_on_auto_mode, execution_start_time,
&planning_trajectory);
if (res_planning) {
TrajectoryPb trajectory_pb = ToTrajectoryPb(execution_start_time, planning_trajectory);
TrajectoryPb trajectory_pb =
ToTrajectoryPb(execution_start_time, planning_trajectory);
AdapterManager::PublishPlanningTrajectory(trajectory_pb);
AINFO << "Planning succeeded";
} else {
......@@ -97,9 +99,7 @@ void PlanningNode::RunOnce() {
}
}
void PlanningNode::Reset() {
planning_.Reset();
}
void PlanningNode::Reset() { planning_.Reset(); }
TrajectoryPb PlanningNode::ToTrajectoryPb(
const double header_time,
......
......@@ -14,10 +14,10 @@
* limitations under the License.
*****************************************************************************/
#include "modules/planning/common/planning_gflags.h"
#include "modules/planning/planning.h"
#include "modules/planning/proto/planning.pb.h"
#include "modules/planning/common/planning_gflags.h"
#include "modules/planning/planner_factory.h"
#include "modules/planning/proto/planning.pb.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
......@@ -28,11 +28,9 @@ namespace planning {
using TrajectoryPb = ADCTrajectory;
using apollo::common::TrajectoryPoint;
class PlanningTest: public ::testing::Test {
};
class PlanningTest : public ::testing::Test {};
TEST_F(PlanningTest, ComputeTrajectory) {
FLAGS_rtk_trajectory_filename = "modules/planning/testdata/garage.csv";
Planning planning;
common::vehicle_state::VehicleState vehicle_state;
......@@ -47,8 +45,7 @@ TEST_F(PlanningTest, ComputeTrajectory) {
double time1 = 0.1;
planning.Plan(vehicle_state, false, time1, &trajectory1);
EXPECT_EQ(trajectory1.size(),
(std::size_t)FLAGS_rtk_trajectory_forward);
EXPECT_EQ(trajectory1.size(), (std::size_t)FLAGS_rtk_trajectory_forward);
const auto& p1_start = trajectory1.front();
const auto& p1_end = trajectory1.back();
......@@ -59,9 +56,8 @@ TEST_F(PlanningTest, ComputeTrajectory) {
double time2 = 0.5;
planning.Plan(vehicle_state, true, time2, &trajectory2);
EXPECT_EQ(trajectory2.size(),
(std::size_t)FLAGS_rtk_trajectory_forward +
(int)FLAGS_rtk_trajectory_backward);
EXPECT_EQ(trajectory2.size(), (std::size_t)FLAGS_rtk_trajectory_forward +
(int)FLAGS_rtk_trajectory_backward);
const auto& p2_backward = trajectory2.front();
const auto& p2_start = trajectory2[FLAGS_rtk_trajectory_backward];
......@@ -79,7 +75,6 @@ TEST_F(PlanningTest, ComputeTrajectory) {
}
TEST_F(PlanningTest, ComputeTrajectoryNoRTKFile) {
FLAGS_rtk_trajectory_filename = "";
Planning planning;
common::vehicle_state::VehicleState vehicle_state;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册