Introduction: An Emergency-Stop Circuit for a Mobile Robot
So you've built a robot. Let's say that it's your second one. Typically, we buy a complete one as a kit, for instance, maybe a Smart Video Car from Sunfounder. We had fun building it, rolling it around.
But our developing dreams are growing and we soon realize that most of these type kits are really not much more than toys.
Regardless, from where, as we move up in the level of robot, they tend to get bigger, heavier, faster, and stronger.
And that can quickly lead to problem. Disaster. Danger. Damage. The Three "D"s. :-)
(Sorry, I got carried away)
Trust me when I say that there will come a moment in your robotics tinkering and developing when you will wish you had built and added in some "robot insurance" to your wheeled menace.
I am making my own robot named Wallace, and it definitely needs this feature.
And that scenario or situation is the motivation for this Instructable.
Most of the higher-end motor-controller boards that can handle the bigger motors that draw upwards of 15A, come with a feature called an emergency-stop. An E-Stop.
It can be as simple as two pins on the board that you short together and that causes all motion to cease.
The concept or main idea in enabling such a feature to your robot implies that you'll want a "watchdog". A watchdog - well , it watches. Sort of. Actually, the watchdog is always ready and yearning to do its thing, however it is being constantly held back from doing it.
If we were talking about a real dog, imagine one straining against the leash, and as long as you hold on to the leash, nothing happens. The second you let go of the leash, the "watchdog" takes off to do its thing.
I have seen a few (very good) examples of roboticists creating some emergency-stop circuits, but a lot of times it involves the use of something like an Arduino or some small controller board that acts as the smart watchdog.
I propose to not use anything "smart". To keep it as simple and as reliable as possible.
Step 1: Begin Circuit Design
I did do some researching on how to handle emergency-stops for a mobile robot. Most of what I saw had to do with industrial robots. It seemed most hobbyists aren't doing this. I did see some that explained how they tackled the problem, and most of what I saw involved another smart component, such as an Arduino or some other microcontroller to serve as the circuit that activates the E-stop.
I didn't want to do that. As a software developer, and from everything I see in the news, I tend not to trust software when it has to do with something fail-safe.
So I wanted to go with something simple. Use some passive components, maybe some active components.
Yes, there would be a watchdog, but it would be doing the reverse. That is, I wanted the circuit's natural tendency to be that it closes the Roboclaw motor-controller's E-stop contacts without any effort, and that in order to prevent it from doing so (keeping it on a leash) would require some smarts. "Smart" would mean that everything is well. Lack of "smarts" means something is wrong, and the circuit fires on it's own.
I did come across a youtube that demonstrated a very simple circuit, with a relay, one transistor, one capacitor, and a momentary push-button switch. You close the switch, and that charges the capacitor very quickly. Then it's just the RC time-constant that takes over as the capacitor discharges.
However, that is the opposite of what I need. In that example, the relay is shorted or energized as long as the capacitor has enough charge remaining to keep the transistor conducting.
In my case, I want the transistor to NOT conduct. I need the capacitor to NOT charge.
Anyway, so I chose to go my own way. Besides, it's a learning experience.
One tool that can be very useful in modeling electrical circuits is LtSpice. Spice, I believe, is the the original electrical modeling tool, and there are many programs that have that as the underlying engine, if you will.
LtSpice is one of those.
For those who use Windows, I think the download and install is easy enough. For Linux users, not so much.
You'll have to first install Wine. There are many instructional videos and how-tos, so I won't bore you with that, but here's just one.
I was able to download and run two different versions: LTspiceIV, and LTspiceXVII.
In my experience, I was unable to get the later version to save any of my work to disk. However, the earlier version worked very well for me.
Please check the videos for this section that goes over the design and how I arrived at the circuit.
The starting point of the design meant getting very familiar with the relay that I would be using to close the E-stop contacts. What is it's operating voltage, how much current is needed, what's the coil resistance, and so forth.
These bits of information would be necessary and helpful in what components to choose for the circuit.
Step 2: It Is Time to Breadboard the Design Model
This is just a model. Actual results may differ. Hopefully not by too much. At least the model-diagram gives us a good starting point.
From the previous Step, and from the previous videos, I did choose to increase the capacitance of the first capacitor, even though I was a bit leery of too much current flowing through the Raspberry GPIO pin that provides the circuit with the "watchdog" feature.
Using the LTSpice modeling software, I established some component limits, just by trying different results, constantly re-running the circuit analysis, and studying the resulting voltage and current waveforms at key points in the circuit.
Some key restrictions and parameters would be:
- limit the current through the 5V signal source
- try to make sure the output voltage (Vrelay) goes to its extremes as much as possible (0 to 5V) to give a solid on and off current to the relay
- try to make the 5V input pulse to be as slow as possible, to hog as little of CPU time as possible, among other reasons
Step 3: We Test Our Breadboard Circuit
As it turns out, the circuit did follow closely with the model from LTSpice. That meant the modeling was a worthwhile exercise, as it helped us choose our components.
One minor point: I also designed and tweaked the circuit to include components that I already had on hand.
The C++ program is just a very basic loop to create a steady pulse according to the LTSpice model.
Please watch the video for this section for all the details.
Step 4: Build the Board and Test It
The built circuit board with components worked just as expected. I used a perfboard, some 3-point terminal blocks, and some jumper wires.
The jumper wires are just for testing now. The exact wiring will wait until the board is placed in its location on the robot.
The video has all the details.
Some next steps (another story for another day):
need a bi-directional 3V-to-5V bus breakout board
need a GPIO Port Extender breakout board
need an general-purpose LEDs/switches breakout board
The Raspberry Pi's ports would connect to the bi-directional level-shifted bus, the bus then connects to the GPIO extender, and this E-Stop circuit board would connect to the extender board. Adding the the LEDs/switches board would give us some feedback.
After all the above boards are mounted and wired into the robot, then begin the software that will be responsible for the pulse input to the circuit.
You can checkout the robot all this is being constructed for, at "Wallace The Autonomous Talking Robot Valet".
Thank you for reading / viewing. Any comments / questions are welcome.