Chatham Rabbit Hole Logo

Interactive GPIO Robot Controls


Interactive GPIO Robot Controls enable an operator to train the robot to perform a timed sequence steps, record them, and play back the sequence.

A computer with wireless SSH connection to the robot controls forward, backward, left, and right motion from the keyboard cursor-arrow keys up, down, left, and right, respectively. The command sequence and time intervals between each command are recorded and may be played ba

The sections below review the main components of the full Python code listing available here.

Code Dependencies

					import time
import os
import sys
import glob
from pynput import keyboard
from datetime import timedelta, datetime
from gpiozero import Robot

Sources and description of the libraries are available here.

Main Program

The Main Program starts with the requisite import statements to load the requried code modules, creates the Robot Class instance, and prints the user prompts to select an operating mode for options TRAINING, PLAYBACK, or QUIT.

Training Mode

In TRAINING mode, the operator controls the robot with the arrow keys, and quits training mode by typing the letter ‘q’.

Playback Mode

In PLAYBACK mode, the operator selects a pre-recorded training file.

The program reads each command and the time for which it is in effect from the file and waits the time specified to read and execute the next command and interval. The program continues reading until the EOF, stops the robot, and exits PLAYBACK mode.