Sheldon robot: crash detection

      No Comments on Sheldon robot: crash detection

It’s sometimes handy to know when things are not going well – for example, when your robot’s collision avoidance systems have failed it and the poor, dumb critter has crashed head-on into something. You’d be surprised how often that happens.

Work on my robot, Sheldon, is progressing slowly. I’ve just added some infrastructure (not shown in the picture) that will allow me to attach infrared proximity and distance sensors. Those will be used by the motor controller to provide a basic level of collision detection and avoidance independent of any higher-level processing.

But, from past experience with such sensors, I know they are easily fooled. A shiny surface can easily defeat them, and they’re in the habit of missing thin and/or rounded objects, such as tripod or chair legs.

In spite of bristling with sensors, robots I’ve built in the past were still in the habit of smashing headlong into furniture, cats and sometimes other robots. This taught me two things:

  • Don’t rely on collision avoidance.
  • Go slow.
  • Tell the cat to hang out somewhere else.

Yes, that was three things, but the last one never works.

Knowing when to stop

If obstacle detection fails, the fail-safe option is to work out when the robot has come to a crashing halt. There are good reasons for wanting to know this.

The first is that the robot can stop trying to do whatever it was in the process of doing. It can even take remedial action, such as backing up and turning.

The second is that you’ll want the motors to stop turning – or worse, trying to turn. The latter situation is bad because stalled motors draw a lot of current. At best, the robot will drain its batteries quickly. At worst, you’ll find that your scheme of fuses and carefully chosen thick cables isn’t quite right and your robot will be merrily burning to the ground. That’s not a good day.

The motors that came with the T300 tank I’m using as Sheldon’s main chassis came equipped with hall effect sensors that can be used as fairly crude encoders. I’m not using them to do things like measuring distance moved because I prefer the ‘soft’ approach to robot design. But I am using them to tell when the motors have stopped turning and put Sheldon into a stopped state.

Backup plan

But I thought it might be handy to have a backup. On one of the many YouTube channels I watch – and I can’t remember which – I saw mention of some simple motion sensors.

In essence, these consist of a tiny, hollow cylinder inside of which is a metal post that also extends outside the cylinder as a pin. Alongside this (on the outside) is a much thinner wire. Inside the cylinder, the wire curls in a spiral around the post without (normally) touching it. If there is sufficient vibration, this spiral wobbles and briefly touches the post, making a connection you can detect with, say, a microcontroller GPIO.

I bought 10 for $1.28 and, when they finally turned up, decided to stick one on a breadboard with a 220Ω resistor and an LED in series with a 5V supply. Flicking the sensor briefly lit the LED, so, yup, they work.

Time to fire up the oscilloscope. I took the LED out of the circuit, leaving just the resistor as a ‘load’. The first surprise was how hard I had to hit the sensor to get a response. I had to tap or flick it quite vigorously – but get a reaction I did.

As you can see, this is a signal in need of serious debouncing. That said, if all you’re trying to do is trigger an interrupt on a microcontroller pin – which is my plan – then even a signal this bouncy will do the trick. The subsequent pulses can be taken care of in software.

Nonetheless, I tried putting a capacitor in parallel with the sensor – a 10µF jobbie chosen precisely because it was already on the breadboard, left over from some previous mucking about. It turned the signal into this:

That’s a lot tidier, isn’t it? It gets high enough to reach a logical high state almost immediately, which would trigger the interrupt, then tails off in a more orderly fashion. Because I already had a resistor in the circuit, this is a classic resistor-capacitor (RC) circuit. The trailing slope could be tailored using the appropriate resistor and capacitor values plus some maths.

Out of sheer curiosity, I decided to measure what we have here.

The time taken from the signal hitting the high level and then dropping back down to 1V (chosen arbitrarily, but not that unreasonable as a definite ‘off’ state) was 3.52ms. Make of that what you will.

Something to bear in mind, though, is that even with the cap, the sensor was still subject to bounce.

In this example, the signal may have stayed high enough at first to remain registering as a logical high. But that peak on the right would definitely have registered as a second pulse.

In this example, we have four distinct pulses.

I need to do some more experimenting to determine how to use this, but I suspect I’ll not bother with a capacitor and just handle the bouncing in software.

The other consideration is how to mount the sensor. The way I had it plugged into the breadboard might have made it just a little too rigid. I suspect that allowing it to wobble a bit more might have made it more sensitive.

But still, this is not a precision sensor. And it’s going to take quite a thwack to trigger it. But that’s precisely the kind of collision the robot needs to know about.

[UPDATE: same day] I just looked again at the Ebay listing through which I bought these sensors and thought you might like to see the specifications:

Maximum working voltage (Vmax) : 12V.
Maximum current (Imax) : less than 5mA.
Open circuit resistance: more than 10m.
On resistance: less than 5ohm.
Ambient temperature: less than 100'C.
Life expectancy: 500000 times.
Suitable for toys, anti-theft alarm, electronic scale, instruments and meters, lamp, gift lamp, digital shoes, sports equipment and other products;
Suitable for small current control circuit of trigger.

That last point, about ‘small current’ is worth noting – as is the maximum power rating of just 5mA. The thinner wire really is very thin and could easily burn out if you’re not paying attention. A current-limiting resistor is probably a good idea at all times.

I was also somewhat taken with the selection of possible uses. Toys? Sure. Anti-theft alarm? Why not? Electronic scale, instruments and meters? Vague, but okay. Lamp? Umm… oh, okay, a lamp you can tap to turn on and off. Okay. Gift lamp? How is this different from lamp? Digital shoes? Well that’s very specific…

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.