#!/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())