liveBook · Manning

Robot shell

As explained in Build Your Own Robot: Using Python, CRICKIT, and Raspberry Pi

A custom interactive command shell that accepts robot movement commands and dispatches them to robot-control code.

A robot shell is a custom interactive REPL for sending movement commands directly to robot hardware. It accepts terminal input, maps commands such as forward and backward to motor-control functions, and keeps running until the user exits. section 4.0 section 4.5

Built with Python’s cmd framework, a shell subclass defines do_ methods for each command and starts its read–evaluate–print loop with cmdloop(). A prompt, welcome message, help, tab completion, and command history make repeated physical control quick to use. section 4.2 section 4.5

Figure 4.2 Hardware stack: the robot shell controls the DC motor through the CRICKIT board.

Commands travel from keyboard input on the Raspberry Pi through the shell and CRICKIT board to signals that drive the DC motors. section 4.3

Movement commands can be extended without changing the shell loop:

  • Parse text following forward or backward as an optional duration; call the motor function without it to retain default behavior. section 4.6
  • Handle EOF with do_EOF returning True, allowing CTRL+D to close the shell cleanly. section 4.6
  • Centralize duration and speed parsing in a helper, then reuse it for forward, backward, left, right, spin_left, and spin_right. section 4.8

Run a saved movement sequence

Put commands such as spin_right, left, and forward 0.2 3 in move.txt, then run cat move.txt | shell.py. The shell processes each line as a command; precmd can print each command before it executes. section 4.8

How Build Your Own Robot: Using Python, CRICKIT, and Raspberry Pi covers it

How deep it goes
Builds a working cmd.Cmd REPL with handlers, optional arguments, EOF handling, shared parsing, and script input.
Examples
Demonstrates forward and backward sessions, timed movements, and a move.txt sequence piped through cat.
What it assumes
Assumes an importable motor module and introduces custom REPL construction through Python’s cmd framework.
What you can do after
Build it from scratch as an interactive or script-driven movement controller using Python’s cmd module.
How it connects
Connects REPLs, Python cmd, Bash, Linux, command history, DC motors, and the CRICKIT board.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Your Own Robot: Using Python, CRICKIT, and Raspberry Pi. The section links point to the parts of the book it draws on.