File size: 3,380 Bytes
dcf1b21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python3
"""Test Nova API connection and configuration."""

import os
import sys
from pathlib import Path

# Add parent directory to path
sys.path.insert(0, str(Path(__file__).parent.parent))

# Simple .env loader
def load_env_file(filepath):
    """Simple .env file loader."""
    if not filepath.exists():
        return {}
    env_vars = {}
    with open(filepath, 'r') as f:
        for line in f:
            line = line.strip()
            if line and not line.startswith('#') and '=' in line:
                key, value = line.split('=', 1)
                env_vars[key.strip()] = value.strip()
                os.environ[key.strip()] = value.strip()
    return env_vars


def main():
    # Load .env.local
    env_path = Path(__file__).parent.parent / ".env.local"
    if not env_path.exists():
        print(f"Error: {env_path} not found")
        return 1

    print(f"Loading environment from {env_path}")
    env_vars = load_env_file(env_path)

    # Import after loading env vars
    try:
        from robots.ur5 import nova_api
    except ImportError:
        print("Error: Could not import nova_api module")
        print("Make sure you're in the nova-sim directory")
        return 1

    # Try to create config
    print("\nTesting Nova API configuration...")
    try:
        config = nova_api.NovaApiConfig.from_env()
        print("✓ Configuration created successfully!")
        print(f"\n  Instance URL: {config.instance_url}")
        print(f"  Cell ID: {config.cell_id}")
        print(f"  Controller ID: {config.controller_id}")
        print(f"  Motion Group ID: {config.motion_group_id}")
        print(f"  Motion Group Model: {config.motion_group_model}")
        print(f"  TCP Name: {config.tcp_name}")
        print(f"  Response Rate: {config.response_rate_ms}ms")
    except ValueError as e:
        print(f"✗ Configuration error: {e}")
        return 1

    # Try to create client
    print("\nCreating Nova API client...")
    try:
        client = nova_api.NovaApiClient(config)
        print("✓ Client created successfully!")
    except Exception as e:
        print(f"✗ Client creation error: {e}")
        return 1

    # Try to fetch motion group description
    print("\nFetching motion group description...")
    try:
        description = client._ensure_motion_group_description()
        if description:
            print("✓ Successfully fetched motion group description!")
            print(f"\n  Motion Group Model: {description.get('motion_group_model', 'N/A')}")
            tcps = description.get('tcps', {})
            if tcps:
                print(f"  Available TCPs: {', '.join(tcps.keys())}")
        else:
            print("✗ No description returned")
            return 1
    except Exception as e:
        print(f"✗ Error fetching description: {e}")
        return 1

    print("\n" + "=" * 60)
    print("SUCCESS! Your Nova API configuration is working correctly.")
    print("=" * 60)
    print("\nYou can now use Nova API integration with the UR5 environment:")
    print("""
    from robots.ur5.ur5_env import UR5Env

    # Enable both state streaming and Nova IK
    env = UR5Env(
        render_mode="human",
        nova_api_config={
            "use_state_stream": True,
            "use_ik": True
        }
    )
    """)

    return 0


if __name__ == "__main__":
    sys.exit(main())