01 Introduction to JupyterLab And Robotics Basics

From Waveshare Wiki
Jump to: navigation, search

Introduction to Robotics Basics

Control Architecture

Our robot employs a dual-controller architecture (akin to a brain-like structure), with the master unit potentially being a Raspberry Pi, Jetson Nano, Orin Nano, or other similar single-board computers equipped with a 40PIN interface. The sub-controller utilizes an ESP32 to control the robot's peripherals, read sensor data, and manage closed-loop speed control for the motors using PID controllers.
The dual controllers communicate through serial connections using JSON-formatted instructions. For more specific communication content, users can refer to the documentation of the sub-controller. For a new beginner, you do not need to understand those commands, you only need to follow the tutorial documentation to call common commands or encapsulated functions.

Leveraging the Advantages of a "Dual-controller" Architecture

1. Raspberry Pi or other single-board computers as the primary processing unit handle complex tasks, such as processing visual information, and the ESP32 as a secondary controller dedicated to managing peripherals and sensors, exemplifies a modular design that enhances system flexibility and scalability.

2. The single-board computers are tasked with higher-level processing and decision-making, while the ESP32 handles real-time, low-level tasks such as motor control. This division of tasks allows each component to focus on its functionality, optimizing the system's overall performance.

3. This architecture efficiently allocates processing power and I/O resources, reducing the strain on a singular system and enhancing efficiency.

4. Communication between components is facilitated through serial connections using JSON, which not only streamlines data transfer but also improves readability, easing the debugging and expansion processes.

5. For hobbyists and makers with limited budgets, this "dual-controller" architecture strategy offers a way to maintain high performance while minimizing the costs and complexity of the system.

Basic Tutorial on Interactive Development Using JupyterLab

What is JupyterLab?

  • Interactive Development Environment: JupyterLab is an open-source interactive development environment that offers an easy-to-use interface for coding, running experiments, and viewing data.
  • Ideal for Data Science and Machine Learning: Initially designed for data science and machine learning, its flexibility and ease of use also make it an excellent choice for robotic programming and experimentation.
  • Based on Web Technologies: JupyterLab integrates seamlessly with web technologies, providing a robust platform for various computing tasks.

Benefits of Developing with JupyterLab

1. The User-Friendly Programming Environment of JupyterLab:
JupyterLab's clean and intuitive user interface makes programming and experimentation more accessible to beginners. Its interactive notebooks allow for easy code writing and testing, ideal for novices to explore and learn gradually.

2. Immediate Feedback and Visualization of Results:
JupyterLab provides instant feedback, enabling users to see the effects of code changes immediately, which is invaluable for debugging and learning. Its convenient data visualization capabilities aid in understanding the behaviors and performance of robots.

3. Support for Multiple Programming Languages:
JupyterLab accommodates various programming languages, including Python, offering flexibility for users of all skill levels.

4. Customization and Extension Capabilities:
JupyterLab's high customizability and extensibility allow users to add new features or tools as needed.
5. Cross-Platform Accessibility
As a web-based tool, JupyterLab boasts excellent cross-platform capabilities, running on different operating systems and accessible through a browser.

Basic Usage of JupyterLab

What is a Jupyter Notebook (.ipynb) Document

  • Jupyter Notebooks (.ipynb) are documents that combine executable code with narrative text (Markdown), equations (LaTeX), images, interactive visualizations, and other rich output elements.

Switching Document Themes

  • Our default theme is the light-colored Jupyter Dark.
  • You can switch to a dark theme based on your preference by clicking on Settings - Theme - JupyterLab Dark at the top of the interface.

COMMAND / EDIT MODE

JupyterLab operates in two modes: COMMAND mode and EDIT mode.

  • COMMAND Mode:

In COMMAND mode, you can quickly perform notebook-wide operations, such as adding or deleting cells, moving cells, changing cell types, etc. In this mode, the cell border is gray. You can enter COMMAND mode by pressing the Esc key.

  • EDIT Mode:

EDIT mode allows you to enter or modify code or text within a cell. In this mode, the cell border is blue. You can enter EDIT mode by clicking inside a selected cell or pressing the Enter key.

Cell Operations

