添加TR360雷达通信功能和命令交互系统
- 添加多端口通信支持:TR360-3-60(10195)和TR360-4-60(20295) - 实现TCP命令服务器,支持带\r\n的雷达命令 - 添加命令历史记录功能 - 支持status、history、set_port等内置命令 - 更新launch文件配置双雷达节点 - 添加测试脚本和文档
This commit is contained in:
1
.catkin_workspace
Normal file
1
.catkin_workspace
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# This file currently only serves to mark the location of a catkin workspace for tool integration
|
||||||
56
.gitignore
vendored
Normal file
56
.gitignore
vendored
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
# Build directories
|
||||||
|
/build/
|
||||||
|
/devel/
|
||||||
|
/install/
|
||||||
|
|
||||||
|
# IDE files
|
||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
|
||||||
|
# Python cache
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
|
# ROS logs
|
||||||
|
.log/
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Catkin tools
|
||||||
|
.catkin_tools/
|
||||||
|
profiles/
|
||||||
|
profiles.yaml
|
||||||
|
|
||||||
|
# CMake
|
||||||
|
CMakeCache.txt
|
||||||
|
CMakeFiles/
|
||||||
|
cmake_install.cmake
|
||||||
|
Makefile
|
||||||
|
|
||||||
|
# Compiled Object files
|
||||||
|
*.o
|
||||||
|
*.a
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Executables
|
||||||
|
*.exe
|
||||||
|
*.out
|
||||||
|
*.app
|
||||||
|
|
||||||
|
# OS generated files
|
||||||
|
.DS_Store
|
||||||
|
.DS_Store?
|
||||||
|
._*
|
||||||
|
.Spotlight-V100
|
||||||
|
.Trashes
|
||||||
|
ehthumbs.db
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# Temporary files
|
||||||
|
*.tmp
|
||||||
|
*.temp
|
||||||
|
|
||||||
|
# Test files
|
||||||
|
test_results/
|
||||||
110
COMMAND_FEATURES.md
Normal file
110
COMMAND_FEATURES.md
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
# TR360 雷达通信命令功能
|
||||||
|
|
||||||
|
## 新增功能
|
||||||
|
|
||||||
|
### 1. 多端口通信支持
|
||||||
|
- **TR360-3-60**: 数据端口 `10195`,命令端口 `11195` (10195 + 1000)
|
||||||
|
- **TR360-4-60**: 数据端口 `20295`,命令端口 `21295` (20295 + 1000)
|
||||||
|
|
||||||
|
### 2. 雷达命令交互
|
||||||
|
- 支持通过TCP连接发送命令到雷达
|
||||||
|
- 命令以 `\r\n` 结尾(符合雷达通信协议)
|
||||||
|
- 响应也以 `\r\n` 结尾
|
||||||
|
|
||||||
|
### 3. 命令历史记录
|
||||||
|
- 自动记录所有发送的命令
|
||||||
|
- 支持查看历史命令列表
|
||||||
|
- 可配置最大历史记录数量(默认100条)
|
||||||
|
|
||||||
|
## 可用命令
|
||||||
|
|
||||||
|
### 基本命令
|
||||||
|
- `status` - 查看雷达状态信息
|
||||||
|
- `history` - 显示命令历史记录
|
||||||
|
- `set_port <port>` - 设置数据端口(需要雷达支持)
|
||||||
|
|
||||||
|
### 自定义命令
|
||||||
|
可以扩展 `processRadarCommand()` 方法来支持更多雷达特定命令:
|
||||||
|
- `start_scan` - 开始扫描
|
||||||
|
- `stop_scan` - 停止扫描
|
||||||
|
- `get_config` - 获取配置
|
||||||
|
- `set_config <param> <value>` - 设置参数
|
||||||
|
|
||||||
|
## 使用方法
|
||||||
|
|
||||||
|
### 1. 启动雷达节点
|
||||||
|
```bash
|
||||||
|
roslaunch tr360_ros tr360.launch
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 使用telnet测试命令
|
||||||
|
```bash
|
||||||
|
# 连接TR360-3-60命令端口
|
||||||
|
telnet 192.168.1.193 11195
|
||||||
|
|
||||||
|
# 发送命令(自动添加回车换行)
|
||||||
|
status\r\n
|
||||||
|
# 响应示例
|
||||||
|
Radar type: TR360-3-60, Port: 10195\r\n
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 使用netcat测试
|
||||||
|
```bash
|
||||||
|
# 发送单个命令
|
||||||
|
echo "status" | nc 192.168.1.193 11195
|
||||||
|
|
||||||
|
# 交互式测试
|
||||||
|
nc 192.168.1.193 11195
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. 使用Python脚本测试
|
||||||
|
```bash
|
||||||
|
python3 test_radar_commands.py
|
||||||
|
```
|
||||||
|
|
||||||
|
## 配置参数
|
||||||
|
|
||||||
|
在launch文件中可配置以下参数:
|
||||||
|
- `enable_command_server`: 是否启用命令服务器(默认true)
|
||||||
|
- `max_history_size`: 最大历史记录数量(默认100)
|
||||||
|
- `local_port`: 数据接收端口(根据雷达类型自动设置)
|
||||||
|
|
||||||
|
## 技术实现
|
||||||
|
|
||||||
|
### 网络架构
|
||||||
|
- **UDP**: 用于高速点云数据传输(端口10195/20295)
|
||||||
|
- **TCP**: 用于可靠命令交互(端口11195/21295)
|
||||||
|
|
||||||
|
### 多线程处理
|
||||||
|
- 主线程处理UDP数据接收和点云处理
|
||||||
|
- 独立线程处理每个TCP命令连接
|
||||||
|
- 使用select()实现多路复用,避免阻塞
|
||||||
|
|
||||||
|
### 命令协议
|
||||||
|
- 命令格式: `command[\r\n]`
|
||||||
|
- 响应格式: `response[\r\n]`
|
||||||
|
- 支持标准雷达命令语法
|
||||||
|
|
||||||
|
## 扩展开发
|
||||||
|
|
||||||
|
要添加新的雷达命令,在 `processRadarCommand()` 方法中添加处理逻辑:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
else if (command == "custom_command") {
|
||||||
|
// 处理自定义命令
|
||||||
|
return "Custom command executed";
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 故障排除
|
||||||
|
|
||||||
|
1. **端口冲突**: 检查端口是否被其他程序占用
|
||||||
|
2. **连接拒绝**: 确认命令服务器已启用(enable_command_server=true)
|
||||||
|
3. **无响应**: 检查防火墙设置和网络连接
|
||||||
|
4. **命令格式错误**: 确保命令以 `\r\n` 结尾
|
||||||
|
|
||||||
|
## 性能考虑
|
||||||
|
|
||||||
|
- 命令服务器使用独立端口,不影响点云数据传输性能
|
||||||
|
- 历史记录使用vector存储,内存占用可控
|
||||||
|
- TCP连接处理使用线程池模式,避免阻塞主循环
|
||||||
1
src
Submodule
1
src
Submodule
Submodule src added at ec1c1e29cd
41
test_commands.sh
Executable file
41
test_commands.sh
Executable file
@@ -0,0 +1,41 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
echo "Testing TR360 Radar Command Interface"
|
||||||
|
echo "===================================="
|
||||||
|
|
||||||
|
# TR360-3-60 命令端口: 10195 + 1000 = 11195
|
||||||
|
# TR360-4-60 命令端口: 20295 + 1000 = 21295
|
||||||
|
|
||||||
|
HOST="192.168.1.193"
|
||||||
|
PORT_3_60=11195
|
||||||
|
PORT_4_60=21295
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "1. Testing TR360-3-60 commands (port $PORT_3_60):"
|
||||||
|
echo "-----------------------------------------------"
|
||||||
|
|
||||||
|
# 测试基本命令
|
||||||
|
echo "Testing status command:"
|
||||||
|
echo "status" | nc -w 3 $HOST $PORT_3_60
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "Testing history command:"
|
||||||
|
echo "history" | nc -w 3 $HOST $PORT_3_60
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "Testing set_port command:"
|
||||||
|
echo "set_port 10195" | nc -w 3 $HOST $PORT_3_60
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "2. Testing TR360-4-60 commands (port $PORT_4_60):"
|
||||||
|
echo "-----------------------------------------------"
|
||||||
|
|
||||||
|
echo "Testing status command:"
|
||||||
|
echo "status" | nc -w 3 $HOST $PORT_4_60
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "Testing custom command:"
|
||||||
|
echo "get_config" | nc -w 3 $HOST $PORT_4_60
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "Command testing completed!"
|
||||||
63
test_radar_commands.py
Normal file
63
test_radar_commands.py
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import socket
|
||||||
|
import time
|
||||||
|
|
||||||
|
def test_radar_commands(host='192.168.1.193', port=11195):
|
||||||
|
"""测试雷达命令功能"""
|
||||||
|
|
||||||
|
print(f"Connecting to radar command server at {host}:{port}")
|
||||||
|
|
||||||
|
try:
|
||||||
|
# 连接到命令服务器
|
||||||
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
sock.connect((host, port))
|
||||||
|
|
||||||
|
# 测试命令列表
|
||||||
|
test_commands = [
|
||||||
|
"status",
|
||||||
|
"get_config",
|
||||||
|
"set_port 10195",
|
||||||
|
"start_scan",
|
||||||
|
"stop_scan",
|
||||||
|
"history"
|
||||||
|
]
|
||||||
|
|
||||||
|
for cmd in test_commands:
|
||||||
|
# 发送命令(添加回车换行)
|
||||||
|
full_cmd = cmd + "\r\n"
|
||||||
|
sock.send(full_cmd.encode())
|
||||||
|
|
||||||
|
# 接收响应
|
||||||
|
response = sock.recv(1024).decode().strip()
|
||||||
|
print(f"Command: {cmd}")
|
||||||
|
print(f"Response: {response}")
|
||||||
|
print("-" * 50)
|
||||||
|
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
sock.close()
|
||||||
|
print("Test completed successfully!")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error: {e}")
|
||||||
|
|
||||||
|
def test_multiple_radars():
|
||||||
|
"""测试多个雷达端口的命令功能"""
|
||||||
|
|
||||||
|
radar_ports = {
|
||||||
|
"TR360-3-60": 11195, # 10195 + 1000
|
||||||
|
"TR360-4-60": 21295 # 20295 + 1000
|
||||||
|
}
|
||||||
|
|
||||||
|
for radar_type, port in radar_ports.items():
|
||||||
|
print(f"\n=== Testing {radar_type} (port {port}) ===")
|
||||||
|
test_radar_commands(port=port)
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# 测试单个雷达
|
||||||
|
test_radar_commands()
|
||||||
|
|
||||||
|
# 测试多个雷达
|
||||||
|
# test_multiple_radars()
|
||||||
Reference in New Issue
Block a user