- Unity frontend with ROS-TCP-Connector for ROS2 communication - Docker-based ROS2 Jazzy backend with MoveIt2 integration - Support for 1-9 DOF manipulators - UR5 robot configuration and URDF files - Assembly task feasibility analysis tools - Comprehensive documentation and deployment guides 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
69 lines
2.2 KiB
C#
69 lines
2.2 KiB
C#
using System.Collections;
|
|
using UnityEngine;
|
|
using UnityMoveIt2.Communication;
|
|
|
|
namespace UnityMoveIt2.Tests
|
|
{
|
|
/// <summary>
|
|
/// 自动连接测试 - 用于命令行测试
|
|
/// Automatic connection test - for command line testing
|
|
/// </summary>
|
|
public class AutoConnectionTest : MonoBehaviour
|
|
{
|
|
private ROSTCPBridge bridge;
|
|
private float testDuration = 30f; // 测试30秒
|
|
private float startTime;
|
|
|
|
void Start()
|
|
{
|
|
Debug.Log("=================================================");
|
|
Debug.Log("[AutoConnectionTest] 开始自动连接测试");
|
|
Debug.Log("=================================================");
|
|
|
|
// 查找或创建 ROSTCPBridge
|
|
bridge = FindObjectOfType<ROSTCPBridge>();
|
|
if (bridge == null)
|
|
{
|
|
GameObject bridgeObj = new GameObject("ROSTCPBridge");
|
|
bridge = bridgeObj.AddComponent<ROSTCPBridge>();
|
|
Debug.Log("[AutoConnectionTest] 创建新的 ROSTCPBridge 实例");
|
|
}
|
|
|
|
startTime = Time.time;
|
|
StartCoroutine(MonitorConnection());
|
|
}
|
|
|
|
IEnumerator MonitorConnection()
|
|
{
|
|
float lastCheckTime = Time.time;
|
|
int checkCount = 0;
|
|
|
|
while (Time.time - startTime < testDuration)
|
|
{
|
|
checkCount++;
|
|
float elapsed = Time.time - startTime;
|
|
|
|
Debug.Log($"[AutoConnectionTest] 检查 #{checkCount} - 已运行: {elapsed:F1}秒");
|
|
|
|
yield return new WaitForSeconds(5f);
|
|
}
|
|
|
|
Debug.Log("=================================================");
|
|
Debug.Log($"[AutoConnectionTest] 测试完成 - 运行了 {testDuration} 秒");
|
|
Debug.Log("=================================================");
|
|
|
|
// 退出 Unity
|
|
#if UNITY_EDITOR
|
|
UnityEditor.EditorApplication.isPlaying = false;
|
|
#else
|
|
Application.Quit();
|
|
#endif
|
|
}
|
|
|
|
void OnDestroy()
|
|
{
|
|
Debug.Log("[AutoConnectionTest] 测试结束,清理资源");
|
|
}
|
|
}
|
|
}
|