提交 e0daa38a 编写于 作者: L Liangliang Zhang 提交者: Jiangtao Hu

Planning: added planning data class.

上级 18575cd4
......@@ -36,14 +36,14 @@ PlanningBase::~PlanningBase() {}
void PlanningBase::PublishPlanningPb(const double timestamp,
ADCTrajectory* const trajectory_pb) {
trajectory_pb->mutable_header()->set_timestamp_sec(timestamp);
if (prediction_obstacles_ != nullptr &&
!prediction_obstacles_->has_header()) {
if (planning_data_.prediction_obstacles != nullptr &&
!planning_data_.prediction_obstacles->has_header()) {
trajectory_pb->mutable_header()->set_lidar_timestamp(
prediction_obstacles_->header().lidar_timestamp());
planning_data_.prediction_obstacles->header().lidar_timestamp());
trajectory_pb->mutable_header()->set_camera_timestamp(
prediction_obstacles_->header().camera_timestamp());
planning_data_.prediction_obstacles->header().camera_timestamp());
trajectory_pb->mutable_header()->set_radar_timestamp(
prediction_obstacles_->header().radar_timestamp());
planning_data_.prediction_obstacles->header().radar_timestamp());
}
// TODO(all): integrate reverse gear
......
......@@ -45,6 +45,19 @@
*/
namespace apollo {
namespace planning {
/**
* @class planning_data
*
* @brief PlanningData contains all necessary data as planning input
*/
struct PlanningData {
std::shared_ptr<prediction::PredictionObstacles> prediction_obstacles;
std::shared_ptr<canbus::Chassis> chassis;
std::shared_ptr<localization::LocalizationEstimate> localization_estimate;
std::shared_ptr<perception::TrafficLightDetection> traffic_light;
std::shared_ptr<routing::RoutingResponse> routing;
};
/**
* @class planning
......@@ -60,14 +73,7 @@ class PlanningBase {
virtual std::string Name() const = 0;
virtual void RunOnce(
const std::shared_ptr<prediction::PredictionObstacles>&
prediction_obstacles,
const std::shared_ptr<canbus::Chassis>& chassis,
const std::shared_ptr<localization::LocalizationEstimate>&
localization_estimate,
const perception::TrafficLightDetection,
const routing::RoutingResponse& routing) = 0;
virtual void RunOnce(const PlanningData& planning_data) = 0;
/**
* @brief Plan the trajectory given current vehicle state
......@@ -78,14 +84,12 @@ class PlanningBase {
ADCTrajectory* const trajectory) = 0;
protected:
void PublishPlanningPb(const double timestamp, ADCTrajectory* const trajectory_pb);
void PublishPlanningPb(const double timestamp,
ADCTrajectory* const trajectory_pb);
void SetFallbackTrajectory(ADCTrajectory* const trajectory_pb);
PlanningData planning_data_;
const hdmap::HDMap* hdmap_ = nullptr;
const std::shared_ptr<prediction::PredictionObstacles> prediction_obstacles_;
const std::shared_ptr<canbus::Chassis> chassis_;
const std::shared_ptr<localization::LocalizationEstimate>
localization_estimate_;
const std::shared_ptr<ADCTrajectory> last_planning_;
double start_time_ = 0.0;
......
......@@ -15,8 +15,8 @@
*****************************************************************************/
#include "modules/planning/planning_component.h"
#include "modules/planning/std_planning.h"
#include "modules/common/util/message_util.h"
#include "modules/planning/std_planning.h"
namespace apollo {
namespace planning {
......@@ -44,6 +44,8 @@ bool PlanningComponent::Init() {
traffic_light_.CopyFrom(*traffic_light);
});
writer_ = node_->CreateWriter<ADCTrajectory>("/apollo/planning");
return true;
}
......@@ -53,15 +55,19 @@ bool PlanningComponent::Proc(
const std::shared_ptr<canbus::Chassis>& chassis,
const std::shared_ptr<localization::LocalizationEstimate>&
localization_estimate) {
routing::RoutingResponse routing_copy;
planning_data_.prediction_obstacles = prediction_obstacles;
planning_data_.chassis = chassis;
planning_data_.localization_estimate = localization_estimate;
{
std::lock_guard<std::mutex> lock(mutex_);
routing_copy = routing_;
planning_data_.routing =
std::make_shared<routing::RoutingResponse>(routing_);
}
perception::TrafficLightDetection traffic_light_copy;
{
std::lock_guard<std::mutex> lock(mutex_);
traffic_light_copy = traffic_light_;
planning_data_.traffic_light =
std::make_shared<TrafficLightDetection>(traffic_light_);
}
ADCTrajectory adc_trajectory_pb;
......
......@@ -64,13 +64,14 @@ class PlanningComponent final
perception::TrafficLightDetection traffic_light_;
routing::RoutingResponse routing_;
PlanningData planning_data_;
std::unique_ptr<PlanningBase> planning_base_;
};
CYBERTRON_REGISTER_COMPONENT(PlanningComponent)
} // namespace planning
} // namepsace apollo
} // namespace apollo
#endif // MODULES_PLANNING_PLANNING_COMPONENT_H_
......@@ -148,14 +148,7 @@ Status StdPlanning::InitFrame(const uint32_t sequence_num,
return Status::OK();
}
void StdPlanning::RunOnce(
const std::shared_ptr<prediction::PredictionObstacles>&
prediction_obstacles,
const std::shared_ptr<canbus::Chassis>& chassis,
const std::shared_ptr<localization::LocalizationEstimate>&
localization_estimate,
const perception::TrafficLightDetection,
const routing::RoutingResponse& routing) {
void StdPlanning::RunOnce(const PlanningData& planning_data) {
const double start_timestamp = Clock::NowInSeconds();
ADCTrajectory not_ready_pb;
......@@ -163,11 +156,11 @@ void StdPlanning::RunOnce(
->mutable_main_decision()
->mutable_not_ready();
if (localization_estimate == nullptr) {
if (planning_data.localization_estimate == nullptr) {
not_ready->set_reason("localization not ready");
} else if (chassis == nullptr) {
} else if (planning_data.chassis == nullptr) {
not_ready->set_reason("chassis not ready");
} else if (!routing.has_header()) {
} else if (planning_data.routing == nullptr) {
not_ready->set_reason("routing not ready");
} else if (HDMapUtil::BaseMapPtr() == nullptr) {
not_ready->set_reason("map not ready");
......@@ -179,13 +172,14 @@ void StdPlanning::RunOnce(
}
// localization
ADEBUG << "Get localization:" << localization_estimate->DebugString();
ADEBUG << "Get localization:"
<< planning_data.localization_estimate->DebugString();
// chassis
ADEBUG << "Get chassis:" << chassis->DebugString();
ADEBUG << "Get chassis:" << planning_data.chassis->DebugString();
Status status = VehicleStateProvider::Instance()->Update(
*localization_estimate, *chassis);
*planning_data.localization_estimate, *planning_data.chassis);
VehicleState vehicle_state =
VehicleStateProvider::Instance()->vehicle_state();
......@@ -213,10 +207,10 @@ void StdPlanning::RunOnce(
return;
}
if (IsDifferentRouting(last_routing_, routing)) {
last_routing_ = routing;
if (IsDifferentRouting(last_routing_, *planning_data.routing)) {
last_routing_ = *planning_data.routing;
GetPlanningStatus()->Clear();
reference_line_provider_->UpdateRoutingResponse(routing);
reference_line_provider_->UpdateRoutingResponse(*planning_data.routing);
}
// Update reference line provider and reset pull over if necessary
......
......@@ -60,13 +60,7 @@ class StdPlanning : public PlanningBase {
* @brief main logic of the planning module, runs periodically triggered by
* timer.
*/
void RunOnce(const std::shared_ptr<prediction::PredictionObstacles>&
prediction_obstacles,
const std::shared_ptr<canbus::Chassis>& chassis,
const std::shared_ptr<localization::LocalizationEstimate>&
localization_estimate,
const perception::TrafficLightDetection,
const routing::RoutingResponse& routing) override;
void RunOnce(const PlanningData& planning_data) override;
apollo::common::Status Plan(
const double current_time_stamp,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册