1 Introduction to the TM129 Jupyter notebook environment

The TM129 virtual computing environment (VCE) is based around a Docker container running a self-contained Linux environment which in turn is running a Jupyter notebook server. This environment enables you to experiment with, and program, simple simulated robots using the Python programming language within a Jupyter notebook context. The same environment can be used on different computing platforms (Windows, macOS, Linux) either running locally on your own computer or via a remote external server accessed over the internet.

Within the Jupyter notebook environment, you will be making use of a simple two-dimensional robot simulator, nbev3devsim. At times, we will refer to the Jupyter notebook + nbev3devsim simulator, or just the simulator itself, as RoboLab (it’s somewhat easier to say than nbev3devsim!)

The RoboLab environment is designed to work in the Chrome browser environment. If you do not have Chrome installed, you should download and install it from www.google.com/chrome and use it when running the RoboLab environment.

You will use the RoboLab environment in a practical session during each study week of this part of the module.

After studying the robotics block practical activities, you should be able to:

  • understand the basics of computer programs (e.g. explain what is meant by a sequential computer program, the terms ‘constant’ and ‘variable’, and explain and illustrate the terms ‘branch’ and ‘loop’)

  • use programs in RoboLab (e.g. run example programs in RoboLab and say what a simple robot control program will do)

  • manipulate simple programs in RoboLab (e.g. modify the programs to give different behaviours and write your own simple robot control programs).

If you already know something about computer programming or robotics, we will also provide you with links to various extension activities that you can use to develop your skill further.

Note that the purpose of these activities is not to teach you how to write code in the Python programming language specifically, nor to provide you with an introductory course in computer programming in general. Instead, the intention is show you how we can use building blocks of code to program a simple simulated robot in order to perform a range of simple tasks. The programming task is often more to do with decomposing a problem into simple steps that we know how to do than writing syntactically correct Python code. So if something new appears in one of the programs we provide you with in an unexplained way, DON’T PANIC. Accept it as a black box that does something, and go with it; a fuller explanation will often appear later.

The lab sessions each week consist of exercises using a simulated robot. The simulated robot is based on a small mobile robot with a number of sensors. Robots like this are available at low cost and many are within the reach of amateur enthusiasts.

RoboLab itself is accessed using a Jupyter environment presented via a web browser. Many activities are presented through interactive Jupyter notebooks and make use of a simple graphical robot simulator.

1.1 The Jupyter notebook environment

Jupyter notebooks are a widely used interactive environment for writing ‘literate’ programming scripts in a web browser. Originally developed to support computational data science projects, they are increasingly used as more general computational notebooks that can blend explanatory text with executable code and graphical, or even interactive, code outputs.

1.1.1 Jupyter notebook environment interactive tour

The Jupyter notebook environment has an inbuilt interactive tour to help you find your way around the Jupyter notebook interface. To take the tour, from the Jupyter notebook Help menu, select the first item: User Interface Tour.

Press the Escape key on your keyboard to cut the tour short.

1.1.2 Jupyter notebook environment overview

The Jupyter notebook home page provides a simple listing of files in a particular directory. Additional tabs allow you to monitor currently running notebooks and configure user-enabled extensions that can be used to customise your notebook environment.

Example of the notebook server home page, including Files, Running and Nbextensions tabs and a file listing.

Clicking on a file of an appropriate type will open it as an interactive Jupyter notebook.

It is generally not advisable to have multiple copies of the same notebook open in multiple windows. As the notebooks autosave, you may find that work you have created and saved from one notebook gets overwritten by an earlier version of the notebook in a different browser tab or window.

Notebooks are structured using the notion of different sorts of ‘cell’. For example, Markdown cells are used to contain explanatory text written using the simple text-based Markdown script. Executable code cells can be used to declare executable Python code, the outputs of which can be displayed as code cell outputs.

Screenshot of notebook fragment showing a Markdown cell containing text and a styled list, a code cell containing a code fragment, the code cell print display and the code cell output.

Markdown and code cells can be edited and saved interactively via the notebook’s browser interface.

1.2 Running Jupyter notebook code cells

The following cell contains Python code that can be executed by ‘running’ the code cell. The code can produce two sorts of output:

  • display items rendered as the program executes via display() or print() commands in the code

  • a ‘cell output’ value that displays the return value (if any) from the last statement in the cell.

The code in the cell can be executed using the Run button in the notebook toolbar, as well as via keyboard shortcuts.

(We will explore the mechanics of using the notebooks in more detail later on.)

print("hello world...")

my_variable = "value of my variable"
my_variable

1.3 Jupyter notebook extensions

A wide range of notebook extensions are installed in the RoboLab environment, although the majority have not been pre-enabled.

You can enable and disable extensions, as well as further configuring certain extensions, via the extensions configurator. This can be accessed from the notebook home page or from the nbextensions config option in the Edit menu of an opened notebook.

Screenshot of Jupyter nbextensions configurator page, showing conficuration panel for a selected extension.

You are welcome to explore the available extensions, or even add further ones of your own, to personalise your notebook environment, but we will not discuss them further here.

You may want to share details of any extensions you find particularly useful in your module or tutor group forums.

1.4 Summary

In this notebook you have seen an overview of the Jupyter notebook server environment and how it can be extended by enabling custom extensions via the notebook configuration panel.

In the next notebook, you will have an opportunity to explore how a Jupyter notebook itself works.

Addendum

At the end of some notebooks, there may be an Addendum section. These sections are optional as far as the module goes, and you are not necessarily expected to, let alone required to, study them, read through them, or even glance at them at all.

In particular, the addendum sections provide additional context or explanation not directly relevant to the module but which may be of interest to the more curious or technically minded amongst you. In some cases, the sections are there to explore in a little more detail how a particular activity or notebook feature works behind the scenes; in other cases, they may hint at other ways in which what you have learned may be applied to other contexts not directly associated with programming robots.