Failure, learning the limits of what you have.

A project log for Low cost pi based quadruped "sparx"

My continuing project to build and improve a low cost quadruped robot as an introduction to walking robots.

KeaKea 09/20/2019 at 13:420 Comments

So I decided It was time to give Sparx some sort of sense, something that would allow it to move autonomously . This is what would for the first time turn Sparx from a rover, to a robot. Real autonomy.

Digging through my box of assorted sensors I found a HC-SR04 sonar sensor, this looked perfect. Doing a bit of reading up on this specific sensor I learned that it was digital, meaning I wouldn't need an ADC (Analog to Digital Converter) to let my Pi speak to it. Plus it could range from 10cm up to 400cm! Likely far further than my little bot would need roaming inside (small British houses)

A quick bit of work in Fusion 360 and a few hours printing gave me a bracket to bolt a servo to Sparx' "head" plus a bracket to attach the sonar sensor, as a happy bonus this let me turn the sensor from side to side AND looked very cute. 

Then I needed to solder up a quick voltage divider, the output of the Sensor is 5v and that would harm the Pi, so a voltage divider was constructed and wired up and Sparx had vision, well, echolocation, kind of.

A short PC session later I had a program that would enable Sparx to walk forward until it detected something less than 10cm infront of it, turn its servo "neck" to each side, scan distance and then turn in the direction of the longest distance and continue walking. I compiled it, confidently loaded it onto the Pi and watched my little bot in excitement as it walked towards my sofa.

30 seconds later Sparx walks straight into the sofa, not the slightest hint of attempting to avoid it. I was surprised so picked it up, restarted the program and put my hand in front of it, as expected the little sensor turned left, then right, then picked a direction. I was confused so I plopped Sparx down again and set it on its way. Yet again, a collision occurred.

A quick adjustment to my code and I printed each ranging measurement to the console as Sparx walked. I watched and looked for what could be causing the odd behaviour. Suddenly the readings went from 80cm to over 1000cm. A quick google showed me the problem, the sonar sensor cannot range accurately versus cloth/material surfaces, they absorb the sound, causing the sensor to read its maximum range regardless of how close.

In frustration I added some sanity checks to my code, discarding any results over 600cm as clearly incorrect. I restarted the program and set Sparx on its way. With the sanity checks enabled It wouldnt walk into the sofa, instead it would get stuck in a loop, unsure what to do. So i adjusted the program again, to ensure no loop condition could happen. What was the result?

Sparx walked around seemingly drunkenly, sometimes crashing into things, sometimes not. The whole project was a failure. Even with sanity checks the sonar sensor was simply the wrong tool for the job. Despite my best attempts I couldn't overcome the limitation of the sensor I was using in the environment I was using it in. My first major setback.

Soon I plan to order either an IR distance sensor, or one of the ToF VL53L0X sensors, perhaps like the one Adafruit sells. These can range versus most materials that aren't IR absorbing and should allow Sparx to roam, as long as I don't need to detect things further than about 100cm.

What I learned from this was to double check the constraints of the sensors I use, the HC-SR04 is a commonly used sensor, both because it is cheap and effective for where it is used. But I didn't check and instead learned something new. So not the worst outcome really.