|
|
@@ -16,7 +16,8 @@ using std::placeholders::_1;
|
|
|
LidarScanController::LidarScanController(rclcpp::Node *node)
|
|
|
: node_(node), active_(false), charging_state_(ChargingState::IDLE), detect_charging_voltage_(false), frame_index_(0), station_detected_(false), current_angle_bisector_k_(0.0),
|
|
|
current_angle_bisector_b_(0.0), // 新增
|
|
|
- has_angle_bisector_(false) // 新增
|
|
|
+ has_angle_bisector_(false),
|
|
|
+ report_manager_(nullptr)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
@@ -24,6 +25,11 @@ LidarScanController::~LidarScanController()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
+void LidarScanController::setReportManager(ReportManager *report_manager)
|
|
|
+{
|
|
|
+ report_manager_ = report_manager;
|
|
|
+}
|
|
|
+
|
|
|
void LidarScanController::initialize()
|
|
|
{
|
|
|
// 声明参数
|
|
|
@@ -62,13 +68,13 @@ void LidarScanController::initialize()
|
|
|
pub_line_ = node_->create_publisher<sensor_msgs::msg::LaserScan>("/scan/out_line", 10);
|
|
|
|
|
|
// 创建基站检测状态发布者(使用 transient_local 确保新订阅者能收到最后一条消息)
|
|
|
- pub_station_detected_ = node_->create_publisher<std_msgs::msg::Bool>(
|
|
|
- "/station/detected",
|
|
|
- rclcpp::QoS(10).transient_local()); // 修改为 transient_local
|
|
|
- pub_charging_voltage_ = node_->create_publisher<std_msgs::msg::String>(
|
|
|
- "/charging/voltage_detected", 10);
|
|
|
- pub1_=node_->create_publisher<std_msgs::msg::Int32>("/vlago/recharge/state",10);
|
|
|
- pub2_=node_->create_publisher<std_msgs::msg::Int32>("/vlago/recharge/feedback",10);
|
|
|
+ // pub_station_detected_ = node_->create_publisher<std_msgs::msg::Bool>(
|
|
|
+ // "/station/detected",
|
|
|
+ // rclcpp::QoS(10).transient_local()); // 修改为 transient_local
|
|
|
+ // pub_charging_voltage_ = node_->create_publisher<std_msgs::msg::String>(
|
|
|
+ // "/charging/voltage_detected", 10);
|
|
|
+ // pub1_=node_->create_publisher<std_msgs::msg::Int32>("/vlago/recharge/state",10);
|
|
|
+ // pub2_=node_->create_publisher<std_msgs::msg::Int32>("/vlago/recharge/feedback",10);
|
|
|
// 初始化控制消息
|
|
|
ctrl_twist_.linear.x = 0.0;
|
|
|
ctrl_twist_.angular.z = 0.0;
|
|
|
@@ -95,9 +101,11 @@ void LidarScanController::resetStationDetection()
|
|
|
detect_charging_voltage_ = false;
|
|
|
|
|
|
// 发布false信号
|
|
|
- auto false_msg = std_msgs::msg::Bool();
|
|
|
- false_msg.data = false;
|
|
|
- pub_station_detected_->publish(false_msg);
|
|
|
+ // auto false_msg = std_msgs::msg::Bool();
|
|
|
+ // false_msg.data = false;
|
|
|
+ // pub_station_detected_->publish(false_msg);
|
|
|
+ if (report_manager_)
|
|
|
+ report_manager_->publishStationDetectedMsg(false);
|
|
|
|
|
|
// 重置时间戳
|
|
|
last_station_publish_time_ = node_->now();
|
|
|
@@ -125,30 +133,17 @@ void LidarScanController::publishStationDetected(bool detected)
|
|
|
{
|
|
|
auto now = node_->now();
|
|
|
auto time_diff = (now - last_station_publish_time_).seconds();
|
|
|
- // if (station_detected_ == false && detected == false)
|
|
|
- // {
|
|
|
- // auto msg = std_msgs::msg::Bool();
|
|
|
- // msg.data = detected;
|
|
|
- // pub_station_detected_->publish(msg);
|
|
|
- // }
|
|
|
// 防止频繁发布,至少间隔0.5秒
|
|
|
if (station_detected_ != detected)
|
|
|
{
|
|
|
- auto msg = std_msgs::msg::Bool();
|
|
|
- msg.data = detected;
|
|
|
- pub_station_detected_->publish(msg);
|
|
|
+ // auto msg = std_msgs::msg::Bool();
|
|
|
+ // msg.data = detected;
|
|
|
+ // pub_station_detected_->publish(msg);
|
|
|
+ if (report_manager_)
|
|
|
+ report_manager_->publishStationDetectedMsg(detected);
|
|
|
station_detected_ = detected;
|
|
|
}
|
|
|
last_station_publish_time_ = now;
|
|
|
-
|
|
|
- // if (detected)
|
|
|
- // {
|
|
|
- // RCLCPP_INFO(node_->get_logger(), "发布基站检测成功信号: true");
|
|
|
- // }
|
|
|
- // else
|
|
|
- // {
|
|
|
- // RCLCPP_DEBUG(node_->get_logger(), "发布基站检测信号: false");
|
|
|
- // }
|
|
|
}
|
|
|
|
|
|
void LidarScanController::stopMotion()
|
|
|
@@ -406,7 +401,8 @@ void LidarScanController::procData(RechargeResult &result)
|
|
|
|
|
|
void LidarScanController::controlRechargeMotion(const RechargeResult &result)
|
|
|
{
|
|
|
- if (!active_) return;
|
|
|
+ if (!active_)
|
|
|
+ return;
|
|
|
publishStationDetected(true);
|
|
|
bool in_rotation_delay = node_->get_parameter("in_rotation_delay").as_bool();
|
|
|
if (in_rotation_delay)
|
|
|
@@ -507,7 +503,7 @@ void LidarScanController::controlRechargeMotion(const RechargeResult &result)
|
|
|
rclcpp::Time adjust_start = node_->now();
|
|
|
int publish_count = 0;
|
|
|
|
|
|
- while (rclcpp::ok() && active_ &&(node_->now() - adjust_start).seconds() < adjust_duration)
|
|
|
+ while (rclcpp::ok() && active_ && (node_->now() - adjust_start).seconds() < adjust_duration)
|
|
|
{
|
|
|
pub_ctrl_->publish(adjust_cmd);
|
|
|
publish_count++;
|
|
|
@@ -541,7 +537,7 @@ void LidarScanController::controlRechargeMotion(const RechargeResult &result)
|
|
|
rclcpp::Time forward_start = node_->now();
|
|
|
int forward_count = 0;
|
|
|
|
|
|
- while (rclcpp::ok() && active_ &&(node_->now() - forward_start).seconds() < forward_duration)
|
|
|
+ while (rclcpp::ok() && active_ && (node_->now() - forward_start).seconds() < forward_duration)
|
|
|
{
|
|
|
pub_ctrl_->publish(forward_cmd);
|
|
|
forward_count++;
|
|
|
@@ -646,9 +642,13 @@ void LidarScanController::controlRechargeMotion(const RechargeResult &result)
|
|
|
ctrl_twist_.linear.x = 0.0;
|
|
|
ctrl_twist_.angular.z = 0.0;
|
|
|
ctrl_twist_time_ = node_->now();
|
|
|
- auto msg =std_msgs::msg::Int32();
|
|
|
- msg.data=RECHARGE_FEEDBACK_SUCCESS_DOCKED;
|
|
|
- pub1_->publish(msg);
|
|
|
+ // auto msg = std_msgs::msg::Int32();
|
|
|
+ // msg.data = RECHARGE_FEEDBACK_SUCCESS_DOCKED;
|
|
|
+ // pub1_->publish(msg);
|
|
|
+
|
|
|
+ if (report_manager_)
|
|
|
+ report_manager_->publishRechargeFeedback(RECHARGE_FEEDBACK_SUCCESS_DOCKED);
|
|
|
+
|
|
|
stopNavigation();
|
|
|
|
|
|
// 模拟检测到充电电压
|
|
|
@@ -1290,7 +1290,7 @@ void LidarScanController::setChargingVoltage(bool value)
|
|
|
{
|
|
|
detect_charging_voltage_ = value;
|
|
|
detect_charging_voltage_time_ = node_->now();
|
|
|
- auto msg = std_msgs::msg::String();
|
|
|
+ // auto msg = std_msgs::msg::String();
|
|
|
std::stringstream ss;
|
|
|
ss << (value ? "CHARGING_VOLTAGE_DETECTED" : "CHARGING_VOLTAGE_LOST")
|
|
|
<< ":timestamp=" << node_->now().seconds()
|
|
|
@@ -1306,8 +1306,9 @@ void LidarScanController::setChargingVoltage(bool value)
|
|
|
ss << ",message=充电电压已断开";
|
|
|
RCLCPP_INFO(node_->get_logger(), "充电电压已断开");
|
|
|
}
|
|
|
- msg.data = ss.str();
|
|
|
- pub_charging_voltage_->publish(msg);
|
|
|
+ // msg.data = ss.str();
|
|
|
+ // pub_charging_voltage_->publish(msg);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
bool LidarScanController::getChargingVoltage() const
|
|
|
@@ -1321,5 +1322,5 @@ bool LidarScanController::getChargingVoltage() const
|
|
|
// return true;
|
|
|
// }
|
|
|
// return false;
|
|
|
- return detect_charging_voltage_;
|
|
|
+ return detect_charging_voltage_;
|
|
|
}
|