4 Creating a robot shell

 

This chapter covers

  • Learning the basics of creating interactive custom shells in Python
  • Creating a command loop for moving the robot forward and backward
  • Handling command arguments in shell commands
  • Centralizing argument handling logic in code shells
  • Executing custom shell scripts in Python

This chapter will teach you how to create a custom interactive REPL robot shell. Shells provide a powerful interactive interface to allow people to directly interact with software or in this case robotic hardware. They are a tried and tested method for user interaction and the Python standard library provides a built in functionality to create custom shells. The chapter starts with a simple robotic shell and then progresses to add more movement functions with more customized options. The chapter then ends showing how a set of commands can be saved and run in one go in the shell as is done in many other shells.

4.1 What’s a REPL or shell

A read–eval–print loop (REPL) or command-line shell is a program that loops endlessly waiting to receive user input which it takes, executes, and prints output as needed. They are also called “line-oriented command interpreters”, as they take commands as a line of user input and interpret or execute the given line. Figure 4.1 visually depicts the three states that a read–eval–print loop goes through.

Figure 4.1 Read-eval-print loop: The REPL endlessly goes between the read–eval–print states.

4.2 Benefits of a REPL

4.3 Hardware Stack

4.4 Software Stack

4.5 Creating the robot shell

4.6 Handling command arguments

4.7 Adding a speed argument

4.8 Running robot shell scripts

4.9 Summary