Preventing SD Card Corruption on a Raspberry Pi

Author: John Gauthier

The Problem:

One vulnerability of the Raspberry Pi is its susceptibility to micro-SD card corruption. Power interruption during a SD card write is the main culprit. Such interruptions can corrupt the file or even make the entire micro-SD card unusable. The problem is worst in designs where the Raspberry Pi runs headless, leaving no convenient way to request a graceful shutdown.

The Solution:

The solution consists of four parts: a Python script, a service, a shell script and a switch. The code and installation instructions are at https://github.com/zizumara/GPIOshutdown.

How it works:

The GPIOshutdown Python script, when run as a service, provides a way to initiate a graceful shutdown of the operating system by grounding one of its GPIO pins through a switch. The script monitors pin #26 by default. The value of SHUTDOWN_PIN in GPIOshutdown.py controls the monitored pin. When launched, the script will wait for a fixed period before beginning to monitor the GPIO pin. This is a failsafe to allow the user to login via SSH and stop the service to prevent continuous rebooting if the GPIO pin is damaged or otherwise accidentally shorted. The delay defaults to 180 seconds but is modifiable by editing the value of ARMING_DELAY in GPIOshutdown.py. Marking the switch to indicate which position initiates shutdown is highly recommended. In this application, shutdown occurs when the switch is closed.

L298N Motor Driver Board – Drive Modes

Author: Doug Paradis

This article discusses how to connect the L298 motor driver in three modes: drive/coast, sign-magnitude, and lock anti-phase. Code examples will be for the Arduino Uno (or with small modifications the Mega2560).

The L298N is a dual H-bridge chip often packaged nicely on a PCB module. It is widely used on small inexpensive hobbyist robots. It has a maximum current specification of 2.0 A per channel with a peak current of 3.0 A per channel (from STI spec sheet). Each H-bridge can control one DC brushed motor.

Picture of a common L298N PCB module

Continue reading

Calibrating Your Robot Using UMBMark

By Paul Bouchier
This procedure summarizes the robot dead-reckoning calibration
procedure found in:
UMBMark – A Method for Measuring, Comparing, and Correcting Dead-reckoning Errors in Mobile Robots
by Borenstein et. al.

Overview

The paper asserts that most dead-reckoning errors come from 2 sources:

  1. Error in assumed wheelbase, which results in turning a different amount than dead-reckoning calculations predict
  2. Difference in wheel diameter. (Ron showed in simulation that a 0.1% error in wheel diameter produces significant deviation from driving a straight line.

The two error sources interact. The figure below shows how a robot can be incorrectly tuned so that these two errors cancel each other out, returning the robot to its starting position (when run in the clockwise direction only).


Figure 1: Two errors cancelling – copyright University of Michigan
The figure below shows how each error in the absence of the other can return the robot to the same ending location

Continue reading

SUBSUMPTION FOR THE SR04 AND JBOT ROBOTS

by David P. Anderson
26 March 2007

 

Featured Image: Subsumption diagram (Flynn & Jones).

Motivation
This article is a compilation of a series of email postings on the Dallas Personal Robotics Group list server concerning the topic of robot programming, and particularly the technique developed by Rodney Brooks and his colleagues at M.I.T., known as subsumption.

It’s not intended as an exhaustive study of the topic, but rather as an overview and context for some particular practical examples from my own robots. The two used here are the SR04 robot and jBot, although the LEGOBot runs very similar software. If you’d like to examine videos of the behaviors of these robots, the LEGOBot webpage has links for these and a few other robots.
Continue reading

PID Motor Control for Robot Applications

Written by Rick Bickle – November 7, 2003

The following presentation looks at the operation of control systems in general, as well as specific control systems for DC motor controls in robots. Circuits used in motor speed control, techniques for speed control, and examples of different types of control systems are shown. Finally, a description of a specific type of motor control system called a PID system is detailed, showing the mathematics of PID, the parameters, the algorithms used, possible pit falls of PID programming, and an example of a PID tuning method.

Presentation PDF file: motorcontrol

Need even more information on PID? Here are links to a few other good sources of information on this important control technique.

Brief H-Bridge Theory of Operation

April 1998, Written by Jim Brown
September 2002, page format revised, links updated by Bob Jordan

What’s all this talk about H-Bridges? How do they work? Well let’s see . . .

How do we make a motor turn?
You take a battery; hook the positive side to one side of your DC motor. Then you connect the negative side of the battery to the other motor lead. The motor spins forward. If you swap the battery leads the motor spins in reverse.

Ok, that’s basic. Now lets say you want a Micro Controller Unit (MCU) to control the motor, how would you do it? Well, for starters you get a device that would act like a solid state switch, a transistor, and hook it up the motor.

NOTE: If you connect up these relay circuits, remember to put a diode across the coil of the relay. This will keep the spike voltage (back EMF), coming out of the coil of the relay, from getting into the MCU and damaging it. The anode, which is the arrow side of the diode, should connect to ground. The bar, which is the Cathode side of the diode, should connect to the coil where the MCU connects to the relay.

Diagram 1Continue reading