Compare commits
6 Commits
5cf5cdafd8
...
3bb1e9d298
| Author | SHA1 | Date | |
|---|---|---|---|
| 3bb1e9d298 | |||
| 752b98ae79 | |||
| 0fbded215d | |||
| 1ea853111f | |||
| 93912c7214 | |||
| c024a82b22 |
22
radio_ctrl.sh
Executable file
22
radio_ctrl.sh
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
source install/setup.bash # ros workspace
|
||||||
|
{
|
||||||
|
gnome-terminal --title="radio" --tab "XXD_ros" -- bash -c "ros2 run radio_ctrl radio_ctrl_node"
|
||||||
|
}&
|
||||||
|
sleep 0.2s
|
||||||
|
|
||||||
|
{
|
||||||
|
gnome-terminal --title="mc" --tab "XXD_ros" -- bash -c "ros2 run mc mc_node"
|
||||||
|
}&
|
||||||
|
sleep 0.2s
|
||||||
|
|
||||||
|
{
|
||||||
|
gnome-terminal --title="ctrl_arbiter" --tab "XXD_ros" -- bash -c "ros2 run ctrl_arbiter ctrl_arbiter_node"
|
||||||
|
}&
|
||||||
|
sleep 0.2s
|
||||||
|
|
||||||
|
{
|
||||||
|
gnome-terminal --title="report" --tab "XXD_ros" -- bash -c "ros2 run mqtt_report mqtt_report_node"
|
||||||
|
}&
|
||||||
|
sleep 0.2s
|
||||||
@ -19,8 +19,8 @@ if(${ENABLE_TRANSFORM})
|
|||||||
add_definitions("-DENABLE_TRANSFORM")
|
add_definitions("-DENABLE_TRANSFORM")
|
||||||
endif(${ENABLE_TRANSFORM})
|
endif(${ENABLE_TRANSFORM})
|
||||||
|
|
||||||
set(rs_driver_INCLUDE_DIRS "/home/alvin/project/zxwl/sweeper/200_123/sweeper_200/src/airy/rslidar_sdk-main/src/rs_driver/src;/usr/local/rslidar_sdk/include")
|
set(rs_driver_INCLUDE_DIRS "/home/nvidia/Downloads/sweeper_200/src/airy/rslidar_sdk-main/src/rs_driver/src;/usr/local/rslidar_sdk/include")
|
||||||
set(RS_DRIVER_INCLUDE_DIRS "/home/alvin/project/zxwl/sweeper/200_123/sweeper_200/src/airy/rslidar_sdk-main/src/rs_driver/src;/usr/local/rslidar_sdk/include")
|
set(RS_DRIVER_INCLUDE_DIRS "/home/nvidia/Downloads/sweeper_200/src/airy/rslidar_sdk-main/src/rs_driver/src;/usr/local/rslidar_sdk/include")
|
||||||
|
|
||||||
set(rs_driver_LIBRARIES "pthread;pcap")
|
set(rs_driver_LIBRARIES "pthread;pcap")
|
||||||
set(RS_DRIVER_LIBRARIES "pthread;pcap")
|
set(RS_DRIVER_LIBRARIES "pthread;pcap")
|
||||||
|
|||||||
@ -6,4 +6,13 @@
|
|||||||
"info_topic": "/zxwl/vehicle/{vid}/info",
|
"info_topic": "/zxwl/vehicle/{vid}/info",
|
||||||
"fault_topic": "/zxwl/vehicle/{vid}/fault"
|
"fault_topic": "/zxwl/vehicle/{vid}/fault"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"vid": "V060003",
|
||||||
|
"mqtt": {
|
||||||
|
"ip": "36.153.162.171",
|
||||||
|
"port": 19683,
|
||||||
|
"info_topic": "/zxwl/vehicle/{vid}/info",
|
||||||
|
"fault_topic": "/zxwl/vehicle/{vid}/fault"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -38,7 +38,6 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 连接服务器,支持最大重试次数
|
|
||||||
bool connect(int max_retries = 5)
|
bool connect(int max_retries = 5)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(mtx_);
|
std::lock_guard<std::mutex> lock(mtx_);
|
||||||
@ -48,7 +47,7 @@ public:
|
|||||||
MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer;
|
MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer;
|
||||||
conn_opts.keepAliveInterval = 20;
|
conn_opts.keepAliveInterval = 20;
|
||||||
conn_opts.cleansession = 1;
|
conn_opts.cleansession = 1;
|
||||||
conn_opts.connectTimeout = 5; // ✅ 限制阻塞时间
|
conn_opts.connectTimeout = 5;
|
||||||
|
|
||||||
if (!username_.empty())
|
if (!username_.empty())
|
||||||
{
|
{
|
||||||
|
|||||||
@ -323,7 +323,7 @@ private:
|
|||||||
for (int code : vehicle_error_code.getAllErrorCodes())
|
for (int code : vehicle_error_code.getAllErrorCodes())
|
||||||
{
|
{
|
||||||
std::string fault_json = generateFaultJson(code, config.vid, getCurrentTimestampMs());
|
std::string fault_json = generateFaultJson(code, config.vid, getCurrentTimestampMs());
|
||||||
if (!mqtt_client_.publish(fault_topic_, fault_json, 1)) // QoS=1
|
if (!mqtt_client_.publish(fault_topic_, fault_json, 0))
|
||||||
{
|
{
|
||||||
RCLCPP_WARN(this->get_logger(), "Failed to publish fault code %d to MQTT", code);
|
RCLCPP_WARN(this->get_logger(), "Failed to publish fault code %d to MQTT", code);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <random>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
@ -227,6 +228,25 @@ private:
|
|||||||
rclcpp::Subscription<sweeper_interfaces::msg::Rtk>::SharedPtr gps_subscribe_;
|
rclcpp::Subscription<sweeper_interfaces::msg::Rtk>::SharedPtr gps_subscribe_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::string generate_mqtt_client_id()
|
||||||
|
{
|
||||||
|
// 获取当前时间戳(以毫秒为单位)
|
||||||
|
auto now = std::chrono::system_clock::now();
|
||||||
|
auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
|
||||||
|
|
||||||
|
// 生成一个 4 位随机数
|
||||||
|
std::random_device rd;
|
||||||
|
std::mt19937 gen(rd());
|
||||||
|
std::uniform_int_distribution<> dis(1000, 9999);
|
||||||
|
int random_num = dis(gen);
|
||||||
|
|
||||||
|
// 拼接成 client ID
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << "client_" << millis << "_" << std::setw(4) << std::setfill('0') << random_num;
|
||||||
|
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
bool load_config(const std::string &path)
|
bool load_config(const std::string &path)
|
||||||
{
|
{
|
||||||
Json::Reader reader;
|
Json::Reader reader;
|
||||||
@ -250,7 +270,7 @@ bool load_config(const std::string &path)
|
|||||||
// int port = m["inter_net_port"].asInt(); // 11883
|
// int port = m["inter_net_port"].asInt(); // 11883
|
||||||
|
|
||||||
g_conf.address = ip + ":" + std::to_string(port);
|
g_conf.address = ip + ":" + std::to_string(port);
|
||||||
g_conf.client_id = "sweeper_CLIENT_1532_GPS"; // 如需可改成 VID 等
|
g_conf.client_id = generate_mqtt_client_id();
|
||||||
g_conf.user = m["mqtt_user"].asString();
|
g_conf.user = m["mqtt_user"].asString();
|
||||||
g_conf.password = m["mqtt_password"].asString();
|
g_conf.password = m["mqtt_password"].asString();
|
||||||
g_conf.pub_gps_topic = m["pub_gps_topic"].asString();
|
g_conf.pub_gps_topic = m["pub_gps_topic"].asString();
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <random>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
@ -43,7 +44,7 @@ std::string mqtt_topic_remote;
|
|||||||
|
|
||||||
// 新增:声明未定义的常量
|
// 新增:声明未定义的常量
|
||||||
std::string ADDRESS;
|
std::string ADDRESS;
|
||||||
std::string CLIENTID_SUB = "sweeper200_sub"; // 客户端ID,提供默认值
|
std::string CLIENTID_SUB; // 客户端ID,提供默认值
|
||||||
|
|
||||||
std::chrono::steady_clock::time_point last_message_time = std::chrono::steady_clock::now();
|
std::chrono::steady_clock::time_point last_message_time = std::chrono::steady_clock::now();
|
||||||
constexpr auto QOS = 1;
|
constexpr auto QOS = 1;
|
||||||
@ -53,6 +54,25 @@ char sub_buff[500];
|
|||||||
|
|
||||||
car_ctrl car_ctrl_mes;
|
car_ctrl car_ctrl_mes;
|
||||||
|
|
||||||
|
std::string generate_mqtt_client_id()
|
||||||
|
{
|
||||||
|
// 获取当前时间戳(以毫秒为单位)
|
||||||
|
auto now = std::chrono::system_clock::now();
|
||||||
|
auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
|
||||||
|
|
||||||
|
// 生成一个 4 位随机数
|
||||||
|
std::random_device rd;
|
||||||
|
std::mt19937 gen(rd());
|
||||||
|
std::uniform_int_distribution<> dis(1000, 9999);
|
||||||
|
int random_num = dis(gen);
|
||||||
|
|
||||||
|
// 拼接成 client ID
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << "client_" << millis << "_" << std::setw(4) << std::setfill('0') << random_num;
|
||||||
|
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
void sendResponse(MQTTClient client, const std::string &topic, long long seqNo, int code, std::string msg)
|
void sendResponse(MQTTClient client, const std::string &topic, long long seqNo, int code, std::string msg)
|
||||||
{
|
{
|
||||||
// 使用JSON库构建响应数据
|
// 使用JSON库构建响应数据
|
||||||
@ -428,7 +448,7 @@ void init_main()
|
|||||||
mqtt_topic_remote = root["mqtt"]["remote_topic"].asString();
|
mqtt_topic_remote = root["mqtt"]["remote_topic"].asString();
|
||||||
// 添加对sub_topic的初始化
|
// 添加对sub_topic的初始化
|
||||||
sub_topic = mqtt_topic_remote;
|
sub_topic = mqtt_topic_remote;
|
||||||
CLIENTID_SUB = CLIENTID_SUB + "_" + mqtt_vid;
|
CLIENTID_SUB = generate_mqtt_client_id();
|
||||||
// ADDRESS = mqtt_inter_net_address + ":" + std::to_string(mqtt_inter_net_port);
|
// ADDRESS = mqtt_inter_net_address + ":" + std::to_string(mqtt_inter_net_port);
|
||||||
ADDRESS = mqtt_external_net_address + ":" + std::to_string(mqtt_external_net_port);
|
ADDRESS = mqtt_external_net_address + ":" + std::to_string(mqtt_external_net_port);
|
||||||
cout << "ADDRESS: " << ADDRESS << endl;
|
cout << "ADDRESS: " << ADDRESS << endl;
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
#include "task_manager_node.hpp"
|
#include "task_manager_node.hpp"
|
||||||
#include "sweeper_interfaces/msg/sub.hpp"
|
#include "sweeper_interfaces/msg/sub.hpp"
|
||||||
#include <signal.h> // 添加信号处理头文件
|
#include <signal.h> // 添加信号处理头文件
|
||||||
|
#include <random>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -35,7 +36,7 @@ std::string sub_topic;
|
|||||||
|
|
||||||
// 修复变量声明和初始化
|
// 修复变量声明和初始化
|
||||||
std::string ADDRESS;
|
std::string ADDRESS;
|
||||||
std::string CLIENTID_SUB = "sweeper200_task"; // 客户端ID
|
std::string CLIENTID_SUB; // 客户端ID
|
||||||
std::string destinationFilePath1 = "./gps_load_now.txt";
|
std::string destinationFilePath1 = "./gps_load_now.txt";
|
||||||
std::chrono::steady_clock::time_point last_message_time = std::chrono::steady_clock::now();
|
std::chrono::steady_clock::time_point last_message_time = std::chrono::steady_clock::now();
|
||||||
constexpr auto QOS = 0;
|
constexpr auto QOS = 0;
|
||||||
@ -49,6 +50,25 @@ TaskStatus status_up = TaskStatus::PENDING;
|
|||||||
CurrentTask currentTask;
|
CurrentTask currentTask;
|
||||||
std::mutex taskMutex;
|
std::mutex taskMutex;
|
||||||
|
|
||||||
|
std::string generate_mqtt_client_id()
|
||||||
|
{
|
||||||
|
// 获取当前时间戳(以毫秒为单位)
|
||||||
|
auto now = std::chrono::system_clock::now();
|
||||||
|
auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
|
||||||
|
|
||||||
|
// 生成一个 4 位随机数
|
||||||
|
std::random_device rd;
|
||||||
|
std::mt19937 gen(rd());
|
||||||
|
std::uniform_int_distribution<> dis(1000, 9999);
|
||||||
|
int random_num = dis(gen);
|
||||||
|
|
||||||
|
// 拼接成 client ID
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << "client_" << millis << "_" << std::setw(4) << std::setfill('0') << random_num;
|
||||||
|
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
// 信号处理函数
|
// 信号处理函数
|
||||||
void signalHandler(int signum)
|
void signalHandler(int signum)
|
||||||
{
|
{
|
||||||
@ -732,7 +752,7 @@ void init_main()
|
|||||||
mqtt_topic_push_status = root["mqtt"]["mqtt_topic_push_status"].asString();
|
mqtt_topic_push_status = root["mqtt"]["mqtt_topic_push_status"].asString();
|
||||||
// 添加对sub_topic的初始化
|
// 添加对sub_topic的初始化
|
||||||
sub_topic = mqtt_topic_sub_task;
|
sub_topic = mqtt_topic_sub_task;
|
||||||
CLIENTID_SUB = CLIENTID_SUB + "_" + mqtt_vid;
|
CLIENTID_SUB = generate_mqtt_client_id();
|
||||||
// ADDRESS = mqtt_inter_net_address + ":" + std::to_string(mqtt_inter_net_port);
|
// ADDRESS = mqtt_inter_net_address + ":" + std::to_string(mqtt_inter_net_port);
|
||||||
ADDRESS = mqtt_external_net_address + ":" + std::to_string(mqtt_external_net_port);
|
ADDRESS = mqtt_external_net_address + ":" + std::to_string(mqtt_external_net_port);
|
||||||
cout << "ADDRESS: " << ADDRESS << endl;
|
cout << "ADDRESS: " << ADDRESS << endl;
|
||||||
|
|||||||
11
start_all.sh
11
start_all.sh
@ -1,24 +1,21 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# 加载 ROS2 系统环境
|
|
||||||
source /opt/ros/foxy/setup.bash
|
|
||||||
|
|
||||||
# 加载你的工作空间环境
|
# 加载你的工作空间环境
|
||||||
source ~/Downloads/sweeper_whu/install/setup.bash
|
source ~/Downloads/sweeper_200/install/setup.bash
|
||||||
|
|
||||||
# 启动节点
|
# 启动节点
|
||||||
ros2 run radio_ctrl radio_ctrl_node &
|
ros2 run radio_ctrl radio_ctrl_node &
|
||||||
ros2 run mc mc_node &
|
ros2 run mc mc_node &
|
||||||
ros2 run ctrl_arbiter ctrl_arbiter_node &
|
ros2 run ctrl_arbiter ctrl_arbiter_node &
|
||||||
ros2 run mqtt_report mqtt_report_node &
|
ros2 run mqtt_report mqtt_report_node &
|
||||||
ros2 run rtk rtk_node &
|
|
||||||
ros2 run pub_gps pub_gps_node &
|
|
||||||
ros2 launch rslidar_sdk start_double.launch.py &
|
ros2 launch rslidar_sdk start_double.launch.py &
|
||||||
|
ros2 run rtk rtk_node &
|
||||||
ros2 run route route_node &
|
ros2 run route route_node &
|
||||||
ros2 run remote remote_node &
|
ros2 run sub sub_node &
|
||||||
ros2 run task_manager task_manager_node &
|
ros2 run task_manager task_manager_node &
|
||||||
ros2 run pl pl_node &
|
ros2 run pl pl_node &
|
||||||
ros2 launch fu fu.launch.py &
|
ros2 launch fu fu.launch.py &
|
||||||
|
ros2 run pub_gps pub_gps_node &
|
||||||
|
|
||||||
wait
|
wait
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user