01 JupyterLab Basics and Robot Introduction
Basic Robot Information Introduction
Control Architecture
This robot uses an upper computer + lower computer architecture (dual‑brain architecture). The upper computer can be a Raspberry Pi, Jetson Nano, Orin Nano, or other single‑board computer with a similar 40‑pin interface. The lower computer uses an ESP32 to control robot peripherals, read sensor information, and perform closed‑loop motor speed control (PID controller).
The upper and lower computers communicate via serial port using JSON‑formatted commands. For specific communication details, refer to the lower computer documentation. As a beginner, you don't need to understand those commands at this stage; you can follow the tutorial documents to call common commands or pre‑packaged functions.
Advantages of the Dual‑Brain Architecture
- The Raspberry Pi or other single‑board computer acts as the upper computer to handle complex tasks such as visual information processing, while the ESP32 lower computer controls peripherals and sensors. This modular design improves system flexibility and scalability.
- The Raspberry Pi or other single‑board computer focuses on high‑level processing and decision‑making, while the ESP32 handles real‑time low‑level tasks such as motor control. This division allows each component to focus on its area of expertise.
- This architecture effectively allocates processing power and I/O resources, reducing the burden on a single system and improving overall efficiency.
- Communication via serial port using JSON format improves data transmission efficiency and readability, facilitating debugging and expansion.
- For makers and hobbyists with limited budgets, this architecture maintains high performance while reducing cost and system complexity.
Basic Tutorial for Using JupyterLab Interactive Development
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.
- Suitable for data science and machine learning: Although 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 can be used on almost any operating system.
Advantages of Using JupyterLab for Development
- Beginner‑friendly programming environment: JupyterLab's clean and intuitive user interface makes programming and experimentation more accessible for beginners. Interactive notebooks allow you to easily write and test code, which is suitable for step‑by‑step exploration and learning.
- Immediate feedback and result visualization: Instant feedback lets you immediately see the effect of code changes, which is very useful for debugging and learning. JupyterLab also makes it easy to visualize data, helping you understand the robot's behavior and performance.
- Supports multiple programming languages: JupyterLab supports multiple programming languages, including Python, offering flexibility for users with various skill levels.
- Customizable and extensible: JupyterLab is highly customizable and extensible; users can add new functions or tools according to their needs.
- Cross‑platform and accessible: As a web‑based tool, JupyterLab has excellent cross‑platform capabilities. It can run on different operating systems and is accessible via a browser.
JupyterLab Basic Usage
- You can refer to the official JupyterLab documentation: https://jupyterlab.readthedocs.io/en/latest/getting_started/overview.html
- Since our interactive tutorials are all completed with Jupyter notebooks (.ipynb) files, we will introduce some basic usage methods here.
What is a Jupyter notebook (.ipynb) document?
A Jupyter notebook (.ipynb) is a document that combines executable code with narrative text (Markdown), equations (LaTeX), images, interactive visualizations, and other rich outputs.
Switching the Document Theme
- Our default theme is the light "Jupyter Dark".
- You can switch to a dark theme according to your preference: click Settings → Theme → JupyterLab Dark.
COMMAND / EDIT MODE
JupyterLab has two working modes: COMMAND mode and EDIT mode.
- COMMAND mode
When in COMMAND mode, you can quickly perform global notebook operations such as adding or deleting cells, moving cells, changing cell types, etc. In this mode, cell borders are gray. You can enter COMMAND mode by pressing the Esc key.
- EDIT mode
EDIT mode allows you to type or modify code or text in a cell. In this mode, the cell border is blue. You can enter EDIT mode by clicking on a selected cell or pressing the Enter key.
Cell Operations
In JupyterLab, you can perform the following operations:
- In COMMAND mode, use the up/down arrow keys to select a cell.
- Add a cell below: Click the "+" button on the toolbar or use the shortcut key B (in COMMAND mode) to add a new cell below the current cell.
- Add a cell above: Click the "+" button on the toolbar or use the shortcut key A (in COMMAND mode) to add a new cell above the current cell.
- Delete a cell: Use D,D (press D twice in COMMAND mode) to delete the currently selected cell.
- Copy a cell: In COMMAND mode, use shortcut C.
- Paste a cell: In COMMAND mode, use shortcut V.
- Cut a cell: In COMMAND mode, use shortcut X.
- Undo: In COMMAND mode, use shortcut Z.
- Redo: In COMMAND mode, use shortcut Shift + Z.
- Convert current cell to code cell: In COMMAND mode, use shortcut Y.
- Convert current cell to Markdown: In COMMAND mode, use shortcut M.
- Change cell type: You can set a cell to be a code cell, Markdown cell, or raw cell. This can be done via the toolbar dropdown menu or using shortcuts Y (code cell), M (Markdown cell) in COMMAND mode.
- Run a cell: Click the "▶︎" button on the toolbar or use shortcut Shift + Enter to execute the current cell and automatically move to the next cell.
Saving and Exporting
- Save a notebook: Click the "💾" button on the toolbar or use shortcut S (in COMMAND mode) to save your notebook.
- Export a notebook: JupyterLab supports exporting notebooks to various formats, including HTML, PDF, Markdown, etc. This can be done via the File → Export Notebook As... menu.
What is a JupyterLab Kernel?
- The JupyterLab Kernel is a computation engine that executes the code written in a notebook.
- Each notebook is associated with a Kernel, which can be of different programming languages such as Python, R, or Julia. The Kernel also has access to resources like memory or CPU.
Setting the Kernel to the Robot's Virtual Environment
- When you open subsequent .ipynb tutorial documents, you need to manually select the kernel in the notebook so that the robot‑related code blocks can be executed correctly.
- The specific method is as follows: Click the Kernel option next to the "⭕" in the upper right corner of the notebook tab, and select Python 3 (ipykernel) from the dropdown menu.
Kernel Management
- Start: When you open a Jupyter notebook, the associated Kernel automatically starts. After startup, a small green dot appears in front of the corresponding notebook in the file list.
- Restart: If the Kernel crashes or you need to clear the current session state, you can restart the Kernel via Kernel → Restart Kernel...
- Stop: In a notebook where the Kernel is running, you can stop the Kernel via Kernel → Shut Down Kernel. You can also stop all kernels via Kernel → Shut Down All Kernels.
- Note: If you call the camera in a tutorial's Kernel and do not stop that notebook's Kernel, the camera resource will remain occupied, preventing other tutorials from using it. You need to stop that tutorial's Kernel before other tutorials can work properly.
Running Code Blocks
After selecting the correct kernel, you can run the code blocks in the notebook. In JupyterLab, code blocks are the basic building blocks of a notebook. To run a code block:
- Run a single code block: Select the code block you want to run, then click the "▶︎" button on the toolbar or use shortcut Shift + Enter. This will execute the current code block and select the next one.
print("test text in jupyterlab")
- Run all code blocks: You can also run all code blocks in the entire notebook. To do this, click the Run menu on the toolbar and then select Run All Cells.
for i in range(0, 10):
print(i)
- Stop running a code block: To stop a running code block, click the "■" button on the toolbar.
With these basic operations, you can effectively use JupyterLab to accomplish various tasks. More advanced features and detailed usage guides can be found in the official JupyterLab documentation.
Clearing Code Block Output
- Clear output of a single code block: Select a code block, then click Edit → Clear Cell Output.
- Clear output of all code blocks: Click Edit → Clear Outputs of All Cells.
More Advanced Content
- You can refer to the official JupyterLab documentation: https://jupyterlab.readthedocs.io/en/latest/getting_started/overview.html
Product Upper‑Computer Usage
- 02 Python Chassis Motion Control
- 03 Pan-Tilt Control and LED Light Control
- 04 OLED Screen Control
- 05 Build UI interface in JupyterLab
- 06 Get Chassis Feedback
- 07 Use JSON Commands to Control Slave Device
- 08 Slave Device JSON Instruction Set
- 09 Automatically Send Instructions When Powered On
- 10 Play Audio Files
- 11 Text to Speech (TTS)
- 12 Implement Low Latency Video Transmission with Flask
- 13 Display Real-Time Screen in Jupyter Lab
- 14 Time-Lapse Photography
- 15 OpenCV Motion Detection
- 16 Take Photos by Pressing Buttons
- 17 OpenCV Face Recognition
- 18 Object Recognition Based on DNN (Deep Neural Network)
- 19 Color Recognition Based on OpenCV
- 20 Color Tracking Based on OpenCV
- 21 Auto Driving of Patrol Lines Based on OpenCV
- 22 Gesture Recognition Based on MediaPipe
- 23 Face Recognition Based on MediaPipe
- 24 Pose Detection Based on MediaPipe
- 25 Simple Web Application
- 26 Introduction to Main Program Architecture
- 27 YAML Configuration File Settings
- 28 Automatically Run Scripts at Startup
- 29 Custom Command Line Functionality
- 30 Web Command Line Applications
- 31 Remote Control via Pgytech