UNPKG

dynamixel

Version:

Node.js library for controlling DYNAMIXEL servo motors via U2D2 interface with Protocol 2.0 support

123 lines (102 loc) โ€ข 4.69 kB
#!/usr/bin/env node import { DynamixelController } from '../index.js'; /** * Example: USB Diagnostics * This example helps diagnose USB connection issues with the U2D2 device */ async function main() { console.log('๐Ÿ”ง DYNAMIXEL U2D2 USB Diagnostics Tool\n'); console.log('This tool will help diagnose USB connection issues with your U2D2 device.\n'); // Run comprehensive diagnostics const diagnostics = DynamixelController.performUSBDiagnostics(); // Additional checks console.log('\n๐Ÿงช Additional Checks:'); // Check Node.js version compatibility const nodeVersion = process.version; const majorVersion = parseInt(nodeVersion.slice(1).split('.')[0]); if (majorVersion < 16) { console.log(' โš ๏ธ Node.js version may be too old (current: ' + nodeVersion + ')'); console.log(' โ€ข Recommended: Node.js 16 or higher'); } else { console.log(' โœ… Node.js version is compatible (' + nodeVersion + ')'); } // Check if running as root/admin if (diagnostics.systemInfo.platform === 'darwin' && !diagnostics.systemInfo.isRoot) { console.log(' โš ๏ธ Not running with elevated privileges'); console.log(' โ€ข This is often required on macOS for USB access'); } if (diagnostics.u2d2Found) { console.log('\n๐Ÿงช Testing U2D2 Connection:'); const controller = new DynamixelController({ timeout: 5000, debug: true // Enable USB debugging }); // Set up event listeners for detailed error reporting controller.on('error', (error) => { console.error('โŒ Connection Error Details:', error.message); // Provide specific guidance based on error type if (error.message.includes('Permission denied') || error.message.includes('LIBUSB_ERROR_ACCESS')) { console.log('\n๐Ÿ’ก Access Error Solutions:'); console.log(' 1. Try running with sudo:'); console.log(' sudo node examples/usb-diagnostics.js'); console.log(' 2. Check if other software is using the U2D2'); console.log(' 3. Try unplugging and reconnecting the U2D2'); console.log(' 4. On newer macOS, check Privacy & Security settings'); } }); try { console.log(' Attempting connection...'); const connected = await controller.connect(); if (connected) { console.log(' โœ… Successfully connected to U2D2!'); console.log(' ๐Ÿ“ก Connection is working properly'); // Quick test console.log(' ๐Ÿงช Testing basic communication...'); try { await controller.ping(1, 100); // Quick ping test console.log(' โœ… Communication test passed'); } catch (pingError) { console.log(' โ„น๏ธ No DYNAMIXEL found at ID 1 (this is normal if no devices are connected)'); } await controller.disconnect(); console.log(' โœ… Disconnected successfully'); } else { console.log(' โŒ Failed to connect to U2D2'); } } catch (testError) { console.log(' โŒ Connection test failed:', testError.message); } } // Summary and next steps console.log('\n๐Ÿ“‹ Summary:'); if (diagnostics.u2d2Found) { console.log(' โœ… U2D2 device detected'); console.log(' ๐Ÿ’ป Platform:', diagnostics.systemInfo.platform); console.log(' ๐Ÿ”‘ Root access:', diagnostics.systemInfo.isRoot); console.log('\n๐ŸŽฏ Next Steps:'); if (diagnostics.systemInfo.platform === 'darwin' && !diagnostics.systemInfo.isRoot) { console.log(' 1. Try running with: sudo node examples/device-discovery.js'); console.log(' 2. Or check macOS Privacy & Security settings'); } console.log(' 3. Ensure no other applications are using the U2D2'); console.log(' 4. Try the device discovery example: npm run example:discovery'); } else { console.log(' โŒ U2D2 device not found'); console.log('\n๐ŸŽฏ Troubleshooting Steps:'); console.log(' 1. Check USB cable connection'); console.log(' 2. Try a different USB port'); console.log(' 3. Verify U2D2 power (LED should be on)'); console.log(' 4. Check device manager (Windows) or system info (macOS/Linux)'); } console.log('\n๐Ÿ“š Additional Resources:'); console.log(' โ€ข U2D2 Manual: https://emanual.robotis.com/docs/en/parts/interface/u2d2/'); console.log(' โ€ข DYNAMIXEL SDK: https://github.com/ROBOTIS-GIT/DynamixelSDK'); console.log(' โ€ข Driver Downloads: https://ftdichip.com/drivers/'); } // Handle process termination process.on('SIGINT', () => { console.log('\n\nโš ๏ธ Diagnostics interrupted'); process.exit(0); }); // Run diagnostics main().catch(console.error);