|
@@ -94,6 +94,8 @@ void SimPerfectControl::InitTimerAndIO() {
|
|
|
[this](const std::shared_ptr<PredictionObstacles> &obstacles) {
|
|
|
this->OnPredictionObstacles(obstacles);
|
|
|
});
|
|
|
+
|
|
|
+
|
|
|
|
|
|
localization_writer_ =
|
|
|
node_->CreateWriter<LocalizationEstimate>(FLAGS_localization_topic);
|
|
@@ -107,6 +109,18 @@ void SimPerfectControl::InitTimerAndIO() {
|
|
|
[this](const std::shared_ptr<LocalizationEstimate> &xloc) {
|
|
|
this->onADCLoc(xloc);
|
|
|
});
|
|
|
+
|
|
|
+ control_command_reader_ = node_->CreateReader<apollo::control::ControlCommand>(
|
|
|
+ "/apollo/control",
|
|
|
+ [this](const std::shared_ptr<apollo::control::ControlCommand> &xctrlcmd) {
|
|
|
+ this->onControl(xctrlcmd);
|
|
|
+ });
|
|
|
+
|
|
|
+ chassis_reader_ = node_->CreateReader<apollo::canbus::Chassis>(
|
|
|
+ "/apollo/adchassis",
|
|
|
+ [this](const std::shared_ptr<apollo::canbus::Chassis> &xchassis) {
|
|
|
+ this->onADCChassis(xchassis);
|
|
|
+ });
|
|
|
//*********完成本段
|
|
|
|
|
|
// Start timer to publish localization and chassis messages.
|
|
@@ -293,6 +307,20 @@ void SimPerfectControl::OnPlanningCommand(
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+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;
|
|
|
+
|
|
|
+ fcmdbrake_ = xCmd->brake();
|
|
|
+ fcmdacc_ = xCmd->throttle();
|
|
|
+}
|
|
|
+
|
|
|
void SimPerfectControl::OnPredictionObstacles(
|
|
|
const std::shared_ptr<PredictionObstacles> &obstacles) {
|
|
|
std::lock_guard<std::mutex> lock(mutex_);
|
|
@@ -454,6 +482,10 @@ void SimPerfectControl::PublishChassis(double cur_speed,
|
|
|
|
|
|
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(fchassissteer);
|
|
|
|
|
|
chassis_writer_->Write(chassis);
|
|
|
}
|
|
@@ -470,7 +502,7 @@ void SimPerfectControl::PublishLocalization(const TrajectoryPoint &point) {
|
|
|
|
|
|
auto *pose = localization->mutable_pose();
|
|
|
|
|
|
- fNowVel = sqrt(pow(pose->mutable_linear_velocity()->x(),2)+pow(pose->mutable_linear_velocity()->y(),2));
|
|
|
+// fNowVel = sqrt(pow(pose->mutable_linear_velocity()->x(),2)+pow(pose->mutable_linear_velocity()->y(),2));
|
|
|
|
|
|
adc_position_.set_x(pose->position().x());
|
|
|
adc_position_.set_y(pose->position().y());
|
|
@@ -565,6 +597,17 @@ void SimPerfectControl::onADCLoc(const std::shared_ptr<apollo::localization::Loc
|
|
|
adcloc_ = xloc;
|
|
|
receiveadcloc = true;
|
|
|
}
|
|
|
+
|
|
|
+void SimPerfectControl::onADCChassis(
|
|
|
+ const std::shared_ptr<apollo::canbus::Chassis >
|
|
|
+ &adchassis)
|
|
|
+{
|
|
|
+ std::lock_guard<std::mutex> lock(mutex_);
|
|
|
+
|
|
|
+ fchassissteer = adchassis->steering_percentage();
|
|
|
+
|
|
|
+ fNowVel = adchassis->speed_mps();
|
|
|
+}
|
|
|
//*********完成增加
|
|
|
|
|
|
} // namespace dreamview
|