April 2018
Beginner
552 pages
13h 58m
English
We import rover_drive to control the robot (if we are using a Pi-Bug robot, bug_drive can be used) and wiringpi2 so that we can use the GPIO to read the sensors (defined as PINS). We define opCmds, which uses a Python dictionary to allocate new commands in response to the original command (using opCmds[char], where char is the original command).
We create a new class called sensor and set up each of the switches as GPIO input (each with an internal pull-ups set). Now, whenever we make a movement (as earlier, from the list of requested commands in the main() function), we check to see if any of the switches have been triggered (by calling mySensor.checkSensor()).
If a switch was tripped, we stop the current movement, and then ...