|
@@ -164,6 +164,12 @@ void SimPerfectControl::InitTimerAndIO() {
|
|
|
[this](const std::shared_ptr<PredictionObstacles> &obstacles) {
|
|
|
this->OnPredictionObstacles(obstacles);
|
|
|
});
|
|
|
+
|
|
|
+ control_command_reader_ = node_->CreateReader<apollo::control::ControlCommand>(
|
|
|
+ "/apollo/control",
|
|
|
+ [this](const std::shared_ptr<apollo::control::ControlCommand> &xctrlcmd) {
|
|
|
+ this->onControl(xctrlcmd);
|
|
|
+ });
|
|
|
|
|
|
localization_writer_ =
|
|
|
node_->CreateWriter<LocalizationEstimate>(FLAGS_localization_topic);
|
|
@@ -361,6 +367,19 @@ void SimPerfectControl::OnPlanningCommand(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+void SimPerfectControl::onControl(
|
|
|
+ const std::shared_ptr<apollo::control::ControlCommand> &xCmd) {
|
|
|
+// std::lock_guard<std::mutex> lock(mutex_);
|
|
|
+
|
|
|
+ std::lock_guard<std::mutex> lock(mutex_);
|
|
|
+
|
|
|
+ // std::cout<<"steer: "<<xCmd->steering_target()<<" acc: "<<xCmd->acceleration()<<" brake:"<<xCmd->brake()<<std::endl;
|
|
|
+
|
|
|
+ fcmdsteer_ = xCmd->steering_target();
|
|
|
+ fcmdbrake_ = xCmd->brake();
|
|
|
+ fcmdacc_ = xCmd->throttle();
|
|
|
+}
|
|
|
+
|
|
|
void SimPerfectControl::OnPredictionObstacles(
|
|
|
const std::shared_ptr<PredictionObstacles> &obstacles) {
|
|
|
std::lock_guard<std::mutex> lock(mutex_);
|
|
@@ -522,8 +541,9 @@ void SimPerfectControl::PublishChassis(double cur_speed,
|
|
|
chassis->set_speed_mps(static_cast<float>(fNowVel));
|
|
|
}
|
|
|
|
|
|
- chassis->set_throttle_percentage(0.0);
|
|
|
- chassis->set_brake_percentage(0.0);
|
|
|
+ chassis->set_throttle_percentage(fcmdacc_);
|
|
|
+ chassis->set_brake_percentage(fcmdbrake_);
|
|
|
+ chassis->set_steering_percentage(fcmdsteer_);
|
|
|
|
|
|
chassis_writer_->Write(chassis);
|
|
|
}
|