In JupyterLab, you can perform the following operations:

  • In COMMAND mode, use the up and down arrow keys to select cells.
  • Add Cell Below: You can add a new cell below the current cell by clicking the "+" button on the toolbar or using the shortcut key B (in COMMAND mode).
  • Add Cell Above: You can add a new cell above the current cell by clicking the "+" button on the toolbar or using the shortcut key A (in COMMAND mode).
  • Delete Cell: Press D,D (press the D key twice in quick succession in COMMAND mode) to delete the currently selected cell.
  • Copy Cell: Use the shortcut key C in COMMAND mode.
  • Paste Cell: Use the shortcut key V in COMMAND mode.
  • Cut Cell: Use the shortcut key X in COMMAND mode.
  • Undo: Use the shortcut key Z in COMMAND mode.
  • Redo: Use the shortcut key Shift + Z in COMMAND mode.
  • Convert the Current Cell to Code Block: Use the shortcut key Y in COMMAND mode.
  • Convert the Current Cell to Markdown: Use the shortcut key M in COMMAND mode.
  • Switch Cell Type: You can set a cell as a code cell, Markdown cell, or raw cell. This can be done using the toolbar dropdown menu or the shortcut keys Y (for code cell) and M (for Markdown cell) in COMMAND mode.
  • Run Cell: You can execute the current cell and automatically move to the next cell by clicking the "▶︎" button on the toolbar or using the shortcut key Shift + Enter.

Saving and Exporting

  • Save Notebook: You can save your notebook by clicking the "💾" button on the toolbar or using the shortcut key S (in COMMAND mode).
  • Export Notebook: JupyterLab allows you to export notebooks in various formats, including HTML, PDF, Markdown, etc. This can be done through the File > Export Notebook As... menu option.

What is a JupyterLab Kernel?

  • A JupyterLab Kernel acts as a computational engine that executes the code written by users in their notebooks.
  • Each notebook is linked to a Kernel, which can be programmed in various languages such as Python, R, or Julia. Kernels also have access to resources like memory and CPU.

Setting the Kernel for a Robotic Virtual Environment

  • When opening subsequent .ipynb tutorial documents, you'll need to manually select the Kernel in the notebook to ensure the robot-related code blocks execute correctly.
  • To do this, click on the Kernel option next to the "⭕" at the top right corner of the notebook tab and choose Python 3 (ipykernel) from the dropdown menu.

Kernel Management

  • Starting: When you open a Jupyter notebook, the associated Kernel will automatically start, indicated by a small green dot appearing in front of the corresponding note in the file list.
  • Restarting: If the Kernel crashes or you need to clear the current session's state, you can restart the Kernel via "Kernel" -> "Restart Kernel...".
  • Stopping: To stop the Kernel of a running note, go to "Kernel" -> "Shut Down Kernel" within the note interface. To stop all Kernels, use "Kernel" -> "Shut Down All Kernels".

Note: If a notebook's Kernel is using the camera and isn't stopped, it will continue to occupy this resource, preventing other notebooks from using it normally. Stopping the notebook's Kernel is necessary for others to function correctly.

Running Code Blocks

After selecting the correct Kernel, you can run code blocks within the notebook. In JupyterLab, code blocks are fundamental components of a notebook. Here's how to execute them:

  • Run a Single Code Block: Select the code block you wish to run and click the "▶︎" button on the toolbar or use the Shift + Enter shortcut. This action will execute the current code block and select the next one.
  • Run All Code Blocks: You can also execute all code blocks in the entire notebook by clicking the Run menu on the toolbar and selecting Run All Cells.
  • Stop a Code Block: To stop a code block that's running, click the "■" button on the toolbar.

These basic operations enable the efficient use of JupyterLab for various tasks. For more advanced features and detailed usage guidelines, refer to JupyterLab's official documentation.

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 in the toolbar and select Run All Cells.
for i in range(0, 10):
    print(i)
  • Stopping a Code Block's Execution: If you need to stop a code block that's currently running, you can click the "■" button on the toolbar.

With these basic operational methods, you can effectively use JupyterLab for various tasks. More advanced features and detailed guides can be found in JupyterLab's official documentation.

Deleting Code Block Outputs

  • To delete the output of a single code block, select the block and then click Edit - Clear Cell Output from the menu above.
  • To delete the outputs of all code blocks, click Edit - Clear Outputs of All Cells from the menu above.

For More Advanced Content