UNPKG

@chart-sg/node-red-ros2-manager

Version:

Shared ROS2 context manager for Node-RED plugins. Eliminates conflicts and enables multi-plugin compatibility.

133 lines (118 loc) 3.88 kB
/** * @chart-sg/node-red-ros2-manager * * Shared ROS2 management platform for Chart Node-RED ROS2 plugins. * Provides centralized ROS2 infrastructure management including node lifecycle, * resource pooling, and thread coordination to prevent conflicts between * multiple ROS2 components in Node-RED. */ const { ros2SharedManager } = require('./lib/ros2-shared-manager'); // Export the manager interface module.exports = { /** * Get the shared ROS2 manager instance * @returns {ROS2SharedManager} The singleton shared manager */ getROS2Manager: () => { return ros2SharedManager; }, /** * Initialize ROS2 with the shared manager * @param {Object} options - Initialization options * @param {number} options.domain - ROS2 domain ID * @param {string} options.owner - Owner identifier for this initialization * @returns {Promise<void>} */ initializeROS2: async (options = {}) => { return await ros2SharedManager.initialize(options); }, /** * Create a ROS2 node through the shared manager * @param {string} nodeName - Name of the node to create * @returns {Promise<{nodeId: string, node: Object}>} */ createNode: async (nodeName) => { return await ros2SharedManager.createNode(nodeName); }, /** * Destroy a ROS2 node * @param {string} nodeId - ID of the node to destroy */ destroyNode: (nodeId) => { return ros2SharedManager.destroyNode(nodeId); }, /** * Get the status of the shared manager * @returns {Object} Status information */ getStatus: () => { return ros2SharedManager.getStatus(); }, /** * Shutdown the shared ROS2 context * @returns {Promise<void>} */ shutdown: async () => { return await ros2SharedManager.shutdown(); }, /** * Add a callback to be executed on shutdown * @param {Function} callback - Callback function */ onShutdown: (callback) => { ros2SharedManager.shutdownCallbacks.add(callback); }, /** * Create an action client * @param {string} nodeId - The node ID to create the action client for * @param {string} actionName - Name of the action * @param {string} actionType - Type of the action * @returns {Promise<string>} Action client ID */ createActionClient: async (nodeId, actionName, actionType) => { return await ros2SharedManager.createActionClient(nodeId, actionName, actionType); }, /** * Send a goal to an action server * @param {string} actionClientId - The action client ID * @param {Object} goal - The goal to send * @param {Function} feedbackCallback - Optional feedback callback * @returns {Promise<Object>} Goal handle */ sendGoal: async (actionClientId, goal, feedbackCallback = null) => { return await ros2SharedManager.sendGoal(actionClientId, goal, feedbackCallback); }, /** * Check if action server is available * @param {string} actionClientId - The action client ID * @returns {boolean} True if server is available */ isActionServerAvailable: (actionClientId) => { return ros2SharedManager.isActionServerAvailable(actionClientId); }, /** * Destroy an action client * @param {string} actionClientId - The action client ID to destroy */ destroyActionClient: (actionClientId) => { return ros2SharedManager.destroyActionClient(actionClientId); }, /** * Get version information * @returns {Object} Version and info */ getInfo: () => { const pkg = require('./package.json'); return { name: pkg.name, version: pkg.version, description: pkg.description, managedNodes: ros2SharedManager.nodes.size, initialized: ros2SharedManager.initialized, spinning: ros2SharedManager.spinning, domain: ros2SharedManager.domain }; } }; // Log manager initialization console.log('[CHART-ROS2-Manager] ROS2 management platform loaded');