-
Failure, learning the limits of what you have.
09/20/2019 at 13:42 • 0 commentsSo 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.
-
Sparx HUNGRY
09/15/2019 at 12:31 • 0 commentsSo a major point of this project is to eventually turn sparx into an autonomous rover, able to wander around and do its own thing. Currently Sparx has no way to know its own battery level, It will continue to function until the batteries shut off, which is not ideal.
Since i am trying to give Sparx a basic AI (eventually) it makes sense to give it sensors. So first off I decided to kill two birds with one stone and give Sparx the ability to sense his battery level which will translate to the sensation of hunger.
This was a fairly simple addition, a pair of voltage dividers (one for each battery) with some high value resistors to ensure that the current draw was low (a few mA a day) a small capacitor to smooth out any peaks and connect that to one of the pins on the MCP3008.
The MCP3008 is an SPI ADC, offering 8 channels and is basically perfect to connect to a raspberry pi. If you follow the tutorial here:
https://learn.adafruit.com/mcp3008-spi-adc/python-circuitpython
You should be able to both hook up the chip and have some basic knowledge of how to talk to it.
I will soon be writing a python script that starts when Sparx is turned on that will check the battery level every few minutes. Measuring the voltage of the battery wont give me a charge percentage or anything like that, but we can use the voltage returned to gauge how empty the battery is, a lipo battery hovers at a little over 4v when fully charged and the charge/boost circuit I have will cut off the batteries around 3v. If i wanted to get a "percentage" of battery remaining I could try and do something with these values but LiPo voltage doesnt drop in a linear fashion across its battery life.
Hopefully all of this will soon tie into the ability for Sparx to search for and find his own charging station.
-
Sparx walks!
09/13/2019 at 13:08 • 0 commentsSparx is now complete enough to walk un-tethered! There is still a lot to do, while mobile Sparx is more of a rover than a robot as none of his functions are autonomous. Soon I will be adding both a sonar distance sensor and a camera to give him some basic autonomy. He will also be equipped with a method to monitor his own charge levels and hopefully in the futue the ability to find and utilise a charging station without intervention.