-
Notifications
You must be signed in to change notification settings - Fork 79
Add tutorial for lifecycle node #1237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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(); |
Copilot
AI
Aug 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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'); |
tutorials/lifecycle-nodes.md
Outdated
| switch (msg.data.toLowerCase()) { | ||
| case 'stop': | ||
| console.log('🛑 Stop command received, shutting down...'); | ||
| this.shutdown(); |
Copilot
AI
Aug 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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(); |
tutorials/lifecycle-nodes.md
Outdated
|
|
||
| shutdown() { | ||
| console.log('🔚 Initiating shutdown sequence...'); | ||
| this.node.deactivate(); |
Copilot
AI
Aug 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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