UNPKG

dynamixel

Version:

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

227 lines (226 loc) 7.9 kB
/** * @typedef {Object} DynamixelControllerOptions * @property {'usb'|'serial'|'webserial'|'auto'} [connectionType='auto'] - Connection type to use * @property {boolean} [deferConnection=false] - Whether to defer connection creation until connectToDevice is called * @property {number} [timeout=5000] - Connection timeout in milliseconds * @property {boolean} [debug=false] - Enable debug logging * @property {number} [baudRate=1000000] - Serial communication baud rate * @property {string} [portPath] - Specific port path for serial connections */ /** * Main DYNAMIXEL Controller * Manages connection and communication with DYNAMIXEL devices * Supports both USB and Serial connection methods */ export class DynamixelController extends EventEmitter<[never]> { /** * Get device model name from model number * @param {number} modelNumber - Model number from device * @returns {string} - Model name or 'Unknown' */ static getModelName(modelNumber: number): string; /** * @typedef {Object} CommunicationDevices * @property {Array<Object>} usb - Array of USB devices * @property {Array<Object>} serial - Array of serial devices * @property {boolean} webserial - Whether Web Serial API is available */ /** * Discover available communication devices (USB and Serial) * @returns {Promise<CommunicationDevices>} - Object containing USB and serial devices */ static discoverCommunicationDevices(): Promise<{ /** * - Array of USB devices */ usb: Array<Object>; /** * - Array of serial devices */ serial: Array<Object>; /** * - Whether Web Serial API is available */ webserial: boolean; }>; /** * Discover U2D2 devices specifically * @returns {Promise<Array>} - Array of U2D2-compatible devices */ static discoverU2D2Devices(): Promise<any[]>; /** * List available USB devices (for debugging) * @returns {Array} - Array of USB device information */ static listUSBDevices(): any[]; /** * List available serial ports * @returns {Promise<Array>} - Array of serial port information */ static listSerialPorts(): Promise<any[]>; /** * Get system information and troubleshooting recommendations * @returns {Object} - System information and recommendations */ static getSystemInfo(): Object; /** * Perform comprehensive USB diagnostics * @returns {Object} - Diagnostic results */ static performUSBDiagnostics(): Object; /** * @param {DynamixelControllerOptions} [options={}] - Controller options */ constructor(options?: DynamixelControllerOptions); connectionType: "usb" | "serial" | "webserial" | "auto"; connection: any; devices: Map<any, any>; isConnected: boolean; deferConnection: boolean; /** * Create the appropriate connection based on type * @param {Object} options - Connection options */ createConnection(options: Object): void; /** * Detect the best connection type for the current environment * @param {Object} options - Connection options * @returns {Object} - Connection instance */ detectBestConnection(options: Object): Object; /** * Set up connection event forwarding */ setupConnectionEvents(): void; /** * Connect to a specific device * @param {Object} deviceInfo - Device information from discovery * @param {Object} options - Connection options * @returns {Promise<boolean>} - Connection success */ connectToDevice(deviceInfo: Object, options?: Object): Promise<boolean>; /** * Connect to U2D2 device with auto-fallback * @param {string} portPath - Optional specific port path for serial connection * @returns {Promise<boolean>} - Connection success */ connect(portPath?: string): Promise<boolean>; /** * Get the detected connection type from the current connection * @returns {string} - Connection type */ getDetectedConnectionType(): string; /** * Disconnect from U2D2 device */ disconnect(): Promise<void>; /** * Ping a specific DYNAMIXEL device * @param {number} id - DYNAMIXEL ID * @param {number} timeout - Timeout in milliseconds * @returns {Promise<Object>} - Device information */ ping(id: number, timeout?: number): Promise<Object>; /** * Discover all DYNAMIXEL devices on the bus * @param {Object} options - Discovery options * @returns {Promise<Array>} - Array of discovered devices */ discoverDevices(options?: Object): Promise<any[]>; /** * Get a specific DYNAMIXEL device by ID * @param {number} id - DYNAMIXEL ID * @returns {DynamixelDevice|null} - Device instance or null if not found */ getDevice(id: number): DynamixelDevice | null; /** * Get all discovered devices * @returns {Array<DynamixelDevice>} - Array of device instances */ getAllDevices(): Array<DynamixelDevice>; /** * Get device count * @returns {number} - Number of discovered devices */ getDeviceCount(): number; /** * Add a device manually (if you know its ID and info) * @param {number} id - DYNAMIXEL ID * @param {Object} deviceInfo - Device information * @returns {DynamixelDevice} - Created device instance */ addDevice(id: number, deviceInfo?: Object): DynamixelDevice; /** * Set the baud rate for communication * @param {number} baudRate - Baud rate (e.g., 57600, 115200, 1000000) */ setBaudRate(baudRate: number): void; /** * Get the current baud rate * @returns {number} - Current baud rate */ getBaudRate(): number; /** * Remove a device from the controller * @param {number} id - DYNAMIXEL ID * @returns {boolean} - Success status */ removeDevice(id: number): boolean; /** * Check if controller is connected * @returns {boolean} - Connection status */ getConnectionStatus(): boolean; /** * Get connection instance (for advanced usage) * @returns {U2D2Connection} - Connection instance */ getConnection(): U2D2Connection; /** * Broadcast ping to all devices * @param {number} timeout - Timeout in milliseconds * @returns {Promise<Array>} - Array of responses */ broadcastPing(timeout?: number): Promise<any[]>; /** * Quick device discovery with progress reporting * @param {Function} onProgress - Progress callback (current, total, id) * @returns {Promise<Array>} - Array of discovered devices */ quickDiscovery(onProgress?: Function): Promise<any[]>; /** * Full device discovery (all possible IDs) * @param {Function} onProgress - Progress callback (current, total, id) * @returns {Promise<Array>} - Array of discovered devices */ fullDiscovery(onProgress?: Function): Promise<any[]>; } export type DynamixelControllerOptions = { /** * - Connection type to use */ connectionType?: "usb" | "serial" | "webserial" | "auto" | undefined; /** * - Whether to defer connection creation until connectToDevice is called */ deferConnection?: boolean | undefined; /** * - Connection timeout in milliseconds */ timeout?: number | undefined; /** * - Enable debug logging */ debug?: boolean | undefined; /** * - Serial communication baud rate */ baudRate?: number | undefined; /** * - Specific port path for serial connections */ portPath?: string | undefined; }; import { EventEmitter } from 'events'; import { DynamixelDevice } from './dynamixel/index.js'; import { U2D2Connection } from './transport/index.js';