Jetson 01 JupyterLab Basics and Robot Introduction
Robot Basic Information Introduction
Control Architecture
This robot uses the architecture of the host device + slave device (Dual Controller architecture), the host device can be Raspberry Pi, Jetson Nano, Orin Nano or other single-board computers with similar 40PIN interfaces, and the slave device uses ESP32 to control robot peripherals, read sensor information, and control motor closed-loop speed (PID controller).
The host device and the slave device use JSON format instructions to communicate through the serial port, the specific communication content can refer to the documentation of the slave device. As a beginner, you don't need to understand those instructions, you only need to follow the tutorial document to call common instructions or encapsulated functions in the early stage.
Advantages of Dual Controller Architecture
- Jetson or other single-board computers can serve as the host device for processing complex tasks, such as visual information processing, while the ESP32, as the slave device, is responsible for controlling peripherals and sensors. This modular design enhances the system's flexibility and scalability.
- Jetson or other single-board computers focus on advanced processing and decision-making, while ESP32 handles real-time low-level tasks such as motor control. This division of labor allows each component to concentrate on its area of expertise.
- This architecture can efficiently allocate processing power and IO resources, reducing the burden on a single system and improving overall efficiency.
- The JSON format is used for communication through the serial port, which improves the efficiency and readability of data transmission, and is easy to debug and expand.
- For makers and hobbyists on a budget, this architecture can reduce cost and system complexity while maintaining high performance.
Interactive Development Basics with JupyterLab
What is JupyterLab?
- Interactive Development Environment: JupyterLab is an open-source interactive development environment that provides an easy-to-use interface for writing code, running experiments, and viewing data.
- Ideal for data science and machine learning: While originally designed for data science and machine learning, its flexibility and ease of use make it ideal for robot programming and experimentation.
- Web-based tool: As a browser-based application, JupyterLab does not require a complicated installation process, and users can use it on almost any operating system.
Advantages of developing with JupyterLab
- User-friendly programming environment: JupyterLab provides a clean, intuitive user interface that makes programming and experimentation more beginner-friendly. Easily write and test code with an interactive notebook for beginners to explore and learn step by step.
- Immediate feedback and result visualization: Instant feedback, users can immediately see the effect of code changes, which is great for debugging and learning. JupyterLab makes it easy to visualize data to help understand the behavior and performance of robots.
- Support for multiple programming languages: JupyterLab supports multiple programming languages such as Python, providing flexibility for users of all skill levels.
- Customization and Extensibility: JupyterLab is highly customizable and extensible, allowing users to add new features or tools according to their needs.
- Cross-platform and accessibility: JupyterLab is a web-based tool with excellent cross-platform capabilities, it can run on different operating systems, and it can be accessed through a browser.
JupyterLab Basics
- You can refer to the official documentation of JupyterLab to learn: https://jupyterlab.readthedocs.io/en/latest/getting_started/overview.html
- Since our interactive tutorials are all made by Jupter notebooks(.ipynb) file, we'll cover some of the basics here.
What is a Jupyter notebooks(.ipynb) document?
A Jupyter notebooks(.ipynb) is a document that combines ready-to-run code with narrative text (Markdown), equations (LaTeX), images, interactive visualizations, and other rich outputs.
Switch the theme of the document
- Our default theme is the bright Jupyter Dark.
- You can switch to a dark theme according to your preference: click Settings - Theme - JupyterLab Dark at the top of the screen.
COMMAND / EDIT MODE
JupyterLab has two working modes, one is COMMAND mode and the other is EDIT mode
- COMMAND mode
When you are in COMMAND mode, you can quickly perform the overall operations of the notebook, such as adding or removing cells, moving cells, changing cell types, etc. In this mode, the cell border is grayed out. You can enter COMMAND mode by pressing the Esc key.
- EDIT Mode
EDIT mode allows you to enter or modify code or text in a cell. In this mode, the cell border is blue. You can enter EDIT mode by clicking or pressing Enter in the selected cell.
Cell Operations
In JupyterLab, you can do the following:
- In COMMAND mode, use the arrow keys up and down to select a cell.
- Add cells below: You can add new cells below the current cell by clicking the + button in the toolbar or by using the shortcut key B (in COMMAND mode).
- Add cells above: You can add new cells below the current cell by clicking the + button in the toolbar or by using the shortcut key A (in COMMAND mode).
- Delete cells: Use D (press D key twice in a row in COMMAND mode) to delete the currently selected cells.
- Copy cells: (in COMMAND mode) Use the shortcut key C.
- Paste cells: (in COMMAND mode) Use the shortcut key V.
- Cut cells: (in COMMAND mode) Use the shortcut key X.
- Undo: (in COMMAND mode) Use the shortcut key Z.
- Redo: (in COMMAND mode) Use the shortcut Shift + Z.
- Convert the current cell to a code block: (in COMMAND mode) Use the shortcut key Y.
- Convert the current cell to Markdown: (in COMMAND mode) Use the shortcut key M.
- Switch cell type: You can set the cell as a code cell, a Markdown cell, or an original cell. This can be swithed in COMMAND mode via the drop-down menu in the toolbar or the shortcut Y (code cell), M (Markdown cell).
- Run Cells: You can click the ▶ button in the toolbar or use the shortcut key Shift + Enter to execute the current cell and run subsequent cells automatically.
Save & Export
- Save notebook: You can save your notebook by clicking the 💾 button in the toolbar or by using the shortcut key S (in COMMAND mode).
- Export notebooks: JupyterLab supports exporting notebooks to a variety of formats, including HTML, PDF, Markdown, and more. This can be accessed via File > Export Notebook As... menu options.
What is JupyterLab's Kernel?
- JupyterLab's Kernel is a computing engine that executes code written by users in notebooks.
- Each notebook is associated with a Kernel, which can be a different programming language, such as Python, R, or Julia. The Kernel also has access to resources, such as memory or CPU.
Set the Kernel as the virtual environment for the bot
- When you open the subsequent .ipynb tutorial documentation, you need to manually select the Kernel in the notebook so that the bot-related code blocks can be executed correctly.
- Here's how: Click on the Kernel option next to ⭕ in the top right corner of the notebook tab and select Python 3 (ipykernel) from the drop-down menu.
Kernel Management
- Startup: When you open a Jupyter notebook, the associated Kernel will start automatically, and a small green dot will appear in front of the corresponding note in the file list.
- Restart: If the Kernel crashes or needs to clear the state of the current session, you can use Kernel -> Restart Kernel... option to restart the Kernel.
- Stop: In the note interface where the Kernel is running, use Kernel -> Shut Down Kernel to stop the Kernel of the current note; It is also possible to stop the Kernel of all notes with Kernel -> Shut Down All Kernels.
- Note: If you call the camera in the Kernel of a tutorial and do not stop the Kernel of the note, it will always occupy this resource, and other tutorials will not be able to use normally, and you need to stop the Kernel of the tutorial before other tutorials can be used normally.
Run Code Block
After selecting the correct Kernel, you can run the code block in the notebook. In JupyterLab, code blocks are the basic building blocks of notebooks. Here's how to run a block:
- Run a single block: Select the block you want to run, then click the ▶ button on the toolbar or use the shortcut key Shift + Enter. This will execute the current block of code and select the next block.
print("test text in jupyterlab")
- Run all code blocks: You can also run all code blocks in the entire notebook. To do this, click on the Run menu in the toolbar and select Run All Cells.
for i in range(0, 10): print(i)
- Stop code block running: If you need to stop a running code block, you can click the ■ button on the toolbar.
With these basic how-tos, you can effectively use JupyterLab for a variety of tasks. More advanced features and detailed instructions can be found in the official JupyterLab documentation.
Delete Code Block Output
- Delete a single code block output: Select a code block and click Edit - Clear Cell Output at the top of the code block
- Delete all code block outputs: Click Edit - Clear Outputs of All Cells at the top
More advanced content
- You can refer to the official documentation of JupyterLab to learn: https://jupyterlab.readthedocs.io/en/latest/getting_started/overview.html