dynamixel
Version:
Node.js library for controlling DYNAMIXEL servo motors via U2D2 interface with Protocol 2.0 support
53 lines (52 loc) • 2.18 kB
TypeScript
/**
* DYNAMIXEL Protocol 2.0 implementation
* Handles packet construction, parsing, and CRC calculation
*/
export class Protocol2 {
/**
* Calculate CRC-16 for DYNAMIXEL Protocol 2.0
* Based on official ROBOTIS code: http://support.robotis.com/en/product/actuator/dynamixel_pro/communication/crc.htm
* CRC-16 (IBM/ANSI) - Polynomial: x16 + x15 + x2 + 1 (0x8005), Initial Value: 0
* @param {Buffer|Array} data - Data to calculate CRC for
* @returns {number} - 16-bit CRC value
*/
static calculateCRC(data: Buffer | any[]): number;
/**
* Create an instruction packet
* @param {number} id - DYNAMIXEL ID (0-252, 0xFE for broadcast)
* @param {number} instruction - Instruction byte
* @param {Array|Buffer} parameters - Parameter data
* @returns {Buffer} - Complete instruction packet
*/
static createInstructionPacket(id: number, instruction: number, parameters?: any[] | Buffer): Buffer;
/**
* Parse a status packet
* @param {Buffer} buffer - Raw packet data
* @returns {Object|null} - Parsed packet or null if invalid
*/
static parseStatusPacket(buffer: Buffer): Object | null;
/**
* Create a PING instruction packet
* @param {number} id - DYNAMIXEL ID (0-252, 0xFE for broadcast)
* @returns {Buffer} - PING instruction packet
*/
static createPingPacket(id: number): Buffer;
/**
* Parse PING status packet to extract device information
* @param {Object} statusPacket - Parsed status packet
* @returns {Object|null} - Device information or null if not a PING response
*/
static parsePingResponse(statusPacket: Object): Object | null;
/**
* Check if buffer contains a complete packet
* @param {Buffer} buffer - Buffer to check
* @returns {number} - Length of complete packet, or 0 if incomplete
*/
static getCompletePacketLength(buffer: Buffer): number;
/**
* Convert error code to human-readable string
* @param {number} errorCode - Error code from status packet
* @returns {string} - Error description
*/
static getErrorDescription(errorCode: number): string;
}