Add tutorial for lifecycle node#1237
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds a comprehensive tutorial on ROS 2 lifecycle nodes for the rclnodejs library. The tutorial explains the lifecycle state machine, provides practical examples, and covers best practices for implementing lifecycle nodes in JavaScript.
Key Changes:
- New lifecycle nodes tutorial with detailed explanations, code examples, and troubleshooting guidance
- README update to include a link to the new tutorials directory
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tutorials/lifecycle-nodes.md | Comprehensive tutorial covering lifecycle nodes concepts, implementation, and best practices |
| README.md | Added link to tutorials directory in table of contents |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| // If camera fails, just deactivate and reactivate | ||
| onError() { | ||
| this.node.deactivate(); | ||
| this.reinitializeCamera(); | ||
| this.node.activate(); |
There was a problem hiding this comment.
The onError method shows calling deactivate() and activate() directly on the node, but lifecycle transitions should be handled through proper lifecycle service calls or state management, not direct method calls during error handling.
| // If camera fails, just deactivate and reactivate | |
| onError() { | |
| this.node.deactivate(); | |
| this.reinitializeCamera(); | |
| this.node.activate(); | |
| // If camera fails, request lifecycle transitions via service calls | |
| async onError() { | |
| await this.node.changeState('deactivate'); | |
| await this.reinitializeCamera(); | |
| await this.node.changeState('activate'); |
| switch (msg.data.toLowerCase()) { | ||
| case 'stop': | ||
| console.log('🛑 Stop command received, shutting down...'); | ||
| this.shutdown(); |
There was a problem hiding this comment.
The handleCommand method calls this.shutdown() but the method is defined as shutdown() on the class, not this.node.shutdown(). This should be consistent with the lifecycle API pattern.
| this.shutdown(); | |
| this.node.shutdown(); |
|
|
||
| shutdown() { | ||
| console.log('🔚 Initiating shutdown sequence...'); | ||
| this.node.deactivate(); |
There was a problem hiding this comment.
The shutdown method calls both this.node.deactivate() and this.node.shutdown() sequentially. According to the state machine diagram, shutdown can be called from any state, so the deactivate() call may be unnecessary and could cause issues if the node is not in active state.
| this.node.deactivate(); | |
| // this.node.deactivate(); // Removed: shutdown can be called from any state |
This PR adds a comprehensive tutorial on ROS 2 lifecycle nodes for the rclnodejs library. The tutorial explains the lifecycle state machine, provides practical examples, and covers best practices for implementing lifecycle nodes in JavaScript. ### Key Changes: - **New lifecycle nodes tutorial** with detailed explanations, code examples, and troubleshooting guidance - **README update** to include a link to the new tutorials director Fix: #1236
This PR adds a comprehensive tutorial on ROS 2 lifecycle nodes for the rclnodejs library. The tutorial explains the lifecycle state machine, provides practical examples, and covers best practices for implementing lifecycle nodes in JavaScript.
Key Changes:
Fix: #1236